Insert two Visibility parameter in a block

williamdepadua
Contributor
Contributor

Insert two Visibility parameter in a block

williamdepadua
Contributor
Contributor

Hi,

 

Originally, autocad did not allow you to insert two or more VisibilityParameters into a block. I'm trying to get around this obstacle as follows.

 

I create a block and enter a VisibilityParameters manually, then copy it using code.

 

I managed to copy, but when I closed the blockeditor the parameter disappeared.

 

CODE:

 

Public Sub TESTE2()

            Dim res As PromptSelectionResult = VBCad.Application.SelectObjectsOnscreen()

            Dim sel As SelectionSet = res.Value

            Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim acCurDb As Database = acDoc.Database
            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                Dim acBlkTbl As BlockTable = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
                Dim acBlkTblRec As BlockTableRecord = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

                For Each e As SelectedObject In sel

                    Dim acEnt As Entity = acTrans.GetObject(e.ObjectId, OpenMode.ForWrite)

                    Dim c As Internal.DatabaseServices.BlockElementEntity = acEnt.Clone

                    acBlkTblRec.AppendEntity(c)
                    acTrans.AddNewlyCreatedDBObject(c, True)

                Next

                acTrans.Commit()
            End Using

        End Sub

Is there a better way to do it?

 

0 Likes
Reply
Accepted solutions (1)
390 Views
4 Replies
Replies (4)

norman.yuan
Mentor
Mentor

To me, your code does not make any sense at all, assuming you are selecting something in Block Editor mode: the code clone an entity element from a block definition (BlockTableRecord currently being edited), presumably a dynamic property parameter - visibility parameter, and then add it to the drawing databases ModelSpace (!).

 

You may want to explain why you need 2 Visibility parameters. Shouldn't you be able to create as many Visibility states as you want to let you show/hide elements in the block definition however you like?

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes

williamdepadua
Contributor
Contributor
Reason for having two VisibilityParameters is because I'm making a dynamic block for solder symbology, I wish I could control entities independently of one another. I work with about 20 different types of soldering. Soon I would have 20 states, but I have these 20 states with a welding circle for every contour, I would have the 20 states with a field welding flag and etc... So I would have a lot of states. If I could control the visibility of the field weld flag for example... Active or inactive... regardless of what symbology I'm using
0 Likes

williamdepadua
Contributor
Contributor
I'm working inside the blockeditor environment, I manually create the VisibilityParameters. Then I call my command and select the VisibilityParameters created earlier and clone it so that I have two VisibilityParameters inside a block.
0 Likes

norman.yuan
Mentor
Mentor
Accepted solution

As I said, your code does not make sense when it adds a VisibilityParameter (as BlockElementEntity) to the database's ModelSpace blocktableblock. It would make some sense to add it to the BlockTbaleRecord that is currently edited (the dynamic block definition). However, I do not think it would achieve what you wanted: AutoCAD has code behind scene that creates anonymous BlockTableRecord based on the dynamic property parameters when a dynamic BlockReference is created with unique property value. Even you can add extra VisibilityParameter without crashing AutoCAD, I suspect the code behind the scene by design would only do something based on only one VisibilityParameter is allowed. I think you are wasting time chasing a wrong thing here.

 

Also, you might be mis-using dynamic block if the VisibilityParameter (or any other dynamic property parameters, for that matter) must have so many states. You might as well create multiple dynamic blocks and split the dynamic properties among these multiple blocks based the business requirements.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes