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() |
How do i add the win32 module in my python
Hi I don't know how to create blocks with atributes, maybe someone here could help me please??
Hi, thanks for this code.
I have blocks with this attributes:
ITEM_CODE: AAAAA
WEIGHT: BBBB
NAME_LOCAL: CCCC
I can already print them and see them on the screen, but how can I extract them to work with them?
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
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
You are a prince. Thank you.