AnsweredAssumed Answered

How to Explode a Block in a drawing view through macro?

Question asked by A. Mahesh on Jul 13, 2011
Latest reply on Aug 2, 2011 by A. Mahesh

Hi,

 

 

  My macro is below:  (Related files are attached)

               

Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swSktManager As SldWorks.SketchManager
    Dim swModel As SldWorks.ModelDoc2
    Dim swMathUtility As SldWorks.MathUtility
    Dim swMathPoint As SldWorks.MathPoint
    Dim PointCoords(2) As Double
    Dim swSktBlkDef As SldWorks.SketchBlockDefinition
    Dim vSheetProps             As Variant
    Dim swSheet                 As SldWorks.Sheet

    Dim boolstatus As Boolean

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSktManager = swModel.SketchManager
    Set swMathUtility = swApp.GetMathUtility
   
    Set swSheet = swModel.GetCurrentSheet
   
    PointCoords(0) = 0.05 'X
    PointCoords(1) = 0  ' Y
    PointCoords(2) = 0 ' Z


    swModel.ActivateView "Drawing View1"
     
    Set swMathPoint = swMathUtility.CreatePoint(PointCoords)
   
    Set swSktBlkDef = swSktManager.MakeSketchBlockFromFile(swMathPoint, "File Location\THROUGH HARDENED.SLDBLK", False, 2, 0)
   
    swModel.ClearSelection2 True

 

    'BLOCK EDIT:

 

    boolstatus = swModel.Extension.SelectByID2("Line2/THROUGH HARDENED-1", "SKETCHSEGMENT", 0#, 0#, 0#, False, 0, Nothing, 0)
    swModel.SketchManager.EditSketchBlock
    boolstatus = swModel.Extension.SelectByID2("Line2/THROUGH HARDENED-1", "SKETCHSEGMENT", 0#, 0#, 0#, False, 0, Nothing, 0)
    Dim myDimension As Object
    Set myDimension = swModel.Parameter("L@THROUGH HARDENED")
    myDimension.SystemValue = 0.023
    swModel.SketchManager.EndEditSketchBlock True

 

   'BLOCK EXPLODE:

  

   Dim myBlockInstance As Object
   boolstatus = swModel.ActivateView("Drawing View1")
   boolstatus = swModel.Extension.SelectByID2("Line2/THROUGH HARDENED-1", "SKETCHSEGMENT", 0#, 0#, 0#, False, 0, Nothing, 0)
   swModel.SketchManager.ExplodeSketchBlockInstance Nothing   ' My problem is started here
   
End Sub

Attachments

Outcomes