3 Replies Latest reply on Aug 21, 2017 7:29 AM by Manikandan Babu

    Get the selected ID

    Xu Sean

      My part has many features, I want to get the ID of the selected feature by mouse clicking .What's the api?

        • Re: Get the selected ID
          Manikandan Babu

          Hi Xu,

           

          Get the ID of feature.

          Dim swApp As SldWorks.SldWorks

          Dim swmodel As SldWorks.ModelDoc2

          Dim swfeat As SldWorks.Feature

          Sub main()

           

           

          Set swApp = Application.SldWorks

          Set swmodel = swApp.ActiveDoc

          Set swfeat = swmodel.SelectionManager.GetSelectedObject6(1, -1)

          Debug.Print swfeat.GetID

          End Sub

           

          Manikandan

            • Re: Get the selected ID
              Xu Sean

              Hi,Manikandan

              Thanks for your answer .The code works  when I click the feature on the feature tree,but it appears the warning "unsupported  type" when I click the feature on the 3d model.What's wrong?

                • Re: Get the selected ID
                  Manikandan Babu

                  Hi Xu,

                   

                  Please go through the below lines.

                   

                  Dim swApp As SldWorks.SldWorks

                  Dim swmodel As SldWorks.ModelDoc2

                  Dim swfeat As SldWorks.Feature

                  Dim Seltype As Integer

                  Dim swface As SldWorks.Face2

                  Dim swSafeEnt As SldWorks.Entity

                   

                  Sub main()

                  Set swApp = Application.SldWorks

                  Set swmodel = swApp.ActiveDoc

                  Seltype = swmodel.SelectionManager.GetSelectedObjectType3(1, -1)

                   

                  If Seltype = 22 Then 'Feature Selection in FM tree

                   

                  Set swfeat = swmodel.SelectionManager.GetSelectedObject6(1, -1)

                  Debug.Print swfeat.GetID

                   

                  ElseIf Seltype = 2 Then 'Face selection in 3d model

                   

                  Set swface = swmodel.SelectionManager.GetSelectedObject6(1, -1)

                   

                  Set swfeat = swface.GetFeature

                   

                  Debug.Print swfeat.GetID

                   

                  End If

                   

                  End Sub

                   

                  Manikandan