Skip to content

Commit 8b0def8

Browse files
committed
add support snoop object from shell console and python code
1 parent 4c71b7d commit 8b0def8

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

CADPythonShell/SnoopCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class SnoopCommand
77
[CommandMethod("Snoop")]
88
public void Execute()
99
{
10-
new CADSnoop.SnoopCommand().Execute();
10+
new CADSnoop.SnoopCommand().Snoop();
1111
}
1212
}
1313
}

CADPythonShell/init.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
from Autodesk.AutoCAD.ApplicationServices import *
44
from Autodesk.AutoCAD.ApplicationServices.Core import *
55
from Autodesk.AutoCAD.Runtime import *
6+
from CADSnoop import SnoopCommand
67
app = Application
78
doc = app.DocumentManager.MdiActiveDocument
89
db = doc.Database
910
ed = doc.Editor
11+
sn = SnoopCommand()
1012
def quit():
1113
__window__.Close()
1214
exit = quit
13-
15+
def snoop():
16+
sn.Snoop()
17+
def snoop(dbObj):
18+
sn.Snoop(dbObj)
1419
# a fix for the __window__.Close() bug introduced with the non-modal console
1520
class WindowWrapper(object):
1621
def __init__(self, win):

CADRuntime/CADRuntime.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,7 @@
6868
<ItemGroup>
6969
<Compile Remove="ExternalCommandAssemblyBuilder.cs" />
7070
</ItemGroup>
71+
<ItemGroup>
72+
<ProjectReference Include="..\AutoCADLookup\CADSnoop.csproj" />
73+
</ItemGroup>
7174
</Project>

CADRuntime/ScriptExecutor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public ScriptScope SetupEnvironment(ScriptEngine engine)
126126

127127
public void SetupEnvironment(ScriptEngine engine, ScriptScope scope)
128128
{
129-
// these variables refer to the signature of the IExternalCommand.Execute method
129+
// these variables refer to the signature of the IExternalCommand.Snoop method
130130
scope.SetVariable("__message__", _message);
131131
scope.SetVariable("__result__", 0);
132132

@@ -140,6 +140,7 @@ public void SetupEnvironment(ScriptEngine engine, ScriptScope scope)
140140

141141
// reference Autocad or Civil3D Api Document and Application
142142
engine.Runtime.LoadAssembly(typeof(Autodesk.AutoCAD.ApplicationServices.Document).Assembly);
143+
engine.Runtime.LoadAssembly(typeof(CADSnoop.SnoopCommand).Assembly);
143144
// also, allow access to the RPS internals
144145
engine.Runtime.LoadAssembly(typeof(ScriptExecutor).Assembly);
145146
}

Script Examples/snoopobjectdemo.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import clr
2+
import sys
3+
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
4+
import os
5+
import math
6+
clr.AddReference('acmgd')
7+
clr.AddReference('acdbmgd')
8+
clr.AddReference('accoremgd')
9+
# Import references from AutoCAD
10+
from Autodesk.AutoCAD.Runtime import *
11+
from Autodesk.AutoCAD.ApplicationServices import *
12+
from Autodesk.AutoCAD.EditorInput import *
13+
from Autodesk.AutoCAD.DatabaseServices import *
14+
from Autodesk.AutoCAD.Geometry import *
15+
adoc = Application.DocumentManager.MdiActiveDocument
16+
ed = adoc.Editor
17+
output =[]
18+
with adoc.LockDocument():
19+
with adoc.Database as db:
20+
with db.TransactionManager.StartTransaction() as t:
21+
bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
22+
btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
23+
for objectid in btr:
24+
obj1 = t.GetObject(objectid, OpenMode.ForRead)
25+
output.append(obj1)
26+
print(obj1)
27+
if(len(output)==0):
28+
print("Dont have any object in view \nPlease draw something!")
29+
else:
30+
from CADSnoop import SnoopCommand
31+
a = output[0]
32+
sn = SnoopCommand()
33+
sn.Snoop(a)
34+
## you can use shell to snoop with method :
35+
# snoop(a)
36+
## or use sn.Snoop(a) from shell command
37+
# note with option snoop() will be snoop by pick object same with button from in ribbon

0 commit comments

Comments
 (0)