[python-win32] Scripting AutoCAD
Josh collins
isjoshreally at gmail.com
Wed Jan 4 07:30:39 EST 2017
Hello community, please help if you can!
I'm adapting a script that I found online here
<https://gist.githubusercontent.com/thengineer/7157510/raw/05dcde3bf47a8db04af98462e23103296996857b/autocadblockreader.py>
.
I'm trying to change it so that it can open a document, and then change it.
Here's what I have:
import win32com.client
acad = win32com.client.DispatchEx("AutoCAD.Application")
acad.Visible = True
doc = acad.Documents.Open("*path*") # Document object
# iterate trough all objects (entities) in the currently opened drawing
# and if its a BlockReference, display its attributes and some other things.
for entity in acad.Database.Blocks:
name = entity.EntityName
if name == 'AcDbBlockReference':
HasAttributes = entity.HasAttributes
if HasAttributes:
for attrib in entity.GetAttributes():
string = str(attrib.TextString)
print(entity.Name)
print(entity.Layer)
print(entity.ObjectID)
print(" {}: {}".format(attrib.TagString, attrib.TextString))
#update text
attrib.TextString = "success!"
attrib.Update()
I'm getting the error attached.
Does anybody know where I'm going wrong?
Thanks,
Josh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20170104/dba9268d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: error.jpg
Type: image/jpeg
Size: 14145 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-win32/attachments/20170104/dba9268d/attachment.jpg>
More information about the python-win32
mailing list