[python-win32] AutoCAD attribute issue
??
T.J.Will at hotmail.com
Mon May 23 19:10:17 EDT 2016
Hi Mark,
Recently I'm working on the AutoCAD attribute extraction. When I install the pywin32 and write the code as follow:
Before into the code, I want to ask one question. If I wish to extract from dxf file can I use the same method as below?
--------------------------------------------------------------------------------------------
import win32com.client
acad = win32com.client.Dispatch("AutoCAD.Application")
ms = acad.ActiveDocument
for entity in acad.ActiveDocument.ModelSpace:
name = entity.EntityName
if name == 'AcDbBlockReference':
HasAttributes = entity.HasAttributes
if HasAttributes:
print(entity.Name)
print(entity.Layer)
print(entity.ObjectID)
for attrib in entity.GetAttributes():
print("{}:{}".format(attrib.TagString, attrib.TextString))
attrib.TextString='modified with python'
arrtib.Update()
I encountered an error says :
==================== RESTART: F:\PHP\DXF_Data\Script4.py ====================
Traceback (most recent call last):
File "E:\python3.5\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221005, 'invalid string', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:\PHP\DXF_Data\Script4.py", line 3, in <module>
acad = win32com.client.Dispatch("__**AutoCAD.Application")
File "E:\python3.5\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "E:\python3.5\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "E:\python3.5\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'invalid string', None, None)
>>>
So I go back to the makeup.py to check if there is a autocad type library but I didn't found it.
Can I get any suggestion from you?
Best Regards,
Will
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20160523/4354bd2a/attachment.html>
More information about the python-win32
mailing list