Files
Explode all sketch blocks in all drawing sheets
Code
Module: mMain
'Demonstrates how to explode all blocks in all sheets in a drawing.
'Preconditions: Drawing is open.
'Results: All sketch blocks on all sheets are exploded.
'Notes:
'To explode a sketch block instance in a drawing, the sheet _
containing the instance must be active.
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Option Compare Text
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swBlockDef As SldWorks.SketchBlockDefinition
Dim vSheetNames As Variant
Dim vBlockDefs As Variant
Dim vInstances As Variant
Dim i As Integer, j As Integer, k As Integer
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
vSheetNames = swDraw.GetSheetNames
For i = 0 To UBound(vSheetNames)
swDraw.ActivateSheet vSheetNames(i)
vBlockDefs = swModel.SketchManager.GetSketchBlockDefinitions
If IsEmpty(vBlockDefs) Then Exit Sub
For j = 0 To UBound(vBlockDefs)
Set swBlockDef = vBlockDefs(j)
vInstances = swBlockDef.GetInstances
If IsEmpty(vInstances) = False Then
For k = 0 To UBound(vInstances)
swModel.SketchManager.ExplodeSketchBlockInstance vInstances(k)
Next k
End If
Next j
Next i
End Sub