2 jiangxinhuan jiangxinhuan 于 2018.05.16 22:01 提问

利用pyautocad在dwg中插入一个块

代码如下:

from pyautocad import Autocad,APoint

acad = Autocad(create_if_not_exists = True)
acad.prompt("hello, cad\n")
p1 = APoint(0,0)
acad.model.InsertBlock(p1,"D:\python\MyPyAutoCADProjects\lightingbox.dwg")
print acad.doc.Name

文件路径没有错,运行错误,错误提示如下:

hello, cad

Traceback (most recent call last):
File "D:\python\MyPyAutoCADProjects\insertBlock.py", line 10, in
acad.model.InsertBlock(p1,"D:\python\MyPyAutoCADProjects\lightingbox.dwg")
File "C:\Python27\lib\site-packages\comtypes\client\lazybind.py", line 163, in caller
return self._comobj._invoke(descr.memid, descr.invkind, 0, *args)
File "C:\Python27\lib\site-packages\comtypes\automation.py", line 664, in _invoke
dp, var, None, argerr)
COMError: (-2147352562, '\xce\xde\xd0\xa7\xb5\xc4\xb2\xce\xca\xfd\xca\xfd\xc4\xbf\xa1\xa3', (None, None, None, 0, None))

弄了一个晚上了,求大神指点迷津。

1个回答

oyljerry
oyljerry   Ds   Rxr 2018.05.16 22:24
已采纳

com错误,应该是你传的参数dwg文件可能有问题

jiangxinhuan
jiangxinhuan   2018.05.16 22:26

解决了,把后面的几个选填的参数补齐就可以了。
acad.model.InsertBlock(p1,"D:\python\MyPyAutoCADProjects\lightingbox.dwg",1,1,1,0)
真是醉了

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!