I'm having problems with DynamicBlockReferenceProperty Value -property. The value is not changing when I'm trying to set it. So far I've recognized that trying to set a value of wrong type causes an exception to be thrown, but in this example case there is no exception thrown nor does the value of the property change.
foreach (DynamicBlockReferenceProperty prop in blockReference.DynamicBlockReferencePropertyCollection) { if (prop.PropertyName != "Property1") continue; if (prop.ReadOnly) continue; Console.WriteLine(string.Format("Current value: {0}", prop.Value));
// Outputs correctly: "Current value: 0" foreach (object obj in prop.GetAllowedValues()) // contains 2 values, 0 and 1 if (!prop.Value.Equals(obj)) // skips the first value { prop.Value = obj; Console.WriteLine(string.Format("New value: {0}", prop.Value));
// Outputs "New value: 0"
// Should output "New value: 1" } }
I have also tried stuff like this:
Console.WriteLine(prop.Value); // Outputs "0" prop.Value = (short)1; Console.WriteLine(prop.Value); // Outputs "0", should output "1"
Am I missing something, such as not setting some specific flag in the 'blockReference' which would allow setting of the property values?
Hi,
I think you have to update the block table record first, using: MyBlkTblRec.UpdateAnonymousBlocks()
Ok, I found the solution to the problem. Actually it wasn't all that complicated, but thanks to gasty I realized what was wrong.
I was attempting to modify the dynamic property directly on the BlockReference, but I had not added it to the current drawing's modelspace. After appending the BlockReference to the model space, it started working.