Skip to content

Commit fbd02a5

Browse files
committed
add support snoop object
1 parent cef1055 commit fbd02a5

File tree

8 files changed

+157
-18
lines changed

8 files changed

+157
-18
lines changed

AutoCADLookup

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit d8c6046c3948baa39ca4bbbd39c687b3bc14da50

CADPythonShell.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Build", "build\Build.csproj
2222
EndProject
2323
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Installer", "Installer\Installer.csproj", "{51C417E1-279A-46C2-B3AE-1FDE56FEE5AB}"
2424
EndProject
25+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CADSnoop", "AutoCADLookup\CADSnoop.csproj", "{275C1B41-9089-4817-B48F-564A72A6D121}"
26+
EndProject
2527
Global
2628
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2729
Debug A22|Any CPU = Debug A22|Any CPU
@@ -30,6 +32,7 @@ Global
3032
EndGlobalSection
3133
GlobalSection(ProjectConfigurationPlatforms) = postSolution
3234
{F1152D68-346B-4F48-8DB7-BE67B5CB1F49}.Debug A22|Any CPU.ActiveCfg = Debug|Any CPU
35+
{F1152D68-346B-4F48-8DB7-BE67B5CB1F49}.Debug A22|Any CPU.Build.0 = Debug|Any CPU
3336
{F1152D68-346B-4F48-8DB7-BE67B5CB1F49}.Installer|Any CPU.ActiveCfg = Release|Any CPU
3437
{F1152D68-346B-4F48-8DB7-BE67B5CB1F49}.Release A22|Any CPU.ActiveCfg = Release|Any CPU
3538
{F1152D68-346B-4F48-8DB7-BE67B5CB1F49}.Release A22|Any CPU.Build.0 = Release|Any CPU
@@ -39,6 +42,7 @@ Global
3942
{7E37F14E-D840-42F8-8CA6-90FFC5497972}.Release A22|Any CPU.ActiveCfg = Release A22|Any CPU
4043
{7E37F14E-D840-42F8-8CA6-90FFC5497972}.Release A22|Any CPU.Build.0 = Release A22|Any CPU
4144
{C8446636-C663-409F-82D0-72C0D55BBA1C}.Debug A22|Any CPU.ActiveCfg = Debug|Any CPU
45+
{C8446636-C663-409F-82D0-72C0D55BBA1C}.Debug A22|Any CPU.Build.0 = Debug|Any CPU
4246
{C8446636-C663-409F-82D0-72C0D55BBA1C}.Installer|Any CPU.ActiveCfg = Release|Any CPU
4347
{C8446636-C663-409F-82D0-72C0D55BBA1C}.Release A22|Any CPU.ActiveCfg = Release|Any CPU
4448
{C8446636-C663-409F-82D0-72C0D55BBA1C}.Release A22|Any CPU.Build.0 = Release|Any CPU
@@ -49,6 +53,12 @@ Global
4953
{51C417E1-279A-46C2-B3AE-1FDE56FEE5AB}.Installer|Any CPU.ActiveCfg = Release|Any CPU
5054
{51C417E1-279A-46C2-B3AE-1FDE56FEE5AB}.Installer|Any CPU.Build.0 = Release|Any CPU
5155
{51C417E1-279A-46C2-B3AE-1FDE56FEE5AB}.Release A22|Any CPU.ActiveCfg = Release|Any CPU
56+
{275C1B41-9089-4817-B48F-564A72A6D121}.Debug A22|Any CPU.ActiveCfg = Debug|Any CPU
57+
{275C1B41-9089-4817-B48F-564A72A6D121}.Debug A22|Any CPU.Build.0 = Debug|Any CPU
58+
{275C1B41-9089-4817-B48F-564A72A6D121}.Installer|Any CPU.ActiveCfg = Debug|Any CPU
59+
{275C1B41-9089-4817-B48F-564A72A6D121}.Installer|Any CPU.Build.0 = Debug|Any CPU
60+
{275C1B41-9089-4817-B48F-564A72A6D121}.Release A22|Any CPU.ActiveCfg = Debug|Any CPU
61+
{275C1B41-9089-4817-B48F-564A72A6D121}.Release A22|Any CPU.Build.0 = Debug|Any CPU
5262
EndGlobalSection
5363
GlobalSection(SolutionProperties) = preSolution
5464
HideSolutionNode = FALSE

