Message 1 of 3
WblockCloneObjects
Not applicable
02-12-2010
11:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to use a selectionSet to create a new dwg file from part of an old one. The old one is open in the editor and the new one will hopefully not need to be opened in the editor. Currently the code copies the objects (I think), but they never get added to the actual drawing. I just end up with an empty drawing, even though, unless I leave the for loop in, I don't get any errors. Can anyone tell me what I'm doing wrong? Here's the code I'm attempting to use.
{code}
'create new autocad document
Dim newDB As DatabaseServices.Database = New DatabaseServices.Database(True, True)
'wblockClone to copy selection set into the new document's database
'copy first
Dim curDWG = Application.DocumentManager.MdiActiveDocument
Dim curDB As DatabaseServices.Database = curDWG.Database
Dim curTransMan As DatabaseServices.TransactionManager
Dim curTrans As DatabaseServices.Transaction
Dim curBT As DatabaseServices.BlockTable
Dim curBTR As DatabaseServices.BlockTableRecord
Dim myMap As New DatabaseServices.IdMapping
Dim myObjs As New DatabaseServices.ObjectIdCollection
Dim newTransMan As DatabaseServices.TransactionManager
Dim newTrans As DatabaseServices.Transaction
Dim newBT As DatabaseServices.BlockTable
Dim newBTR As DatabaseServices.BlockTableRecord
curTransMan = curDB.TransactionManager
curTrans = curTransMan.StartTransaction
curBT = curDB.BlockTableId.GetObject(OpenMode.ForRead)
curBTR = curBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
If Not selset Is Nothing Then
For i As Integer = 0 To selset.Count - 1
myObjs.Add(selset(i).ObjectId)
Next
End If
newTransMan = newDB.TransactionManager
newTrans = newTransMan.StartTransaction
newBT = newDB.BlockTableId.GetObject(OpenMode.ForRead)
newBTR = newBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
newDB.WblockCloneObjects(myObjs, newBT.ObjectId, myMap, DuplicateRecordCloning.Replace, False)
For i As Integer = 0 To myObjs.Count - 1
newTrans.AddNewlyCreatedDBObject(myObjs(i).GetObject(OpenMode.ForRead), True) ' This line doesn't work (eNotFromThisDocument)
Next
newTrans.Commit()
curTrans.Commit()
{code}
{code}
'create new autocad document
Dim newDB As DatabaseServices.Database = New DatabaseServices.Database(True, True)
'wblockClone to copy selection set into the new document's database
'copy first
Dim curDWG = Application.DocumentManager.MdiActiveDocument
Dim curDB As DatabaseServices.Database = curDWG.Database
Dim curTransMan As DatabaseServices.TransactionManager
Dim curTrans As DatabaseServices.Transaction
Dim curBT As DatabaseServices.BlockTable
Dim curBTR As DatabaseServices.BlockTableRecord
Dim myMap As New DatabaseServices.IdMapping
Dim myObjs As New DatabaseServices.ObjectIdCollection
Dim newTransMan As DatabaseServices.TransactionManager
Dim newTrans As DatabaseServices.Transaction
Dim newBT As DatabaseServices.BlockTable
Dim newBTR As DatabaseServices.BlockTableRecord
curTransMan = curDB.TransactionManager
curTrans = curTransMan.StartTransaction
curBT = curDB.BlockTableId.GetObject(OpenMode.ForRead)
curBTR = curBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
If Not selset Is Nothing Then
For i As Integer = 0 To selset.Count - 1
myObjs.Add(selset(i).ObjectId)
Next
End If
newTransMan = newDB.TransactionManager
newTrans = newTransMan.StartTransaction
newBT = newDB.BlockTableId.GetObject(OpenMode.ForRead)
newBTR = newBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
newDB.WblockCloneObjects(myObjs, newBT.ObjectId, myMap, DuplicateRecordCloning.Replace, False)
For i As Integer = 0 To myObjs.Count - 1
newTrans.AddNewlyCreatedDBObject(myObjs(i).GetObject(OpenMode.ForRead), True) ' This line doesn't work (eNotFromThisDocument)
Next
newTrans.Commit()
curTrans.Commit()
{code}