9 Replies Latest reply on Mar 5, 2018 4:07 PM by J. R.

    Problem with GetSelectionPoint2

    J. R.

      Hello,

       

      A part of macro I'm making has to select a point by it's ID (sketch point, geometry point, Center of Mass point, etc.) and output it's coordinates. I'm using GetSelectionPoint2 method, testing it out on a sketch point (for now), with the following code:

       

      Function GetCGdifferences()
          Dim SelPt As Variant
          
          boolstatus = swModel.Extension.SelectByID2("Point1@SET Center of Mass", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
          SelPt = swSelMgr.GetSelectionPoint2(1, -1)
          
          Debug.Print SelPt(0)
          Debug.Print SelPt(1)
          Debug.Print SelPt(2)
      End Function
      

       

      However, for whatever reason, this code doesn't work - it selects the point, but the output is 0, 0, 0. Now, most surprisingly, if I select the point manually, the GetSelectionPoint2 outputs the proper coordinates. In fact, if I replace the 4th line with:

       

      boolstatus = swModel.Extension.SelectByID2"Point1@SET Center of Mass", "EXTSKETCHPOINT", 0.370861965642898, -0.109938984318898, 2.58003532522887, False, 0, Nothing, 0)
      

       

      then the GetSelectionPoint2 also outputs the correct coordinates. The difference in that line is that the selection is overiden by selection coordinates (I got them by recording a macro).

       

      This is most puzzling for me, because I don't understand why the GetSelectionPoint2 is so picky about the way I select that point that I need to extract coordinates from. Can someone please point out my mistake? Why isn't the initial code working?

       

      Thank you in advance.

        • Re: Problem with GetSelectionPoint2
          Josh Brady

          GetSelectionPoint is not for getting coordinates of things.  It's for getting the place you clicked.  When you don't click, you don't selection point coordinates.  You need to get a pointer to the actual point that's selected (GetSelectedObject6) and then get the coordinates from that interface.

            • Re: Problem with GetSelectionPoint2
              J. R.

              Thank you very much. I was looking up some examples, and got so deep into it, that I forgot to consider what the name of this method actually meant. Can't believe I was stuck on this for hours. I solved this with the following code, in case anyone else will need it:

               

              Function GetCGdifferences() 
                  Dim SelPt As Variant 
                  boolstatus = swModel.Extension.SelectByID2("Point1@SET Center of Mass", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0) 
                  Set SelPt = swSelMgr.GetSelectedObject6(1, -1)
              
                  Debug.Print SelPt.X
                  Debug.Print SelPt.Y
                  Debug.Print SelPt.Z
              End Function 
              

               

               

              Thank you again for pointing out my rather basic mistake.

              • Re: Problem with GetSelectionPoint2
                J. R.

                By the way, if you don't mind me asking, it appears that the same method doesn't work with a Center of Mass Reference Point - setting SelPt with GetSelectedObject6 doesn't allow to use SelPt.X to extract X coordinate ("Object doesn't support this property or method"). But I'm not sure what methods are there to extract coordinates in this case, could you please advise? I can't seem to find any relevant examples in API documentation.

                  • Re: Problem with GetSelectionPoint2
                    Josh Brady

                    What do you mean by "center of mass point"?

                     

                    This thing?

                      • Re: Problem with GetSelectionPoint2
                        J. R.

                        No, this thing:

                         

                        1.jpg

                         

                        That one that is created by right-clicking on Center of Mass, and then clicking "Center of Mass Reference Point". It's renamed in my example. I'm trying to extract it's coordinates via GetSelectedObject6.

                          • Re: Problem with GetSelectionPoint2
                            Josh Brady

                            Interesting.  GetSelectedObjectType2 returns 243 for this feature, which is not listed in the API documentation.  I would recommend contacting API support (apisupport at solidworks dot com) and requesting documentation be updated.

                              • Re: Problem with GetSelectionPoint2
                                J. R.

                                I was thinking of a workaround. Creating a 3D sketch, making a point coincident with that Center of Mass Reference Point, and then referring to that point to get coordinates. Problem is, although I can make a 3D sketch point coincident with that CoM Reference Point manually (drawing a 3D sketch point and then dragging it with mouse to the CoM Reference Point), I can't make it happen through macro. The relation isn't added. Here's the code I'm trying:

                                 

                                boolstatus = swModel.Extension.SelectByID2("COV Ref Point", "CENTEROFMASSREFPOINT", 0, 0, 0, True, 0, Nothing, 0)
                                boolstatus = swModel.Extension.SelectByID2("Point1@SET Center of Mass", "SKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
                                swModel.SketchAddConstraints "sgCOINCIDENT"
                                

                                 

                                Do you know why this isn't working for me? Or maybe you know another way to extract the coordinates of that CoM Reference Point?

                      • Re: Problem with GetSelectionPoint2
                        Josh Brady

                        Nope... That's why I recommended contacting API support.  I can't find anything in the documentation referring to this feature.  I would say that you could read mass properties directly, but as I understand it the Center Of Mass Reference Point feature may be anywhere in the tree, such that you should be able to read its coordinates at any time relative to its position in the tree.  It should be a feature with a definition and/or properties etc. but they're not documented.