Has anybody successfully used the new feature of the layer states manager- ImportLayerStatefrom DB?
Here is some sample code but I get an unhandle exception:
"Object Reference not set to an Instance of an Object"
Using Application.DocumentManager.MdiActiveDocument.LockDocument
Using LayMan As LayerStateManager = Application.DocumentManager.MdiActiveDocument.Database.LayerStateManager
Dim Id As ObjectId = LayMan.LayerStatesDictionaryId(True)
Dim Tid As ObjectId
Try
For x As Integer = 0 To States.Count - 1
Dim NewDB As Database = New Database(True, True)
NewDB.ReadDwgFile(dwgName, IO.FileShare.Read, False, "")
Try
LayMan.ImportLayerStateFromDb(States.Item(x), NewDB)
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox(ex.Message & vbCrLf & ex.InnerException.ToString & vbCrLf & ex.ErrorStatus)
Finally
NewDB.Dispose()
End Try
LayMan.SaveLayerState(States.Item(x), 1023, Tid)
Next
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox(ex.Message & vbCrLf & ex.InnerException.ToString & vbCrLf & ex.ErrorStatus)
End Try
End Using
End Using
Application.DocumentManager.MdiActiveDocument.LockDocument.Dispose()