WblockCloneObjects

WblockCloneObjects

Anonymous
Not applicable
475 Views
2 Replies
Message 1 of 3

WblockCloneObjects

Anonymous
Not applicable
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}
0 Likes
476 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Hi,

You are far more likely to find persons knowledgeable in NET program in
the .NET newsgroup. This newsgroup is for VBA/VB6.


Regards,


Laurie Comerford

vampirefromtheitcave2 wrote:
> 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}
>
0 Likes
Message 3 of 3

Anonymous
Not applicable
Oops. Sorry I thought I was in the right one.
0 Likes