2 Replies Latest reply on Aug 26, 2016 2:50 PM by Marc Vivant

    Get Feature or Feature ID from selected sketch entity

    Marc Vivant

      Hi all,

       

      I need to the feature or feature ID of the sketch that contains a sketch entity I have selected.

       

      For example, Sketch1 in my tree as a Spline. When I click this spline and run the macro, I would like to be able to have Sketch1 returned or the feature number of sketch1. Is there an API for this? I couldn't find one that works with sketch entites, I may be mistaking however.

       

      Thanks,

       

      Marc

        • Re: Get Feature or Feature ID from selected sketch entity
          Ivana Kolin
          
          Option Explicit
          Dim swApp                                         As SldWorks.SldWorks
          Dim selMgr                                        As SldWorks.SelectionMgr
          Dim Model                                         As SldWorks.ModelDoc2
          Dim swSketchPoint                                 As SldWorks.SketchPoint
          Dim swSketchSegment                               As SldWorks.SketchSegment
          Dim SketchFeature                                 As SldWorks.Feature
          Dim swSkech                                       As SldWorks.Sketch
          
          
          Sub main()
              Set swApp = Application.SldWorks
              Set Model = swApp.ActiveDoc
          
              Set selMgr = Model.SelectionManager
              'Get the sketch from the SelectionMgr
              Select Case selMgr.GetSelectedObjectType3(1, -1)
              Case swSelEXTSKETCHPOINTS
                  Set swSketchPoint = selMgr.GetSelectedObject6(1, -1)
                  Set swSkech = swSketchPoint.GetSketch
              Case swSelEXTSKETCHSEGS
                  Set swSketchSegment = selMgr.GetSelectedObject6(1, -1)
                  Set swSkech = swSketchSegment.GetSketch
              Case Else
                  MsgBox "Unknown type: " & selMgr.GetSelectedObjectType3(1, -1)
                  Exit Sub
              End Select
              Set SketchFeature = swSkech
              MsgBox SketchFeature.Name
          
          
          End Sub