CADPythonShell/CADPythonShell.csproj

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@
3535
<ItemGroup>
3636
<None Remove="Images\New.png" />
3737
<None Remove="Images\SaveAs.png" />
38+
<None Remove="Resources\Console-16.png" />
39+
<None Remove="Resources\Console-32.png" />
40+
<None Remove="Resources\CreateWall.png" />
41+
<None Remove="Resources\Deployment-16.png" />
42+
<None Remove="Resources\Deployment-32.png" />
43+
<None Remove="Resources\Find-16.png" />
44+
<None Remove="Resources\Find-32.png" />
45+
<None Remove="Resources\ipy.ico" />
46+
<None Remove="Resources\py.ico" />
47+
<None Remove="Resources\pycon.ico" />
48+
<None Remove="Resources\Python-16.png" />
49+
<None Remove="Resources\Python-32.png" />
50+
<None Remove="Resources\Python.xshd" />
51+
<None Remove="Resources\PythonConsole16x16.png" />
52+
<None Remove="Resources\PythonConsole32x32.png" />
53+
<None Remove="Resources\PythonScript16x16.png" />
54+
<None Remove="Resources\PythonScript32x32.png" />
55+
<None Remove="Resources\Settings-16.png" />
56+
<None Remove="Resources\Settings-32.png" />
3857
</ItemGroup>
3958
<ItemGroup>
4059
<Reference Include="accoremgd">
@@ -98,14 +117,6 @@
98117
<Resource Include="Images\New.png" />
99118
<Resource Include="Images\Number.png" />
100119
<Resource Include="Images\Paragraph.png" />
101-
<EmbeddedResource Include="Resources\Console-16.png" />
102-
<EmbeddedResource Include="Resources\Console-32.png" />
103-
<EmbeddedResource Include="Resources\Deployment-16.png" />
104-
<EmbeddedResource Include="Resources\Deployment-32.png" />
105-
<EmbeddedResource Include="Resources\Python-16.png" />
106-
<EmbeddedResource Include="Resources\Python-32.png" />
107-
<EmbeddedResource Include="Resources\Settings-16.png" />
108-
<EmbeddedResource Include="Resources\Settings-32.png" />
109120
<Content Include="startup.py">
110121
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
111122
</Content>
@@ -141,18 +152,29 @@
141152
<Resource Include="Images\SaveAs.png" />
142153
<Resource Include="Images\Undo.png" />
143154
<Resource Include="Images\WordWrap.png" />
155+
<EmbeddedResource Include="Resources\Console-16.png" />
156+
<EmbeddedResource Include="Resources\Console-32.png" />
144157
<EmbeddedResource Include="Resources\CreateWall.png" />
145-
<Content Include="Resources\py.ico" />
146-
<Content Include="Resources\pycon.ico" />
147-
<EmbeddedResource Include="Resources\PythonConsole32x32.png" />
158+
<EmbeddedResource Include="Resources\Deployment-16.png" />
159+
<EmbeddedResource Include="Resources\Deployment-32.png" />
160+
<EmbeddedResource Include="Resources\Find-16.png" />
161+
<EmbeddedResource Include="Resources\Find-32.png" />
162+
<EmbeddedResource Include="Resources\ipy.ico" />
163+
<EmbeddedResource Include="Resources\py.ico" />
164+
<EmbeddedResource Include="Resources\pycon.ico" />
165+
<EmbeddedResource Include="Resources\Python-16.png" />
166+
<EmbeddedResource Include="Resources\Python-32.png" />
167+
<EmbeddedResource Include="Resources\Python.xshd" />
148168
<EmbeddedResource Include="Resources\PythonConsole16x16.png" />
169+
<EmbeddedResource Include="Resources\PythonConsole32x32.png" />
149170
<EmbeddedResource Include="Resources\PythonScript16x16.png" />
150171
<EmbeddedResource Include="Resources\PythonScript32x32.png" />
172+
<EmbeddedResource Include="Resources\Settings-16.png" />
173+
<EmbeddedResource Include="Resources\Settings-32.png" />
151174
<Content Include="CADPythonShell.xml">
152175
<SubType>Designer</SubType>
153176
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
154177
</Content>
155-
<EmbeddedResource Include="Resources\Python.xshd" />
156178
</ItemGroup>
157179
<ItemGroup>
158180
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
@@ -172,6 +194,7 @@
172194
</BootstrapperPackage>
173195
</ItemGroup>
174196
<ItemGroup>
197+
<ProjectReference Include="..\AutoCADLookup\CADSnoop.csproj" />
175198
<ProjectReference Include="..\CADRuntime\CADRuntime.csproj" />
176199
<ProjectReference Include="..\PythonConsoleControl\PythonConsoleControl.csproj" />
177200
</ItemGroup>

