受this answer的启发,我正在尝试使用python和win32com客户端要操作打开的AutoCAD文件,并将给定图层中的所有对象收集到选择集中,请执行以下操作:
from comtypes.client import *
from comtypes.automation import *
import win32com.client
acad = GetActiveObject("AutoCAD.Application")
doc = acad.ActiveDocument
SSet = doc.SelectionSets[0]
FilterType = win32com.client.VARIANT(VT_ARRAY|VT_I2, [8])
FilterData = win32com.client.VARIANT(VT_ARRAY|VT_VARIANT, ["Layer1"])
SSet.Select(5, FilterType, FilterData)
select命令将弹出以下错误消息:
ArgumentError: argument 2: <class 'TypeError'>: Cannot put win32com.client.VARIANT(8194, [8]) in VARIANT
我模模糊糊地理解这个错误,因为它在抱怨第二个参数的类型/格式(可能还有第三个,如果它走得那么远的话),但我不明白为什么:它似乎在告诉我,它不能在需要一个变量的插槽中接受一个特定的变量,但我不知道为什么。你知道吗
回答时请记住,我精通python、AutoCAD和老式的AutoLISP编码,但对win32com(或任何其他com)几乎一无所知,尤其是对变体,或者让AutoCAD使用python。你知道吗
(对于其他老学究:我正在尝试模仿SSGET命令。)
就我个人而言,我对选择集不是很有经验,所以我偶然发现了一个没有使用它们的解决方案。下面的代码是在模型空间中的每个对象之间循环的示例,检查它是否有特定的层,并构建一个字符串,该字符串将通过
SendCommand
选择所有对象。你知道吗我相信您实际上也可以使用
SendCommand
来操作选择集。(类似于autolisp中的(command "ssget")
)我个人发现这个解决方案更容易解决。你知道吗相关问题 更多 >
编程相关推荐