TheSwamp

Code Red => .NET => Topic started by: Conveyor1 on June 18, 2018, 06:57:30 PM

Title: Dynamic Block Visibility State Options to ComboBox
Post by: Conveyor1 on June 18, 2018, 06:57:30 PM
Afternoon,

I have created an Autocad template and inside this template I have some dynamic blocks with visibility properties.  When required, I would update the block with new visibility options, delete the visible block in the drawing, then save it as the new template for everyone to use.  I have some VB.net code to see if the block exists in the drawing after the program is loaded, but I am looking for a way to populate into a ComboBox the available options from this blocks visibility states.

Does anyone know what field I would need to look at to get this information or the best way to get this information?
 
I would know the name of the uninserted block and the name of the dynamic property.
 
Please let me know your thoughts.
Title: Re: Dynamic Block Visibility State Options to ComboBox
Post by: WILL HATCH on June 18, 2018, 07:15:51 PM
Think this is essentially what you're looking for, dumps out all the properties by their name:

Code - C#: [Select]
  1.         public static Dictionary<string, DynamicBlockReferenceProperty> getProperties(this BlockReference br, bool IncludeReadOnly)
  2.         {
  3.             if (!br.IsDynamicBlock) return null;
  4.             DynamicBlockReferencePropertyCollection coll = br.DynamicBlockReferencePropertyCollection;
  5.             if (coll.Count == 0) return null;
  6.             Dictionary<string, DynamicBlockReferenceProperty> props = new Dictionary<string,DynamicBlockReferenceProperty>();
  7.             foreach (DynamicBlockReferenceProperty prop in coll)
  8.             {
  9.                 if (IncludeReadOnly | !prop.ReadOnly)
  10.                     props.Add(prop.PropertyName, prop);
  11.             }
  12.             return props;
  13.         }
Title: Re: Dynamic Block Visibility State Options to ComboBox
Post by: Conveyor1 on June 18, 2018, 07:23:58 PM
Afternoon,

Thank you for the quick reply.  Let me see if I can reprogram the structure to VB.net and see how it goes.
Title: Re: Dynamic Block Visibility State Options to ComboBox
Post by: Conveyor1 on June 18, 2018, 10:04:34 PM
Evening, I tried to keep the same idea of you code and do it a VB.net format.

However, I am not getting the result i was looking for.

For example, I want to find the dynamic block property named Visibility1, then find what options are available Visibility1.  So under Visiblity1, i could have state1, state2, state3, etc.

The code provided gives me the names of the available dynamic block properties and or what their currect setting is.

Code: [Select]
                ' Dynamic Block Type Check for Testing
                Dim myDBRPC As DynamicBlockReferencePropertyCollection = myBlkRef.DynamicBlockReferencePropertyCollection
                Dim myDBRP As DynamicBlockReferenceProperty
                Dim list1 As String = ""
                Dim list2 As String = ""
                For Each myDBRP In myDBRPC
                    list1 = list1 + myDBRP.Value.ToString
                    list2 = list2 + myDBRP.PropertyName.ToString
                Next
 

But I could have done something wrong.

Please let me know when you can.
Title: Re: Dynamic Block Visibility State Options to ComboBox
Post by: WILL HATCH on June 19, 2018, 04:10:52 PM
I've never had any compelling reason to go down this path, but I did manage to find a page that helped me turn back all those years ago... http://www.private.peterlink.ru/poleshchuk/cad/2009/tainypod06e.htm (http://www.private.peterlink.ru/poleshchuk/cad/2009/tainypod06e.htm)
Title: Re: Dynamic Block Visibility State Options to ComboBox
Post by: Conveyor1 on June 19, 2018, 04:41:33 PM
That is about 7 levels above my knowledge.  I did find this.

http://adndevblog.typepad.com/autocad/2012/05/accessing-visible-entities-in-a-dynamic-block.html (http://adndevblog.typepad.com/autocad/2012/05/accessing-visible-entities-in-a-dynamic-block.html)

Only issue I have is I have an understanding of VB.net and not so much the C# side.  Anyone have a Rosetta Stone?
Title: Re: Dynamic Block Visibility State Options to ComboBox
Post by: WILL HATCH on June 19, 2018, 06:07:06 PM
Haha, nope. I surveyed the community before choosing language originally to avoid this sort of thing. Good luck
Title: Re: Dynamic Block Visibility State Options to ComboBox
Post by: Conveyor1 on June 25, 2018, 09:10:39 AM
Morning,

We were close.

Turns out myDBRP..GetAllowedValues has the information I am looking for.
Title: Re: Dynamic Block Visibility State Options to ComboBox
Post by: WILL HATCH on June 26, 2018, 04:11:29 PM
Oh geeze... there it is staring at me from the documentation...  :idiot2: :whistling: