4 Replies Latest reply on Oct 26, 2015 2:58 PM by Amen Allah Jlili

    Delete Broken-Out-Section

    Rafi Sokol

      How do I  use API code to delet Broken-Out-Section?

        • Re: Delete Broken-Out-Section
          Deepak Gupta

          Why you need a macro for that?

            • Re: Delete Broken-Out-Section
              Rafi Sokol

              I have a macro that handles views, dimensions, annotations etc. in a drawing.

                • Re: Delete Broken-Out-Section
                  Amen Allah Jlili



                  This is an illustration of my early answer. I've tested on SW 2015 and it's running fine.




                  'Active window is a sw drawing


                  'Previous selection will be cleared (for safety reasons)

                  'All broken out sections will be selected and deleted without prompting warning (silent delete)


                  'BY JELLY SW <3 FOR EVER


                  Dim swApp As SldWorks.SldWorks

                  Dim swModel As SldWorks.ModelDoc2

                  Dim swSelectionMgr As SldWorks.SelectionMgr

                  Dim swDrawingDoc As SldWorks.DrawingDoc

                  Dim swView As SldWorks.View

                  Dim VswView As Variant

                  Dim swSheet As SldWorks.Sheet

                  Dim swBrokenOutSection As SldWorks.Feature

                  Dim VswBrokenOutSections As Variant

                  Dim swSelectData As SldWorks.SelectData



                  Sub main()

                  Set swApp = Application.SldWorks

                  Set swModel = swApp.ActiveDoc

                  swModel.ClearSelection2 (True)

                  Set swDrawingDoc = swModel

                  Set swSheet = swDrawingDoc.GetCurrentSheet

                  Set swSelectionMgr = swModel.SelectionManager

                  VswView = swSheet.GetViews

                  If Not IsEmpty(VswView) Then

                  For i = LBound(VswView) To UBound(VswView)

                  Set swView = VswView(i)

                  VswBrokenOutSections = swView.GetBreakOutSections

                  If Not IsEmpty(VswBrokenOutSections) Then

                  For j = LBound(VswBrokenOutSections) To UBound(VswBrokenOutSections)

                  Set swBrokenOutSection = VswBrokenOutSections(j)

                  Dim bool As Boolean

                  bool = swSelectionMgr.AddSelectionListObject(swBrokenOutSection, swSelectData)

                  Next j

                  End If

                  Next i

                  End If

                  If swSelectionMgr.GetSelectedObjectCount > 0 Then

                  swModel.DeleteSelection (False)

                  End If

                  End Sub

              • Re: Delete Broken-Out-Section
                Amen Allah Jlili

                I hope with these steps would help you can accomplish what you want.


                1. Declare your SLDWORKS object, cast SLDWORKS.ACTIVEDOC into a MODELDOC object


                3. declare DRAWINGDOC object and cast the MODELDOC into it.

                4. Declare a SHEET object.

                5. Use the DRAWINGDOC.GETCURRENTSHEET method to return the current sheet from your active model.
                6. Get the sheet's views using SHEET.GETVIEWS (If you're doing a VB macro, you want to assign the return of that method to a VARIANT type)
                7. Repeat previous step only this time you're using VIEW.BROKENOUTSECTIONS method to get the broken out sections,  from the views, into a variant.
                8. Traverse the variant of the broken out sections and assign every element of the variant to FEATURE object which you want to add to SELECTIONMANAGER and then use the method MODELDOC.DELETESELECTION to delete the broken out sections.


                Get inspired from this example: