Grimoult Posted June 28, 2024 Posted June 28, 2024 (edited) Hello everyone, (This is my fist post ever, so don't hesitate to ask me more information if needed) I'm trying to write a python code to modify a dynamic property of a bloc outside of AutoCAD with python. Here are some information: - The bloc name is "MESH_RECT". It is a rectangle with a dynamic parameter WIDTH and LENGTH - The dynamic parameter I want to modify is named "WIDTH" - I want to write a python code which would be able to insert the bloc and define width value to the value X (3 for example) I manage to insert the block, but can't modify the parameter width. Here is the python code I have started: import pyautocad acad = pyautocad.Autocad() doc = acad.ActiveDocument ms = doc.ModelSpace insertion_point = pyautocad.APoint(0, 0) inserted_block = ms.InsertBlock(insertion_point, "MESH_RECT", 1000, 1000, 1000, 0) print(inserted_block.hasattributes) if inserted_block.IsDynamicBlock: # Iterate through dynamic properties dynamic_properties = inserted_block.GetDynamicBlockProperties() if dynamic_properties: for prop in dynamic_properties: print(f"Property: {prop.PropertyName}, Value: {prop.Value}") if prop.PropertyName == "Width": prop.Value = 3 else: print("No dynamic properties found.\n") Thanks in advance for your help ! Edited June 28, 2024 by SLW210 Added Code Tags! Quote
SLW210 Posted June 28, 2024 Posted June 28, 2024 Please use Code Tags for your code in the future. (<> in the editor toolbar) I have moved your thread to the .NET, ObjectARX & VBA Forum, please post in the most appropriate forum. Can you post the drawing? Quote
Grimoult Posted June 28, 2024 Author Posted June 28, 2024 Voici le bloc que je cherche à manipuler: example.dwg Quote
Grimoult Posted June 28, 2024 Author Posted June 28, 2024 6 hours ago, Grimoult said: Hello everyone, (This is my fist post ever, so don't hesitate to ask me more information if needed) I'm trying to write a python code to modify a dynamic property of a bloc outside of AutoCAD with python. Here are some information: - The bloc name is "MESH_RECT". It is a rectangle with a dynamic parameter WIDTH and LENGTH - The dynamic parameter I want to modify is named "WIDTH" - I want to write a python code which would be able to insert the bloc and define width value to the value X (3 for example) I manage to insert the block, but can't modify the parameter width. Here is the python code I have started: import pyautocad acad = pyautocad.Autocad() doc = acad.ActiveDocument ms = doc.ModelSpace insertion_point = pyautocad.APoint(0, 0) inserted_block = ms.InsertBlock(insertion_point, "MESH_RECT", 1000, 1000, 1000, 0) print(inserted_block.hasattributes) if inserted_block.IsDynamicBlock: # Iterate through dynamic properties dynamic_properties = inserted_block.GetDynamicBlockProperties() if dynamic_properties: for prop in dynamic_properties: print(f"Property: {prop.PropertyName}, Value: {prop.Value}") if prop.PropertyName == "Width": prop.Value = 3 else: print("No dynamic properties found.\n") Thanks in advance for your help ! example.dwg Quote
Danielm103 Posted June 29, 2024 Posted June 29, 2024 using the wrappers I'm working on import traceback from pyrx_impx import Rx, Ge, Gi, Db, Ap, Ed, Ax def PyRxCmd_xdoit1() -> None: try: axAp = Ax.getApp() axDoc = axAp.ActiveDocument axModel = axDoc.ModelSpace inserted_block = axModel.InsertBlock((0,0,0), "MESH_RECT", 1000, 1000, 1000, 0) if inserted_block.IsDynamicBlock: prop: Ax.IAcadDynamicBlockReferenceProperty for prop in inserted_block.GetDynamicBlockProperties(): print(f"Property: {prop.PropertyName}, Value: {prop.Value}") if prop.PropertyName == "Width": prop.Value = 300.0 else: print("No dynamic properties found.\n") except Exception as err: traceback.print_exception(err) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.