Obtaining the Layer States from an External DWG file

by Fenton Webb        Here’s some code which shows how to obtain the LayerStates from an external DWG file using VB.NET         _    Public Sub GetLayerStates()           Dim doc As Document = Application.DocumentManager.MdiActiveDocument      Dim ed As Editor = doc.Editor           ' select a dwg file      Dim openFileDlg As OpenFileDialog      openFileDlg = New OpenFileDialog("Select DWG File", "fenton.dwg", "dwg", "Select DWG file", 0)      ' if something was selected      If openFileDlg.ShowModal() = True Then             ' extract the file path        Dim dwgPath As String = openFileDlg.Filename             ' now get the layer state name        Dim lsName As PromptResult        lsName = ed.GetString("Enter Layer State name")        ' if ok        If lsName.Status = PromptStatus.OK Then               ' now open the dwg in a side database          Using sideDb As Database = New Database(False, True)            ' read the dwg file            sideDb.ReadDwgFile(dwgPath, IO.FileShare.Read, False, Nothing)            ' close the file and make sure we have read everything in            sideDb.CloseInput(True)                 ' get the layer state manager            Dim lsManager As LayerStateManager = sideDb.LayerStateManager                 ed.WriteMessage(vbNewLine + "Data for Later State " _    + lsName.StringResult)            ed.WriteMessage(vbNewLine + "Mask = " _    + lsManager.GetLayerStateMask(lsName.StringResult).ToString())            ' obtain all of the layers for a particular layerstate            Dim lsLayers As ArrayList = _    lsManager.GetLayerStateLayers(lsName.StringResult, False)                 For Each layer As String In lsLayers              ed.WriteMessage(vbNewLine + "Layer = " + layer)            Next               End Using        End If           End If         End Sub

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading