[IronPython]选择集示例
大家好,我有一些关于Ipy的工作要做,我想我会分享一些片段。
这可能不是最佳实现,但它显示了处理时要考虑的几个重要事项。在这种情况下,传递一个对象数组(Python没有数组)。
该方法基本上是一些用于选择特定类型的一些对象的模板代码,如果需要,将它扩展到多种类型并不困难。
您将需要Tim的PyAcad.Net来在acad中运行它,如果您需要一个简单的dll来运行脚本,我将在另一个线程中发布一个简单的VS解决方案,稍后我将在此链接。python脚本:
# 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() # 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 -对于IronPython 1.1,acad 2007-9
**** Hidden Message ***** 谢谢你,米克
页:
[1]