Message 1 of 9
copy a layer from a drawing to another
Not applicable
01-24-2008
04:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, Guys.
My name is Bruno. I'm trying to copy a layer from a drawing to another, using dot net, but I'm not getting to do it. I already did it with VBA (using copybjects), and with ARX (using deepclone), but when I do using dot net, appears a error message when I open the layer properties manager: "no active transactions".
Here is the code I'm using:
Private Sub copyLayerFromAnotherDrawing(ByVal layerStr As String, ByVal fromFileStr As String)
Dim LT, myLt As LayerTable
Dim tm, myTm As DBTransMan
Dim ta, myTa As Transaction
Dim dbMe, dbFrom As New Database
Dim lyr, copy As LayerTableRecord
Dim itens As SymbolTableEnumerator
Dim id As ObjectId
Dim idMap As New IdMapping()
dbMe = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
dbFrom.ReadDwgFile(fromFileStr, IO.FileShare.Read, True, "")
tm = dbFrom.TransactionManager
ta = tm.StartTransaction
LT = ta.GetObject(dbFrom.LayerTableId, OpenMode.ForRead, False)
myTm = dbMe.TransactionManager
myTa = myTm.StartTransaction
myLt = myTa.GetObject(dbMe.LayerTableId, OpenMode.ForWrite, False)
itens = LT.GetEnumerator
Do While itens.MoveNext
id = itens.Current
lyr = tm.GetObject(id, OpenMode.ForRead)
If lyr.Name.CompareTo(layerStr) = 0 Then
copy = lyr.DeepClone(myLt, idMap, False)
myLt.Add(copy)
myTa.AddNewlyCreatedDBObject(copy, True)
Exit Do
End If
Loop
myTa.Commit()
ta.Commit()
End Sub
Thanx for de help.
My name is Bruno. I'm trying to copy a layer from a drawing to another, using dot net, but I'm not getting to do it. I already did it with VBA (using copybjects), and with ARX (using deepclone), but when I do using dot net, appears a error message when I open the layer properties manager: "no active transactions".
Here is the code I'm using:
Private Sub copyLayerFromAnotherDrawing(ByVal layerStr As String, ByVal fromFileStr As String)
Dim LT, myLt As LayerTable
Dim tm, myTm As DBTransMan
Dim ta, myTa As Transaction
Dim dbMe, dbFrom As New Database
Dim lyr, copy As LayerTableRecord
Dim itens As SymbolTableEnumerator
Dim id As ObjectId
Dim idMap As New IdMapping()
dbMe = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
dbFrom.ReadDwgFile(fromFileStr, IO.FileShare.Read, True, "")
tm = dbFrom.TransactionManager
ta = tm.StartTransaction
LT = ta.GetObject(dbFrom.LayerTableId, OpenMode.ForRead, False)
myTm = dbMe.TransactionManager
myTa = myTm.StartTransaction
myLt = myTa.GetObject(dbMe.LayerTableId, OpenMode.ForWrite, False)
itens = LT.GetEnumerator
Do While itens.MoveNext
id = itens.Current
lyr = tm.GetObject(id, OpenMode.ForRead)
If lyr.Name.CompareTo(layerStr) = 0 Then
copy = lyr.DeepClone(myLt, idMap, False)
myLt.Add(copy)
myTa.AddNewlyCreatedDBObject(copy, True)
Exit Do
End If
Loop
myTa.Commit()
ta.Commit()
End Sub
Thanx for de help.