Jump to content

Change the dynamic property of a bloc using python


Grimoult

Recommended Posts

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 by SLW210
Added Code Tags!
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)
        

 

x.png.aff9ed4e109771cc38c22c13fbd57101.png

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...