1+ using Autodesk . AutoCAD . Runtime ;
2+ using Autodesk . Windows ;
3+ using MgdDbg ;
4+ using Orientation = System . Windows . Controls . Orientation ;
5+
6+ namespace CADPythonShell
7+ {
8+ public class IronPythonConsoleApp : ICadCommand
9+ {
10+ public const string RibbonTitle = "Python Shell" ;
11+ public const string RibbonId = "PythonShell" ;
12+
13+ [ CommandMethod ( "InitPythonConsole" ) ]
14+ public override void Execute ( )
15+ {
16+ CreateRibbon ( ) ;
17+ MgdDbg . App MgdDbgSnoop = new App ( ) ;
18+ MgdDbgSnoop . Initialize ( ) ;
19+ }
20+
21+ private void CreateRibbon ( )
22+ {
23+ RibbonControl ribbon = ComponentManager . Ribbon ;
24+ if ( ribbon != null )
25+ {
26+ RibbonTab rtab = ribbon . FindTab ( RibbonId ) ;
27+ if ( rtab != null )
28+ {
29+ ribbon . Tabs . Remove ( rtab ) ;
30+ }
31+
32+ rtab = new RibbonTab ( ) ;
33+ rtab . Title = RibbonTitle ;
34+ rtab . Id = RibbonId ;
35+ ribbon . Tabs . Add ( rtab ) ;
36+ AddContentToTab ( rtab ) ;
37+ }
38+ }
39+
40+ private void AddContentToTab ( RibbonTab rtab )
41+ {
42+ rtab . Panels . Add ( AddPanelOne ( ) ) ;
43+ rtab . Panels . Add ( AddPanelTwo ( ) ) ;
44+ }
45+
46+ private static RibbonPanel AddPanelOne ( )
47+ {
48+ RibbonPanelSource rps = new RibbonPanelSource ( ) ;
49+ rps . Title = "Cad Python Shell" ;
50+ RibbonPanel rp = new RibbonPanel ( ) ;
51+ rp . Source = rps ;
52+ RibbonButton rci = new RibbonButton ( ) ;
53+ rci . Name = "Python Shell Console" ;
54+ rps . DialogLauncher = rci ;
55+ //create button1
56+ var addinAssembly = typeof ( IronPythonConsoleApp ) . Assembly ;
57+ RibbonButton btnPythonShell = new RibbonButton
58+ {
59+ Orientation = Orientation . Vertical ,
60+ AllowInStatusBar = true ,
61+ Size = RibbonItemSize . Large ,
62+ Name = "Run CPS" ,
63+ ShowText = true ,
64+ Text = "Run CPS" ,
65+ Description = "Start Write Python Console\n Command: PythonShellConsole" ,
66+ Image = CADPythonShellApplication . GetEmbeddedPng ( addinAssembly ,
67+ "CADPythonShell.Resources.Python-16.png" ) ,
68+ LargeImage =
69+ CADPythonShellApplication . GetEmbeddedPng ( addinAssembly , "CADPythonShell.Resources.Python-32.png" ) ,
70+ CommandHandler = new RelayCommand ( new IronPythonConsoleCommand ( ) . Execute )
71+ } ;
72+ rps . Items . Add ( btnPythonShell ) ;
73+ //create button2
74+ RibbonButton btnConfig = new RibbonButton
75+ {
76+ Orientation = Orientation . Vertical ,
77+ AllowInStatusBar = true ,
78+ Size = RibbonItemSize . Large ,
79+ Name = "Configure CPS" ,
80+ ShowText = true ,
81+ Text = "Configure CPS" ,
82+ Description = "Configure Cad Python Shell\n Command: PythonShellSetting" ,
83+ Image = CADPythonShellApplication . GetEmbeddedPng ( addinAssembly ,
84+ "CADPythonShell.Resources.Settings-16.png" ) ,
85+ LargeImage =
86+ CADPythonShellApplication . GetEmbeddedPng ( addinAssembly , "CADPythonShell.Resources.Settings-32.png" ) ,
87+ CommandHandler = new RelayCommand ( new ConfigureCommand ( ) . Execute )
88+ } ;
89+ //Add the Button to the Tab
90+ rps . Items . Add ( btnConfig ) ;
91+ return rp ;
92+ }
93+
94+ private static RibbonPanel AddPanelTwo ( )
95+ {
96+ RibbonPanelSource rps = new RibbonPanelSource ( ) ;
97+ rps . Title = "Lookup" ;
98+ RibbonPanel rp = new RibbonPanel ( ) ;
99+ rp . Source = rps ;
100+ RibbonButton rci = new RibbonButton ( ) ;
101+ rci . Name = "Lookup" ;
102+ rps . DialogLauncher = rci ;
103+ //create button1
104+ var addinAssembly = typeof ( IronPythonConsoleApp ) . Assembly ;
105+ RibbonButton btnSnoop = new RibbonButton
106+ {
107+ Orientation = Orientation . Vertical ,
108+ AllowInStatusBar = true ,
109+ Size = RibbonItemSize . Large ,
110+ Name = nameof ( MgdDbgAction . Snoop ) ,
111+ ShowText = true ,
112+ Text = "Snoop" ,
113+ Description = "Start snoop object inside Autocad \n Command: Snoop" ,
114+ Image = CADPythonShellApplication . GetEmbeddedPng ( addinAssembly ,
115+ "CADPythonShell.Resources.Find-16.png" ) ,
116+ LargeImage =
117+ CADPythonShellApplication . GetEmbeddedPng ( addinAssembly , "CADPythonShell.Resources.Find-32.png" ) ,
118+ CommandHandler = new RelayCommand ( new SnoopCommand ( ) . Execute ) ,
119+ AllowInToolBar = true ,
120+ KeyTip = "Quick Snoop An objects Sample" ,
121+ } ;
122+ RibbonButton btnSnoopDB = new RibbonButton
123+ {
124+ Orientation = Orientation . Vertical ,
125+ AllowInStatusBar = true ,
126+ Size = RibbonItemSize . Large ,
127+ Name = nameof ( MgdDbgAction . SnoopDB ) ,
128+ ShowText = true ,
129+ Text = "Snoop\n Database" ,
130+ Description = $ "Start snoop Database inside Autocad \n Command: { nameof ( MgdDbgAction . SnoopDB ) } ",
131+ Image = CADPythonShellApplication . GetEmbeddedPng ( addinAssembly ,
132+ "CADPythonShell.Resources.database-16.png" ) ,
133+ LargeImage =
134+ CADPythonShellApplication . GetEmbeddedPng ( addinAssembly , "CADPythonShell.Resources.database-32.png" ) ,
135+ CommandHandler = new RelayCommand ( new SnoopDBCommand ( ) . Execute ) ,
136+ AllowInToolBar = true ,
137+ KeyTip = "Snoop Database" ,
138+ } ;
139+ RibbonButton btnSnoopEd = new RibbonButton
140+ {
141+ Orientation = Orientation . Vertical ,
142+ AllowInStatusBar = true ,
143+ Size = RibbonItemSize . Large ,
144+ Name = nameof ( MgdDbgAction . SnoopEd ) ,
145+ ShowText = true ,
146+ Text = "Snoop\n Editor" ,
147+ Description = $ "Start snoop Snoop Editor inside Autocad \n Command: { nameof ( MgdDbgAction . SnoopEd ) } ",
148+ Image = CADPythonShellApplication . GetEmbeddedPng ( addinAssembly ,
149+ "CADPythonShell.Resources.editor-16.png" ) ,
150+ LargeImage =
151+ CADPythonShellApplication . GetEmbeddedPng ( addinAssembly , "CADPythonShell.Resources.editor-32.png" ) ,
152+ CommandHandler = new RelayCommand ( new SnoopEditorCommand ( ) . Execute ) ,
153+ AllowInToolBar = true ,
154+ KeyTip = "Snoop Editor" ,
155+ } ;
156+ RibbonButton btnSnooByHandle = new RibbonButton
157+ {
158+ Orientation = Orientation . Vertical ,
159+ AllowInStatusBar = true ,
160+ Size = RibbonItemSize . Large ,
161+ Name = nameof ( MgdDbgAction . SnoopByHandle ) ,
162+ ShowText = true ,
163+ Text = "Snoop\n By Handle" ,
164+ Description = $ "Start snoop Snoop Editor inside Autocad \n Command: { nameof ( MgdDbgAction . SnoopByHandle ) } ",
165+ Image = CADPythonShellApplication . GetEmbeddedPng ( addinAssembly ,
166+ "CADPythonShell.Resources.handle-16.png" ) ,
167+ LargeImage =
168+ CADPythonShellApplication . GetEmbeddedPng ( addinAssembly , "CADPythonShell.Resources.handle-32.png" ) ,
169+ CommandHandler = new RelayCommand ( new SnoopByHanderCommand ( ) . Execute ) ,
170+ AllowInToolBar = true ,
171+ KeyTip = "Snoop By Handle" ,
172+ } ;
173+ RibbonButton btnSnoopEntities = new RibbonButton
174+ {
175+ Orientation = Orientation . Vertical ,
176+ AllowInStatusBar = true ,
177+ Size = RibbonItemSize . Large ,
178+ Name = nameof ( MgdDbgAction . SnoopEnts ) ,
179+ ShowText = true ,
180+ Text = "Snoop\n Entities" ,
181+ Description = $ "Start snoop Snoop Entities inside Autocad \n Command: { nameof ( MgdDbgAction . SnoopEnts ) } ",
182+ Image = CADPythonShellApplication . GetEmbeddedPng ( addinAssembly ,
183+ "CADPythonShell.Resources.snoopentities-16.png" ) ,
184+ LargeImage =
185+ CADPythonShellApplication . GetEmbeddedPng ( addinAssembly , "CADPythonShell.Resources.snoopentities-32.png" ) ,
186+ CommandHandler = new RelayCommand ( new SnoopEntitiesCommand ( ) . Execute ) ,
187+ AllowInToolBar = true ,
188+ KeyTip = "Snoop By Entities" ,
189+ } ;
190+ RibbonButton btnSnoopEntitiesNested = new RibbonButton
191+ {
192+ Orientation = Orientation . Vertical ,
193+ AllowInStatusBar = true ,
194+ Size = RibbonItemSize . Large ,
195+ Name = nameof ( MgdDbgAction . SnoopNEnts ) ,
196+ ShowText = true ,
197+ Text = "Snoop\n Nested Entities" ,
198+ Description = $ "Start snoop Snoop Entities inside Autocad \n Command: { nameof ( MgdDbgAction . SnoopNEnts ) } ",
199+ Image = CADPythonShellApplication . GetEmbeddedPng ( addinAssembly ,
200+ "CADPythonShell.Resources.snoopentitiesnes-16.png" ) ,
201+ LargeImage =
202+ CADPythonShellApplication . GetEmbeddedPng ( addinAssembly , "CADPythonShell.Resources.snoopentitiesnes-32.png" ) ,
203+ CommandHandler = new RelayCommand ( new SnoopEntitiesNestedCommand ( ) . Execute ) ,
204+ AllowInToolBar = true ,
205+ KeyTip = "Snoop By Nested Entities" ,
206+ } ;
207+ RibbonButton btnSnoopEvents = new RibbonButton
208+ {
209+ Orientation = Orientation . Vertical ,
210+ AllowInStatusBar = true ,
211+ Size = RibbonItemSize . Large ,
212+ Name = nameof ( MgdDbgAction . SnoopEvents ) ,
213+ ShowText = true ,
214+ Text = "Snoop\n Events" ,
215+ Description = $ "Start snoop Snoop Events inside Autocad \n Command: { nameof ( MgdDbgAction . SnoopEvents ) } ",
216+ Image = CADPythonShellApplication . GetEmbeddedPng ( addinAssembly ,
217+ "CADPythonShell.Resources.events-16.png" ) ,
218+ LargeImage =
219+ CADPythonShellApplication . GetEmbeddedPng ( addinAssembly , "CADPythonShell.Resources.events-32.png" ) ,
220+ CommandHandler = new RelayCommand ( new SnoopEventsCommand ( ) . Execute ) ,
221+ AllowInToolBar = true ,
222+ KeyTip = "Snoop Events" ,
223+ } ;
224+ RibbonButton btnSnoopTestFramework = new RibbonButton
225+ {
226+ Orientation = Orientation . Vertical ,
227+ AllowInStatusBar = true ,
228+ Size = RibbonItemSize . Large ,
229+ Name = nameof ( MgdDbgAction . SnoopTests ) ,
230+ ShowText = true ,
231+ Text = "Snoop\n Test Framework" ,
232+ Description = $ "Start snoop Snoop Test Framework inside Autocad \n Command: { nameof ( MgdDbgAction . SnoopTests ) } ",
233+ Image = CADPythonShellApplication . GetEmbeddedPng ( addinAssembly ,
234+ "CADPythonShell.Resources.test-16.png" ) ,
235+ LargeImage =
236+ CADPythonShellApplication . GetEmbeddedPng ( addinAssembly , "CADPythonShell.Resources.test-32.png" ) ,
237+ CommandHandler = new RelayCommand ( new TestFrameworkCommand ( ) . Execute ) ,
238+ AllowInToolBar = true ,
239+ KeyTip = "Snoop Test Framework" ,
240+ } ;
241+ rps . Items . Add ( btnSnoop ) ;
242+ rps . Items . Add ( btnSnoopDB ) ;
243+ rps . Items . Add ( btnSnoopEd ) ;
244+ rps . Items . Add ( btnSnooByHandle ) ;
245+ rps . Items . Add ( btnSnoopEntities ) ;
246+ rps . Items . Add ( btnSnoopEntitiesNested ) ;
247+ rps . Items . Add ( btnSnoopEvents ) ;
248+ rps . Items . Add ( btnSnoopTestFramework ) ;
249+ return rp ;
250+ }
251+ }
252+ }
0 commit comments