change blockreference visibility using c#

change blockreference visibility using c#

1930331246064
Participant Participant
375 Views
3 Replies
Message 1 of 4

change blockreference visibility using c#

1930331246064
Participant
Participant

I have created two visibilities VisibilityState0 and VisibilityState1 for a blockreference, now if i want to change the visibility of that block using c# code, how can i do it if I have a blockreference object?

0 Likes
Accepted solutions (1)
376 Views
3 Replies
Replies (3)
Message 2 of 4

_gile
Consultant
Consultant
Accepted solution

Hi,

You can use this method:

public static void SetDynamicPropertyValue(BlockReference block, string propName, object value)
{
    if (block.IsDynamicBlock)
    {
        var props = block.DynamicBlockReferencePropertyCollection;
        foreach (DynamicBlockReferenceProperty prop in props)
        {
            if (prop.PropertyName.Equals(propName))
            {
                try
                {
                    prop.Value = value;
                }
                catch (System.Exception ex)
                {
                    var ed = Application.DocumentManager.MdiActiveDocument.Editor;
                    ed.WriteMessage($"\n{ex.Message}");
                }
                break;
            }
        }
    }
}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 4

1930331246064
Participant
Participant

My blockreference is not dynamic, then what to do?

0 Likes
Message 4 of 4

ActivistInvestor
Mentor
Mentor

Visibility states only work with dynamic blocks. Other than attributes, non-dynamic blocks cannot have insertions that have a differing appearance. 

0 Likes