Hi All,
I have a bit of work to do with Ipy and I thought I'd share some snippets as I go.
This is probably not the best implementation but it shows a couple of important things to consider when dealing with .net from Python, in this case passing an array of objects (Python doesn't have arrays).
The method is basically some boiler plate code for selecting some objects of a particular type, it wouldn't be hard to extend this for multiple types if needed.
You will need Tim's PyAcad.Net to run this in acad, if you need a simple dll just to run scripts I will be posting a simple VS solution in another thread which I'll link in here at a later date.
The python script:
# selection.py
# Created: 7th May 2009 Copyright Mick Duprez
# initialise and import our lib's
import sys
#----- change these paths as required for your system and lib.file locations
sys.path.append('C:\\Program Files\\AutoCAD 2009')
sys.path.append('C:\\DCS_3D\\ipyscripts')
import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
clr.AddReferenceToFile('acdbmgd.dll')
clr.AddReferenceToFile('acmgd.dll')
import System.Windows.Forms as winfrm
from System.Drawing import *
import Autodesk.AutoCAD.DatabaseServices as acdb
import Autodesk.AutoCAD.ApplicationServices.Application as app
import Autodesk.AutoCAD.EditorInput as aced
from System import Array
# method to select entities using a simple filter for entity type
def select_ents(typecode, value):
doc = app.DocumentManager.MdiActiveDocument
ed = doc.Editor
tv = acdb.TypedValue(typecode, value)
filter = Array[acdb.TypedValue]([tv]) # create a .net array for acad to use
res = ed.GetSelection(aced.SelectionFilter(filter))
if res.Status != aced.PromptStatus.OK or res.Status == aced.PromptStatus.Cancel:
return None
ids = res.Value.GetObjectIds() # gives us an array object
return ids
#### test the selection method:
ids = select_ents(0, "3DSOLID")
doc = app.DocumentManager.MdiActiveDocument
ed = doc.Editor
idlist = list(ids) #convert the array to a python list
for id in idlist:
ed.WriteMessage(id.ToString() + '\n')
PS - for IronPython 1.1, acad 2007-9