1 Reply Latest reply on Jun 7, 2017 8:54 AM by Alexandre Gragnano

    Get Feature from Sketch

    Alexandre Gragnano

      The SW API allow to obtain a Sketch pointer from a Feature pointer with:

      var sketch = (Sketch)feature.GetSpecificFeature2();


      There is a way to obtain a Feature pointer from a Sketch pointer?

      var sketch = modelDoc.GetActiveSketch2();
      var feature = .......................;
        • Re: Get Feature from Sketch
          Alexandre Gragnano

          OK, simply:


          var feature = (Feature)sketch;


          VBA example:


          Sub main()
              Dim app As SldWorks.SldWorks
              Dim doc As SldWorks.ModelDoc2
              Dim mgr As SldWorks.SelectionMgr
              Dim ft As SldWorks.Feature
              Dim sk As SldWorks.Sketch
              Set app = Application.SldWorks
              Set doc = app.ActiveDoc
              Set mgr = doc.SelectionManager
              Set ft = mgr.GetSelectedObject6(1, -1)
              Set sk = ft.GetSpecificFeature2
              Set ft = sk
              Debug.Print ft.Name
          End Sub