2 Replies Latest reply on Aug 12, 2016 1:47 AM by Chennai Inopc

    how to get the sketch segments

    Chennai Inopc

      Dear All,

       

      I am trying to create a macro to get the sketch segment inside the block.

       

      Dim swApp As SldWorks.SldWorks

      Dim swmodel As SldWorks.ModelDoc2

      Dim swselmgr As SldWorks.SelectionMgr

      Dim swblk As SldWorks.SketchBlockInstance

      Dim swblkdef As SldWorks.SketchBlockDefinition

      Dim swarc As SldWorks.SketchArc

      Dim i As Integer

      Dim swseg As SldWorks.SketchSegment

      Sub main()

       

      Set swApp = Application.SldWorks

      Set swmodel = swApp.ActiveDoc

      Set swselmgr = swmodel.SelectionManager

      Set swblk = swselmgr.GetSelectedObject5(1)

      swmodel.SketchManager.EditSketchBlock

      Set swblkdef = swblk.Definition

       

      Please help me out this..to get the sketchsegment inside the block

        • Re: how to get the sketch segments
          Viktor Bovzdarenko

          Hi

          Try this:

          Dim swApp                   As SldWorks.SldWorks

          Dim swModel                 As SldWorks.ModelDoc2

           

           

          Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Dim swSelMgr As SldWorks.SelectionMgr: Set swSelMgr = swModel.SelectionManager

              Dim swFeat As SldWorks.Feature: Set swFeat = swSelMgr.GetSelectedObject6(1, 0)

              Dim blockDef As SketchBlockDefinition: Set blockDef = swFeat.GetSpecificFeature2

             

              Dim blockSketch As ISketch: Set blockSketch = blockDef.GetSketch

              Dim varSerments As Variant:  varSerments = blockSketch.GetSketchSegments

              Debug.Print "Block consists of '" & UBound(varSerments) + 1 & "' segments"

          End Sub

           

          varSerments - are sketch segments

          The macro will print to immediate window the number of segments in selected block.

          Regards

            • Re: how to get the sketch segments
              Chennai Inopc

              Dear Viktor,

               

              Thanks for your code.

              It is working fine. i have made the slight the change in code.

               

              Dim swApp                   As SldWorks.SldWorks

              Dim swModel                 As SldWorks.ModelDoc2

                Sub main()

                  Set swApp = Application.SldWorks

                  Set swModel = swApp.ActiveDoc

                  Dim swSelMgr As SldWorks.SelectionMgr: Set swSelMgr = swModel.SelectionManager

                ' Dim swFeat As SldWorks.Feature: Set swFeat = swSelMgr.GetSelectedObject5(1)

                  Dim swblk As SldWorks.SketchBlockInstance: Set swblk = swSelMgr.GetSelectedObject5(1)

                  Dim blockDef As SketchBlockDefinition: Set blockDef = swblk.Definition

                  Dim blockSketch As ISketch: Set blockSketch = blockDef.GetSketch

                  Dim varSerments As Variant:  varSerments = blockSketch.GetSketchSegments

                  Debug.Print "Block consists of '" & UBound(varSerments) + 1 & "' segments"

              End Sub

               

              Regards

              Manikandan.B