From 08fa303f3f81ad9da8634321f4ee504d76924fa7 Mon Sep 17 00:00:00 2001 From: rave Date: Mon, 2 Sep 2013 23:44:02 +0800 Subject: [PATCH] Added context menu Demonstrate how to launch command using context menu for a specific entity type --- .gitignore | 1 + .../Contents/2014/Lazcad.Opc.dll | Bin 7168 -> 8192 bytes Lazcad.Opc.bundle/PackageContents.xml | 6 +-- Lazcad.Opc/Commands.cs | 3 +- Lazcad.Opc/Extensions.cs | 38 ++++++++++++++++++ Lazcad.Opc/Lazcad.Opc.csproj | 4 +- Lazcad.Opc/OpcContextMenu.cs | 27 +++++++++++++ 7 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 Lazcad.Opc/Extensions.cs create mode 100644 Lazcad.Opc/OpcContextMenu.cs diff --git a/.gitignore b/.gitignore index 31a08b7..cc5a784 100644 --- a/.gitignore +++ b/.gitignore @@ -152,3 +152,4 @@ $RECYCLE.BIN/ # Mac desktop service store files .DS_Store +/Lazcad.Opc.bundle/Contents/Resources/lazcadopc.mnr diff --git a/Lazcad.Opc.bundle/Contents/2014/Lazcad.Opc.dll b/Lazcad.Opc.bundle/Contents/2014/Lazcad.Opc.dll index 4cc3f225cf37dae93a214e85d967e7dc3617dde1..38bbf95d55494c40e6580387197107b1be9def56 100644 GIT binary patch delta 3219 zcmZ{ndu&tJ9ml`t+P=Oq#BguoKvD({VZcy$EG6Cx>Zc@2czvkXacseRns)JtEz3FcA$2XHceu%P1=A>`<`R- zh*)pp&-uO1@0{~H=U!irKRn)kaNqo=Pb}y|`MM0PewvsD%%(vv89#2D{J|5!gKfa$ z($G$)XR^L(`ZK_E>Vsbb=D79RgYJ`}G4Saun!^0dcE2u~MVEd9?dsmxT>;z0)! zc>q(3&=BAf@;8B8q**F?Qy^D(kYYgR3Ro7su$WplD!p2E2^&4zLM}wpRzxi6)qgDhM=HwFq#2@Vc*i<_VwsW5tgY|Kpjp;I^M@Hnp981_qj;H_g{PyQI=2 zr|i!5Mjm~No7b=#c$e+p49fjZK9$*0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zO?&{`xWAJ*B$>l7HOp|67{M6P#M{IMoI$Cc!g(y!H{(;Z>%GKbJ%h_Qu0Mqz@v*)e zVSJ$v5ijfe$e-2^V+yx0O3_)yQT&cd;~0dHjz`FmJtAwoNtt;gPW?m1IC37IGRWa5 z4x$+~coyTL2GwXJ?!xQD`>>ek!*z-lbN>#G#+eD`0FF}5D()}CYU+1l6LAYhL_LlC z32iDaen65r#2m|UbB=kQImv{OsZnM z{_ExW+K~6izh#kOU-aE?wDhMM`upwjqQ~ubi`pX1ed%mE*^?f$u+GZ#ru&jv3pJ_i z)=Xiyze5zR1XgH~Ra<-e(>+$E$?CH*l+fLfrOR*A_N--pRC2Qd6ISNCg|9xmW_&zR z)_zy86Yf)k8`{E)Cx=xd=%;H1w{$^gMK|K%$))0`(?%+gLHn#O*VyHQANlk z)8#fTGi~-#H@eN-Y383-LjTO}rrA?HRx&elQudScrtZ1@cP7_UN@rcNh-xwLSfVk3 zD=P=frp`9KaW*j_;;weh9uBQi1~T?U=t7{~`G1mQ_0`$O!V#sb&i*jGt`IHj5`{qI R4^_$66@q2Ii6gbHzX8*8M8^OC diff --git a/Lazcad.Opc.bundle/PackageContents.xml b/Lazcad.Opc.bundle/PackageContents.xml index 3ec1a0d..31a52b1 100644 --- a/Lazcad.Opc.bundle/PackageContents.xml +++ b/Lazcad.Opc.bundle/PackageContents.xml @@ -2,19 +2,19 @@ - + - + \ No newline at end of file diff --git a/Lazcad.Opc/Commands.cs b/Lazcad.Opc/Commands.cs index 383fa6a..8a33fdf 100644 --- a/Lazcad.Opc/Commands.cs +++ b/Lazcad.Opc/Commands.cs @@ -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 @@ -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(); diff --git a/Lazcad.Opc/Extensions.cs b/Lazcad.Opc/Extensions.cs new file mode 100644 index 0000000..21538fe --- /dev/null +++ b/Lazcad.Opc/Extensions.cs @@ -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() + { + } + } +} diff --git a/Lazcad.Opc/Lazcad.Opc.csproj b/Lazcad.Opc/Lazcad.Opc.csproj index ed70bb7..42f1d0e 100644 --- a/Lazcad.Opc/Lazcad.Opc.csproj +++ b/Lazcad.Opc/Lazcad.Opc.csproj @@ -16,7 +16,7 @@ true full false - bin\Debug\ + ..\..\..\..\..\..\..\ProgramData\Autodesk\ApplicationPlugins\Lazcad.Opc.bundle\Contents\2014\ DEBUG;TRACE prompt 4 @@ -66,7 +66,9 @@ + + diff --git a/Lazcad.Opc/OpcContextMenu.cs b/Lazcad.Opc/OpcContextMenu.cs new file mode 100644 index 0000000..65ffbad --- /dev/null +++ b/Lazcad.Opc/OpcContextMenu.cs @@ -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); + } + } +}