Dynamic Block object visibility state

Dynamic Block object visibility state

ceduca
Explorer Explorer
1,706 Views
3 Replies
Message 1 of 4

Dynamic Block object visibility state

ceduca
Explorer
Explorer

Hi, 

 

I need some help.  @_gile 

 

How to change an object that is in a visibility state to another?
I cloned (or added) some objects inside the block. How do I determine in which state of visibility the object should stay?

All cloned objects are in all visibility states. They must remain in the "remover" state of visibility and i don't know how to put them in this state of visibility. Cloned objects are on a different layer.

 

I've attached some dwg files for better understanding.

 

I used this code to clone the objects in the block.

 

 

                    For Each id As ObjectId In btr
                        Dim ent As Entity = id.GetObject(OpenMode.ForRead)

                        If layersOriginais.Contains(UCase(ent.Layer)) Then
                            Dim posicaoLayer As Integer = Array.IndexOf(layersOriginais, ent.Layer)

                            Dim collection As New ObjectIdCollection()
                            collection.Add(ent.Id)

                            Dim mapping As New IdMapping()
                            db.DeepCloneObjects(collection, btr.Id, mapping, False)

                            Dim ent2 As Entity

                            Using Tx As Transaction = db.TransactionManager.StartTransaction()

                                Dim pair1 As IdPair = mapping(ent.ObjectId)

                                ent2 = TryCast(Tx.GetObject(pair1.Value, OpenMode.ForWrite), Entity)

                                ent2.Layer = layersSP(posicaoLayer)
                                ent2.ColorIndex = 256

                                blkref.RecordGraphicsModified(True)
                                Tx.Commit()
                                Tx.Dispose()
                            End Using
                        End If
                    Next

                    btr.UpdateAnonymousBlocks()
                Next

 

Thanks.

0 Likes
1,707 Views
3 Replies
Replies (3)
Message 2 of 4

norman.yuan
Mentor
Mentor

Mr Gille Chantaeu probably is taking much needed break, we all miss his kind and expertly advises.

 

Anyway, it is fairly easy to set dynamic blockreference's dynamic property (including Visibility, which could have a property name other than "Visibility"): simply loop through DynamicBlockReferencePropertyCollection of a BlockReference object to find the target property by its name, and then set the property to a valid value.

 

For example, assume there is a BlockReference, and its the Visibility property is named "Visibility1" and has 2 state "Show1" and "Show2", and you want to set the property to "Show2". You do:

 

foreach (var prop in TheBlockRef.DynamicBlockReferencePropertyCollection)

{

    if (prop.PropertyName.ToUpper()=="VISIBILITY1")

    {

       prop.Value="Show2";

       break;

    }

}

 

Since Visibility's state is usually a list of state names, sometimes you may want to verify if the value you want to set the Visibility state is valid state name or not. Then, you can get the allowed state name list from DynamicBlockReferenceProperty,GetAllowedValues() and compare to see if your value is vaild or not before using it to set the property.

 

So, regardless what other things your process does, as long as you can get to each target BlockReference, you can then manipulate its dynamic properties this way.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 4

ceduca
Explorer
Explorer

Norman,

 

thanks for your reply.

 

The problem is not with the change of state of visibility of the block but with the visibility of the objects that were cloned.

The objects that were cloned are in all visibility states and should only be in one state.

How to put cloned objects in a certain state of visibility?

 

Did you see the attached files?

0 Likes
Message 4 of 4

_gile
Consultant
Consultant

Hi,

 

AFAIK, there are none API to deal with dynamic properties within the block definition.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes