- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Assuming I have a BlockReferenceId As ObjectId returned from a function that selects an object, how do I go about saving this specific object to a new file after exploding it's contents (nested explode if possible).
I have been trying to add the objects as DBObjects to a separate Database() and save that, but it isn't working correctly.
Public Function SelectBlockRef(ByVal doc As Document) As ObjectId
Dim peo As New PromptEntityOptions("Select a Part to Delete")
peo.AllowNone = True
peo.SetRejectMessage("Only BlockReferences may be selected.")
peo.AddAllowedClass(GetType(BlockReference), True)
Dim per As PromptEntityResult = doc.Editor.GetEntity(peo)
If per.Status = PromptStatus.OK Then
Using doc.TransactionManager.StartTransaction()
Dim br As BlockReference = DirectCast(per.ObjectId.GetObject(OpenMode.ForRead), BlockReference)
Return br.BlockTableRecord
End Using
Else
Return ObjectId.Null
End If
End Function
Dim selId = SelectBlockRef(doc)
If (selId.IsNull) Then
Core.Application.ShowAlertDialog("Please select an block to continue.")
Return
End If
Using tempFileDb As New Database(False, False)
Using tr As Transaction = db.TransactionManager.StartTransaction()
'Dim bt As BlockTable = tr.GetObject(selId, OpenMode.ForRead)
'Dim btr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead)
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(selId, OpenMode.ForRead), BlockTableRecord)
Dim addedSelectedObjects As Int32 = 0
For Each btrID As ObjectId In btr
Dim dboObj As DBObject = tr.GetObject(btrID, OpenMode.ForRead)
tempFileDb.AddDBObject(dboObj)
addedSelectedObjects += 1
Next
If addedSelectedObjects > 0 Then
tr.Commit()
tempFileDb.SaveAs(tempDirectory + tempFileName, DwgVersion.AC1027)
End If
End Using
End Using
Solved! Go to Solution.
Link copied