2 Replies Latest reply on Jun 6, 2017 3:56 AM by Peter Brinkhuis

    SelectEntity→How to record select entity?

    Yong Ning

      RecordEnt.jpg

      Now manual select edge. follow key code,

        tmp = SwView.SelectEntity(SwEnt, False)

      Help me, How to record of manual select entity?

       

       

       

       

       

      Private Sub del20170606()

          Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

              Set SwApp = Application.SldWorks

              Set SwModel = SwApp.ActiveDoc

          Dim SwSelMgr As SelectionMgr

          Dim SwDraw As DrawingDoc

              Set SwDraw = SwModel

          Dim SwView As View

              Set SwView = SwDraw.GetFirstView

              Set SwView = SwView.GetNextView

              Set SwModel = SwView.ReferencedDocument

              Set SwSelMgr = SwModel.SelectionManager

              Debug.Print SwModel.GetPathName

          Dim SwEnt As Entity

              Set SwEnt = SwSelMgr.GetSelectedObject5(1)

             tmp = SwView.SelectEntity(SwEnt, False)

              Stop

              Stop

      End Sub

       

       

       

      RecordEnt1.jpg

       

       

       

      How to change box volume? | SOLIDWORKS Forums  https://forum.solidworks.com/message/281202#comment-281202

      InsertMacroFeature→Area | SOLIDWORKS Forums  https://forum.solidworks.com/message/319064

       

       

      2010 SOLIDWORKS API Help - Dimension Edge in Drawing Example (VBA)  http://help.solidworks.com/2010/english/api/sldworksapi/dimension_edge_in_drawing_example_vb.htm

       

       

       

       

       

       

       

      Private Sub del3()

         Dim Str

         Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

             Set SwApp = Application.SldWorks

             Set SwModel = SwApp.ActiveDoc

         Dim SwDraw As DrawingDoc

             Set SwDraw = SwModel

         Dim SwSelMgr As SelectionMgr

             Set SwSelMgr = SwDraw.SelectionManager

         Dim SwView As View

             Set SwView = SwSelMgr.GetSelectedObject5(1)

             Set SwModel = SwView.ReferencedDocument

             Debug.Print SwModel.GetPathName

             Set SwSelMgr = SwModel.SelectionManager

             ''

         Dim SwDim As Dimension, SwDispDim As DisplayDimension

        

             Set SwDim = SwModel.Parameter("b3@Sketch")

             Debug.Print SwDim.FullName

             SwModel.ClearSelection2 True

             Str = "RD2@注解"

             tmp = SwModel.Extension.SelectByID2(Str, "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

             Debug.Print SwModel.GetPathName, SwSelMgr.GetSelectedObjectCount

             Set SwDispDim = SwSelMgr.GetSelectedObject5(1)

         Dim SwAnn As Annotation

             Set SwAnn = SwDispDim.GetAnnotation

            

         Dim Ss, Ss1

         Dim SwEnt  As Entity

             With SwAnn

                 Ss1 = .GetAttachedEntityTypes

                 Ss = .GetAttachedEntities

             End With

            

             Set SwEnt = Ss(0)

             tmp = SwView.SelectEntity(SwEnt, False)

             Stop

            

      End Sub

        • Re: SelectEntity→How to record select entity?
          VIGNESH NAGARAJAN

          Hi Yong,

           

          Try with this !!!

          Dim swApp As SldWorks.SldWorks

                  Dim Part As SldWorks.ModelDoc2

                  Dim SelMgr As SldWorks.SelectionMgr

                  Dim swedge As SldWorks.Edge

                  Dim swent As SldWorks.Entity

                  Dim bret As Boolean

           

           

                  swApp = CreateObject("sldworks.application")

                  Part = swApp.ActiveDoc

                  SelMgr = Part.SelectionManager

                  swedge = SelMgr.GetSelectedObject6(1, 0)

           

                  If swedge Is Nothing Then

                      MsgBox("Please select the edge")

                  End If

           

           

                  swent = swedge

           

           

                  Part.ClearSelection2(True)

           

           

                  bret = swent.Select2(False, 0)

                      End Sub

           

          Regards,

          Vignesh N

          • Re: SelectEntity→How to record select entity?
            Peter Brinkhuis

            I'm having a hard time understanding what you mean. Which of these two is your question?

            1. How do I create code that selects an edge?
            2. How do i create code that gets an edge that was selected by the user.

             

            If you're looking for the answer to question 1, the best method depends on the SolidWorks version you're using. It looks like an older version, so you could use SelectByRay after selecting the edge manually and setting the view to a known orientation (*Front or *Isometric for example). The name of the edge will probably not be constant, so you can't use SelectByID2 with the name of the edge. You could however use SelectByID2 using only coordinates and using "EDGE" as the type. For this one to work consistently, you need to set the orientation as well before calling it.