VB.Net Explode block

VB.Net Explode block

Jedimaster
Collaborator Collaborator
1,976 Views
1 Reply
Message 1 of 2

VB.Net Explode block

Jedimaster
Collaborator
Collaborator

I am trying create a routine for AutoCAD 2015.

I am using VSC 2013 with ObjectARX 2015.

 
The routine finds all block references in the drawing. Looks to see if there are nested blocks with attributes under the block. If all criteria are met explode the parent block.

 

Public Shared Sub ExplodeNestedBlocks()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
doc.LockDocument()
Application.DocumentManager.MdiActiveDocument.LockDocument()
Dim ed As Editor = doc.Editor
Dim acTypValAr(0) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.Start, "INSERT"), 0)
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
Dim trans As Transaction = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()
Dim acSSPrompt As PromptSelectionResult
acSSPrompt = ed.SelectAll(acSelFtr)
If acSSPrompt.Status = PromptStatus.OK Then
Dim acSSet As SelectionSet = acSSPrompt.Value
For Each Itm As SelectedObject In acSSet
Dim BlkRef As BlockReference = trans.GetObject(Itm.ObjectId, OpenMode.ForWrite, False, True)
Dim BlkRec As BlockTableRecord = trans.GetObject(BlkRef.BlockTableRecord, OpenMode.ForWrite, False, True)
If BlkRec.XrefStatus = XrefStatus.NotAnXref And _
BlkRef.IsAProxy = False And _
BlkRef.IsDynamicBlock = False And _
BlkRec.Explodable = True And _
BlkRec.HasAttributeDefinitions = False And _
BlkRec.IsAProxy = False And _
BlkRec.IsDependent = False And _
BlkRec.IsDynamicBlock = False And _
BlkRec.IsLayout = False Then
For Each ent In BlkRec
If ent.ObjectClass.DxfName = "INSERT" Then
Dim SubBlkRef As BlockReference = trans.GetObject(ent, OpenMode.ForWrite, False, True)
Dim SubBlkRec As BlockTableRecord = trans.GetObject(SubBlkRef.BlockTableRecord, OpenMode.ForWrite, False, True)
If SubBlkRec.HasAttributeDefinitions = True Then

 

<<EXPLODE BLKREF>> This is the part of the routine that escapes me right now. BlkRef.ExplodeToOwnerSpace and BlkRef.Explode do not seem to work.


End If
End If
Next
End If
Next

trans.Commit()

 End If
End Sub

 

Thanks in advance for any insight.

0 Likes
Accepted solutions (1)
1,977 Views
1 Reply
Reply (1)
Message 2 of 2

_gile
Consultant
Consultant
Accepted solution

Hi,

 

Using ExplodeToOwnerSpace() method you do not have to add each component to the block reference owner space but you have to erase the block reference:

 

BlkRef.ExplodeToOwnerSpace()
BlkRef.Erase()

 

Using Explode() method you have to add each component to the block owner space and erase it too.

 

var objs = new DBObjectCollection();
br.Explode(objs);
var space = (BlockTableRecord)tr.GetObject(br.OwnerId, OpenMode.ForWrite);
foreach (DBObject obj in objs)
{
    space.AppendEntity((Entity)obj);
    tr.AddNewlyCreatedDBObject(obj, true);
}
br.Erase();


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub