Skip to content

Commit

Permalink
Added context menu
Browse files Browse the repository at this point in the history
Demonstrate how to launch command using context menu for a specific
entity type
  • Loading branch information
tam-wh committed Sep 2, 2013
1 parent b4673d7 commit 08fa303
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,4 @@ $RECYCLE.BIN/

# Mac desktop service store files
.DS_Store
/Lazcad.Opc.bundle/Contents/Resources/lazcadopc.mnr
Binary file modified Lazcad.Opc.bundle/Contents/2014/Lazcad.Opc.dll
Binary file not shown.
6 changes: 3 additions & 3 deletions Lazcad.Opc.bundle/PackageContents.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
<ApplicationPackage SchemaVersion="1.0"
ProductType="Application"
Name="Lazcad.Opc"
AppVersion="0.3"
AppVersion="0.4"
Description="Lazcad Opc"
Author="Lazcad"
Icon="./Contents/Resources/lazcadopc.bmp" >
<CompanyDetails Name="Lazcad" Url="http://www.lazcad.com" Email="[email protected]" />
<Components>
<RuntimeRequirements OS="Win32|Win64" Platform="PNID|PLANT3D" SeriesMin="R19.1" SeriesMax="R19.1"/>
<ComponentEntry AppName="Lazcad.Opc" ModuleName="./Contents/2014/lazcad.opc.dll" AppDescription="Lazcad Opc" LoadOnAutoCADStartup="false" LoadOnCommandInvocation="True">
<ComponentEntry AppName="Lazcad.Opc" ModuleName="./Contents/2014/lazcad.opc.dll" AppDescription="Lazcad Opc" LoadOnAutoCADStartup="true" LoadOnCommandInvocation="false">
<Commands GroupName="LAZ_OPC">
<Command Local="opcselect" Global="opcselect" />
<Command Local="opcclear" Global="opcclear" />
</Commands>
</ComponentEntry>
<ComponentEntry AppName="Lazcad.Opc" Version="0.3" ModuleName="./Contents/Resources/lazcadopc.cuix" AppDescription="Alternative OPC Connector" />
<ComponentEntry AppName="Lazcad.Opc" Version="0.4" ModuleName="./Contents/Resources/lazcadopc.cuix" AppDescription="Alternative OPC Connector" />
</Components>
</ApplicationPackage>
3 changes: 2 additions & 1 deletion Lazcad.Opc/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.ProcessPower.PlantInstance;
using Autodesk.ProcessPower.PnIDObjects;

namespace Lazcad.Opc
Expand All @@ -16,7 +17,7 @@ public static void OpcSelectCommand()
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;

ObjectId opcId;

var sel = ed.SelectImplied();
Expand Down
38 changes: 38 additions & 0 deletions Lazcad.Opc/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.ProcessPower.PlantInstance;
using Autodesk.ProcessPower.PnIDObjects;
using System;

namespace Lazcad.Opc
{
public class Extensions : IExtensionApplication
{
private OpcContextMenu _menu = new OpcContextMenu();

public void Initialize()
{
PlantApplication.CurrentProjectOpenedEvent += PlantApplication_CurrentProjectOpenedEvent;
}

void PlantApplication_CurrentProjectOpenedEvent()
{
//Disable once loaded first time
PlantApplication.CurrentProjectOpenedEvent -= PlantApplication_CurrentProjectOpenedEvent;

AddContext(typeof(DynamicOffPage));
AddContext(typeof(OffPage));
}

public void AddContext(Type type)
{
RXClass rxc = Entity.GetClass(type);
Application.AddObjectContextMenuExtension(rxc, new OpcContextMenu());
}

public void Terminate()
{
}
}
}
4 changes: 3 additions & 1 deletion Lazcad.Opc/Lazcad.Opc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\..\..\..\..\..\..\ProgramData\Autodesk\ApplicationPlugins\Lazcad.Opc.bundle\Contents\2014\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down Expand Up @@ -66,7 +66,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Commands.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="OpcApp.cs" />
<Compile Include="OpcContextMenu.cs" />
<Compile Include="OpcEntity.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
27 changes: 27 additions & 0 deletions Lazcad.Opc/OpcContextMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Autodesk.AutoCAD.ApplicationServices.Core;
using Autodesk.AutoCAD.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lazcad.Opc
{
public class OpcContextMenu : ContextMenuExtension
{
public OpcContextMenu()
{
Title = "Lazcad OPC";

var connectMenu = new MenuItem("Opc Connect (Lazcad)");
connectMenu.Click += connectMenu_Click;

MenuItems.Add(connectMenu);
}

void connectMenu_Click(object sender, EventArgs e)
{
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("opcselect ", true, false, true);
}
}
}

0 comments on commit 08fa303

Please sign in to comment.