- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I'm hoping someone here can help me with what I've been beating my head against the wall trying to do all day. Essentially this is the problem I'm trying to solve:
- I have two open drawings, a source and a destination drawing in ACAD
- I have different layers and linetypes in each drawing
- I need to get the objects on a specified layer in the source drawing and copy them to the destination drawing, but ensure that they are put on a specified layer in that drawing which differs in name from the original drawing.
I've tried coming at this a few different ways, but can't really seem to come a conclusion on how to do this. WBlockCloneObjects, of course, allows me to clone the items to the new drawing, but in doing so, drags along all the layers and linetypes with it which I don't want "contaminating" my new drawing. I'm trying to keep the conversion as clean as possible. I can't pre-change the layer name or linetype, etc as the destination for these values doesn't exist in the source drawing.
Is there a way to create a new entity (an anonymous one, independent of the source ObjectClass that I need so I don't have to create multiple routines to handle each one), not attached to a DB, copy the values from the source DB entity and then modify the layer, linetype, color etc before appending the entity to the destination database?
Here is my code for what I have, but since I don't really have a clue where to turn with this, all this really shows at the moment is a straight cloning of the objects from one DB to another. As a side note, I'm working in Civil 3D 2011 and when WBlockCloneObjects is called an "AutoCAD Map Messages" window appears with no messages in it. Anyone seen that before?
I appreciate any help or ideas that anyone can provide,
Chris Welk
Public Function CopyLayerContents(ByVal acdocSource As Document, ByVal strSourceLayer As String, ByVal acdocDest As Document, ByVal strDestLayer As String, ByVal bCopyBlocks As Boolean) As Boolean
Dim bComplete = False
Dim acSourceDB As Database = acdocSource.Database
Dim acDestDB As Database = acdocDest.Database
Dim acSourceBlockTable As BlockTable
Dim acSourceModelSpace As BlockTableRecord
Dim acDestBlockTable As BlockTable
Dim acDestModelSpace As BlockTableRecord
Dim acSourceLayerTable As LayerTable
Dim acDestLayerTable As LayerTable
Dim acObjIDs As ObjectIdCollection = New ObjectIdCollection()
Dim acIDMap As IdMapping = New IdMapping()
Try
Using acDocLock As DocumentLock = acdocDest.LockDocument()
Using acSourceTrans As Transaction = acSourceDB.TransactionManager.StartTransaction()
Using acDestTrans As Transaction = acDestDB.TransactionManager.StartTransaction()
acSourceBlockTable = acSourceTrans.GetObject(acSourceDB.BlockTableId, OpenMode.ForRead)
acSourceModelSpace = acSourceTrans.GetObject(acSourceBlockTable(BlockTableRecord.ModelSpace), OpenMode.ForRead)
acSourceLayerTable = acSourceTrans.GetObject(acSourceDB.LayerTableId, OpenMode.ForRead)
acDestBlockTable = acDestTrans.GetObject(acDestDB.BlockTableId, OpenMode.ForWrite)
acDestModelSpace = acDestTrans.GetObject(acDestBlockTable(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
acDestLayerTable = acDestTrans.GetObject(acDestDB.LayerTableId, OpenMode.ForRead)
If acSourceLayerTable.Has(strSourceLayer) And acDestLayerTable.Has(strDestLayer) Then
For Each acObjID As ObjectId In acSourceModelSpace
Dim acEnt As Entity = acSourceTrans.GetObject(acObjID, OpenMode.ForRead)
If acEnt.Layer = strSourceLayer Then
acObjIDs.Add(acObjID)
End If
Next acObjID
acSourceDB.WblockCloneObjects(acObjIDs, acDestModelSpace.ObjectId, acIDMap, _
DuplicateRecordCloning.Replace, False)
acDestTrans.Commit()
bComplete = True
Else
bComplete = False
End If
End Using
End Using
End Using
Catch ex As Exception
MessageBox.Show("Error importing objects: " & ex.Message & vbCrLf & vbTab & ex.StackTrace, "DASMAP - " & System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButtons.OK, MessageBoxIcon.Error)
bComplete = False
End Try
Return bComplete
End Function
Solved! Go to Solution.

