 
					
				
		
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm trying to modify my dynamic block's visibility. My code successfully displays the correct visibility of the block but it seems as if it doesn't commit to it. What I mean by this is, when I close the drawing and open it back up, it is back to its default state (or first visible state). Below are screenshots of the results I get (along with the code below those screenshots). The first image shows an example of the default state when I manually insert it without trying to modify the visibility.
Default state ("Panneau 48x38x12_AC_AF"):
Take a look at the code when I step through it.
My prop.Value is equal to the default state even once I've stepped through when my variable panelVal is as another state ... What's weird is; it displays the correct visibility of the panelVal, but has the selection still set to the default state:
If I then close the drawing and open it back up, it is set back to the default state... If I manually change it, there's no problem. It keeps the changes, but the point of this is to get it all automated.
Code
    Private Sub ModifyVisibility(ByVal Path As String, ByVal blkname As String)
        Dim bId As ObjectId
        Dim utils As New AcadNetUtils
        Dim currLayer As New clsLayer
        Dim acDoc As Document = AcApp.Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
        Dim tempDb As New Database(False, True)
        Dim ed As Editor = acDoc.Editor
        Dim acBlkTbl As BlockTable
        Dim acBlkTblRec As BlockTableRecord
        Dim br As BlockReference
        Dim insertJig As InsertBlockJig
        Dim pr As PromptResult
        Dim oldSnapMode As Integer = AcApp.Application.GetSystemVariable("SNAPMODE")
        Using lock As DocumentLock = acDoc.LockDocument
            Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView()
            AcApp.Application.SetSystemVariable("SNAPMODE", 1)
            'Get the current database and start the Transaction Manager
            tempDb.ReadDwgFile(Path, FileOpenMode.OpenForReadAndReadShare, True, "")
            acCurDb.Insert(blkname, tempDb, False)
            tempDb.Dispose()
            'Start a transaction
            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
                'Open Model space for write
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
                acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
                br = New BlockReference(Point3d.Origin, acBlkTbl.Item(blkname))
                Dim btr As BlockTableRecord = acTrans.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead)
                'Sets the correct text for the panel. ex: "Panneau 60x49x18_AC"
                If br <> Nothing AndAlso br.IsDynamicBlock Then
                    Dim pc As DynamicBlockReferencePropertyCollection = br.DynamicBlockReferencePropertyCollection
                    Dim panelVal As String = "Panneau 60x49x18_AC"
                    'Loop through to get the info for each property
                    For Each prop As DynamicBlockReferenceProperty In pc
                        Select Case prop.PropertyName
                            Case "Visibility"
                                prop.Value = panelVal 'DOES NOT GET MODIFIED
                        End Select
                    Next
                End If
                'Using InsertBlockJig class to insert the block
                insertJig = New InsertBlockJig(br)
                pr = ed.Drag(insertJig)
                If pr.Status = PromptStatus.OK Then
                    bId = acBlkTblRec.AppendEntity(br) 'Add the object to the drawing
                    acTrans.AddNewlyCreatedDBObject(br, True) 'Tell the transaction
                    acTrans.Commit() 'Commit the changes and dispose of the transaction
                    'Release objects
                    acBlkTblRec = Nothing
                    acBlkTbl = Nothing
                End If
            End Using
        End Using
    End SubWhat could be causing this issue? Am I not setting the block's visibility correctly?
Thanks for the help in advance,
Alex
Solved! Go to Solution.