CADPythonShell/IronPythonConsoleApp.cs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ private void CreateRibbon()
2525
{
2626
ribbon.Tabs.Remove(rtab);
2727
}
28+
2829
rtab = new RibbonTab();
2930
rtab.Title = RibbonTitle;
3031
rtab.Id = RibbonId;
@@ -35,10 +36,11 @@ private void CreateRibbon()
3536

3637
private void AddContentToTab(RibbonTab rtab)
3738
{
38-
rtab.Panels.Add(AddOnePanel());
39+
rtab.Panels.Add(AddPanelOne());
40+
rtab.Panels.Add(AddPanelTwo());
3941
}
4042

41-
private static RibbonPanel AddOnePanel()
43+
private static RibbonPanel AddPanelOne()
4244
{
4345
RibbonPanelSource rps = new RibbonPanelSource();
4446
rps.Title = "Cad Python Shell";
@@ -58,8 +60,10 @@ private static RibbonPanel AddOnePanel()
5860
ShowText = true,
5961
Text = "Run CPS",
6062
Description = "Start Write Python Console\nCommand: PythonShellConsole",
61-
Image = CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Python-16.png"),
62-
LargeImage = CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Python-32.png"),
63+
Image = CADPythonShellApplication.GetEmbeddedPng(addinAssembly,
64+
"CADPythonShell.Resources.Python-16.png"),
65+
LargeImage =
66+
CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Python-32.png"),
6367
CommandHandler = new RelayCommand(new IronPythonConsoleCommand().Execute)
6468
};
6569
rps.Items.Add(btnPythonShell);
@@ -73,13 +77,47 @@ private static RibbonPanel AddOnePanel()
7377
ShowText = true,
7478
Text = "Configure CPS",
7579
Description = "Configure Cad Python Shell\nCommand: PythonShellSetting",
76-
Image = CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Settings-16.png"),
77-
LargeImage = CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Settings-32.png"),
80+
Image = CADPythonShellApplication.GetEmbeddedPng(addinAssembly,
81+
"CADPythonShell.Resources.Settings-16.png"),
82+
LargeImage =
83+
CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Settings-32.png"),
7884
CommandHandler = new RelayCommand(new ConfigureCommand().Execute)
7985
};
8086
//Add the Button to the Tab
8187
rps.Items.Add(btnConfig);
8288
return rp;
8389
}
90+
91+
private static RibbonPanel AddPanelTwo()
92+
{
93+
RibbonPanelSource rps = new RibbonPanelSource();
94+
rps.Title = "Lookup";
95+
RibbonPanel rp = new RibbonPanel();
96+
rp.Source = rps;
97+
RibbonButton rci = new RibbonButton();
98+
rci.Name = "Lookup";
99+
rps.DialogLauncher = rci;
100+
//create button1
101+
var addinAssembly = typeof(IronPythonConsoleApp).Assembly;
102+
RibbonButton btnSnoop = new RibbonButton
103+
{
104+
Orientation = Orientation.Vertical,
105+
AllowInStatusBar = true,
106+
Size = RibbonItemSize.Large,
107+
Name = "Snoop",
108+
ShowText = true,
109+
Text = "Snoop",
110+
Description = "Start snoop object inside Autocad \n Command: Snoop",
111+
Image = CADPythonShellApplication.GetEmbeddedPng(addinAssembly,
112+
"CADPythonShell.Resources.Find-16.png"),
113+
LargeImage =
114+
CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Find-32.png"),
115+
CommandHandler = new RelayCommand(new SnoopCommand().Execute),
116+
AllowInToolBar = true,
117+
KeyTip = "Snoop",
118+
};
119+
rps.Items.Add(btnSnoop);
120+
return rp;
121+
}
84122
}
85123
}

CADPythonShell/PackageContents.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<Command Local="PythonConsole" Global="PythonConsole" />
1818
<Command Local="PythonShellSetting" Global="PythonShellSetting" />
1919
<Command Local="InitPythonConsole" Global="InitPythonConsole" StartupCommand="True" />
20+
<Command Local="Snoop" Global="Snoop" />
2021
</Commands>
2122
</ComponentEntry>
2223
</Components>
511 Bytes
Loading
1020 Bytes
Loading

CADPythonShell/SnoopCommand.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Autodesk.AutoCAD.ApplicationServices;
2+
using Autodesk.AutoCAD.DatabaseServices;
3+
using Autodesk.AutoCAD.EditorInput;
4+
using Autodesk.AutoCAD.Runtime;
5+
using CADSnoop.Model;
6+
using CADSnoop.View;
7+
using CADSnoop.ViewModel;
8+
using Exception = System.Exception;
9+
using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;
10+
using MessageBox = System.Windows.MessageBox;
11+
12+
namespace CADPythonShell
13+
{
14+
public class SnoopCommand
15+
{
16+
[CommandMethod("Snoop")]
17+
public void Execute()
18+
{
19+
try
20+
{
21+
Document doc = Application.DocumentManager.MdiActiveDocument;
22+
Editor ed = doc.Editor;
23+
Database db = doc.Database;
24+
using (Transaction tran = db.TransactionManager.StartTransaction())
25+
{
26+
List<ObjectId> objectIds = PickObjectBySelect(doc);
27+
if (objectIds!=null)
28+
{
29+
SnoopViewModel vm = new SnoopViewModel(doc, db, objectIds);
30+
MainWindow form = new MainWindow(vm);
31+
form.SetCadAsWindowOwner();
32+
form.Show();
33+
}
34+
tran.Commit();
35+
36+
}
37+
}
38+
catch (Exception ex)
39+
{
40+
MessageBox.Show(ex.ToString());
41+
}
42+
}
43+
44+
List<ObjectId> PickObjectBySelect(Document doc)
45+
{
46+
try
47+
{
48+
//PromptSelectionOptions poOptions = new PromptSelectionOptions();
49+
//poOptions.SingleOnly = true;
50+
PromptSelectionResult promptSelectionResult = doc.Editor.GetSelection();
51+
if (promptSelectionResult.Status != PromptStatus.OK) return null;
52+
SelectionSet selectionSet = promptSelectionResult.Value;
53+
return selectionSet.GetObjectIds().ToList();
54+
}
55+
catch(ArgumentNullException){}
56+
catch(NullReferenceException){}
57+
catch (Exception e)
58+
{
59+
MessageBox.Show(e.ToString());
60+
}
61+
62+
return null;
63+
}
64+
65+
}
66+
}

0 commit comments

Comments
 (0)