.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dynamic blocks created with .Net not keeping visibility state

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
gomahony
751 Views, 6 Replies

Dynamic blocks created with .Net not keeping visibility state

I wrote a .Net routine that inserts a group of dynamic blocks in various visibility states. When the routine is run, everything works and the blocks are inserted with the appropriate visibility states.

 

However, when I save/close and re-open the drawing, all of these blocks have reverted to the default visibility state. I've noticed that after the routine inserts the blocks, even though graphically they have the correct visibility state, in the triangle drop-down menu the visibility is still listed as the default state.

 

Is there some other property I need to set in order to get the blocks to remember their visibility state?

 

This is the relevant excerpt from my code:

 

'Open the block reference
Dim br As BlockReference = New BlockReference(New Point3d(plineInsertPt(i).X, plineInsertPt(i).Y - 3 / 32, plineInsertPt(i).Z), btrId)
br.Layer = "EE-FIRE"
br.ScaleFactors = New Scale3d(1)

'Get the block reference property collection
Dim propColl As DynamicBlockReferencePropertyCollection = br.DynamicBlockReferencePropertyCollection

'Iterate through the collection
For Each prop As DynamicBlockReferenceProperty In propColl
         If prop.PropertyName = "Visibility" Then
                 prop.Value = myTypeColl(myAddColl(i + 1))
                 Exit For
         End If
Next

ms.AppendEntity(br)
trans.AddNewlyCreatedDBObject(br, True)

 

6 REPLIES 6
Message 2 of 7
norman.yuan
in reply to: gomahony

You code looks OK.

 

Do you use AutoCAD2015 or previous version (@014 or older)? Do you test it in a computer other than your development computer?

 

If you use Acad2014 or older, and if you have to set FIBERWORLD to 0 for debugging, then that is the cause for this issue, which I ran into in my development.

 

Turn FIBERWORLD back to 1 should solve it.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 7
gomahony
in reply to: norman.yuan

Thanks for the response Norman.

 

I'm in AutoCAD 2014. I've tried on two different PCs (both running 2014), and the problem was the same on both. FIBERWORLD was set to 1 on both computers (and listed as read only). 

Message 4 of 7
norman.yuan
in reply to: gomahony

OK, I may have said "Your code looks OK" too soon:-(.

 

Because the dynamic block need to change its visibility after inserting, unless the visibility-changing entities in the block reference are AttributeReference, AutoCAD may needs to create a corresponding anonymous block definition for the blockreference in that particular visibility state.

 

So, you need to first commit the Transaction that adds the new block reference to the space (model or paper). Then you change the visibility state in a new transaction.

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 5 of 7
hgasty1001
in reply to: gomahony

Hi,

 

I think you have a wrong work flow, this is what i have:

 

1.-Create the block reference

2.-Set its properties (layer, scale, rotation)

3.-Append the block reference to the block table record:blkTblRec.AppendEntity(blkRef)

4.-Add the newly created object to the database:MyTrans.AddNewlyCreatedDBObject(blkRef,true)

5.-Add Attributes if it have

6.-Set the dynamic properties including visible state

7.-Set the Record Graphics Mofied to true: blkRef.RecordGraphicsModified(true)

8.-Update the blocktable record for the anonymous block:blkTblRec.UpdateAnonymousBlock

9.-Commit the transaction.

 

Gaston Nunez

 

 

 

 

Message 6 of 7
gomahony
in reply to: hgasty1001

Thanks for the help from both of you, Norman and Gaston. What you're saying is making sense. When I get a chance I'll re-work the code and see if that solves it (I expect it will).

Message 7 of 7
gomahony
in reply to: gomahony

Gaston, I followed that workflow and it worked as expected. Thanks again for the help!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost