3 Replies Latest reply on Aug 10, 2018 6:54 AM by Alejandro Español

    Explode nested blocks / "Unlink" Blocks

    Sascha Smolny


      I'm trying to write a macro to make blocks independently.

      The manual way: Explode the Block, select the sketch elements, create new block.

      We need that often, so a button to "unlink" the Block would be nice. We need it, to make changes in sketch without affecting the other Blocks.


      I have tried many ways. But no one will work.

      1.) If i explode the Block, i dont know which elements are included.


      2.) Create New Block with macro:

      Dim swApp As Object
      Dim Part As Object
      Dim boolstatus As Boolean
      Dim longstatus As Long, longwarnings As Long
      Sub main()
      Set swApp = _
      Set Part = swApp.ActiveDoc
      Dim myModelView As Object
      Set myModelView = Part.ActiveView
      Dim skMgr As SketchManager
      Set skMgr = Part.SketchManager
      Dim vBlocks As Variant
      vBlocks = skMgr.GetSketchBlockDefinitions
      Dim pBlock As SketchBlockDefinition
      'Try only with the first Block
      Set pBlock = vBlocks(0)
      Debug.Print (pBlock.FileName)
      'Use the first Instance
      Dim BlockInst As SketchBlockInstance
      Set BlockInst = pBlock.GetInstances(0)
      Dim SK As Sketch
      Set SK = pBlock.GetSketch
      Dim Point As MathPoint
      Set Point = BlockInst.InstancePosition
      'Test1: Create New Block with Sketch from Block
      'Dim Block As SketchBlockDefinition
      'Set Block = skMgr.MakeSketchBlockFromSketch(Nothing, SK)
      'Test2: Create New Block and Explode the old Block in the Block
      BlockInst.Select False, Nothing
      Dim Block As SketchBlockDefinition
      Set Block = skMgr.MakeSketchBlockFromSelected(Point)
      'Test2/1 Select BlockInstance and Explode
      'Dim NewBlockInstance As SketchBlockInstance
      'Set NewBlockInstance = Block.GetSketch.GetSketchBlockInstances(0) 'BlockInstance from Block in Block
      'NewBlockInstance.Select False, Nothing
      'skMgr.ExplodeSketchBlockInstance Nothing
      'Same test with Parameter:
      'skMgr.ExplodeSketchBlockInstance NewBlockInstance
      'Test2/2 Same as Test2/1 with edit Block
      Dim NewBlockInstance As SketchBlockInstance
      Set NewBlockInstance = Block.GetSketch.GetSketchBlockInstances(0) 'BlockInstance from Block in Block
      NewBlockInstance.Select False, Nothing
      'skMgr.ExplodeSketchBlockInstance Nothing
      'Same test with Parameter:
      skMgr.ExplodeSketchBlockInstance NewBlockInstance
      Part.SketchManager.EndEditSketchBlock True
      End Sub



      Test1: If i create the new Block with the Sketch from the other Block i get a new Block that contains all Blocks in Drawing. That is wrong. I dont know why.

      Test2: I think this is a way that can function.
      I Create a new Block wich contains the old Block. Than i only need to explode the nested Block. But i dont know how to explode that. In the Drawing view i can select the nested Block and can use Explode. But how can i do that with the api?

      Or is there a other way to make this?