.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dynamic block properties not being updated using C# .NET

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
jlobo2
2384 Views, 4 Replies

Dynamic block properties not being updated using C# .NET

Hello All,

 

I am trying to update the dynamic block properties using C# .NET, but while doing so I receive the eInvalidInput exception.

 

The code I am using is below. Any help with this will be highly appreciated.

Thank You

 

 

private static void DisplayDynBlockProperties( Editor ed, BlockReference br, string name )
        {
            // Only continue is we have a valid dynamic block
            if (br != null && br.IsDynamicBlock)
            {
                ed.WriteMessage( "\nDynamic properties for \"{0}\"\n", name );

                // Get the dynamic block's property collection
                DynamicBlockReferencePropertyCollection pc = br.DynamicBlockReferencePropertyCollection;

                // Loop through, getting the info for each property 
                foreach (DynamicBlockReferenceProperty prop in pc)
                {
                    // Start with the property name, type and description
                    ed.WriteMessage( "\nProperty: \"{0}\" : {1}", prop.PropertyName, prop.UnitsType );

                    if (prop.Description != "")
                    {
                        ed.WriteMessage( "\n  Description: {0}", prop.Description );
                    }

                    // Is it read-only?
                    if (prop.ReadOnly)
                    {
                        ed.WriteMessage(" (Read Only)");
                    }
                    else if (!prop.ReadOnly)
                    {
                        ed.WriteMessage(" (READ WRITE Only)");
                    }

                    //Switch Property
                    if (prop.PropertyName == "STEM_LENGTH" )  
                    {

                        object[] values = prop.GetAllowedValues();
                        prop.Value = 48;
                        // GETTING THE EXCEPTION HERE.
                       
                    }
            .........
            ..........
       }
    }
}

 


@_gile / @Alexander.Rivilis - Could you guys please help out with this.

 

My final objective is to 

1. Read a dynamic block reference from an existing dwg file and

2. Update the properties via code using C# .NET

 

Thank You for your help in advance.

Labels (3)
4 REPLIES 4
Message 2 of 5
_gile
in reply to: jlobo2

Hi,

you should provide the dynamic block with the "STEM_LENGTH" property so that we can try to understand why 48 is not an "invalid input" for this property.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 5
jlobo2
in reply to: _gile

@_gile Please find attached.

In this block. The property is "STEM LENGTH"

Message 4 of 5
_gile
in reply to: jlobo2

The type of value for the "STEM LENGTH" property is 'double', so you have to explicitly pass a 'double' value:

prop.Value = 48.0;

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 5
jlobo2
in reply to: _gile

Wow... thank you so much.

Not sure how I missed that.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report