Created
October 25, 2013 16:27
-
-
Save thengineer/7157510 to your computer and use it in GitHub Desktop.
AutoCAD automation via python and win32com: read all attributes from BlockReferences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import win32com.client | |
acad = win32com.client.Dispatch("AutoCAD.Application") | |
doc = acad.ActiveDocument # 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.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)) | |
# update text | |
attrib.TextString = 'modified with python' | |
attrib.Update() |
Dear thengineer!
I use Visual Studio Code. But i can't setup Module WIN32, PYCOM.
Please tell me how i can do?
Thank you so much
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thengineer!
First of all, thx for such a good code.
Could you PLEASE help me to find a way to solve my problem:
need to change #acad.ActiveDocument.PaperSpace#, so the script can look through all layouts in dwg file and do the job