6 Replies Latest reply on Oct 8, 2012 6:33 PM by Artem Taturevych

    How to select vertex(es) on drawing?

    Laszlo Szucs

      Hi, I am working on a macro which should select vertex(es) on drawing(s).

      I know the X, Y  coordinates  (and Z but it is always 0) of the vertex(es) but I

      don't know how to select them. Does anybody have any idea how to do it? Many thanks!

        • Re: How to select vertex(es) on drawing?
          Keith Rice

          Laszlo,

           

          Welcome to the forums.

           

          Is the vertex in a drawing view? If it isn't then it is probably easiest to select with IModelDocExtension::SelectByID2. Otherwise it is probably easiest to traverse all sketch points in the drawing view and then use ISketchPoint::Select4. For the latter, you can modify the example I have at my Macro Library called "Get the coordinates of all sketch points in a drawing view".

           

          I can post an example if you tell me more details about where the vertex is located.

           

          Keith

          Video Tutorials for the SolidWorks API

          • Re: How to select vertex(es) on drawing?
            Artem Taturevych

            If you are talking about the vertex (i.e. IVertex interface) you should call the View::SelectEntity method. Please follow the examples for this method in API Help Documentation. I would strongly recommend you to traverse the entities as Keith suggested and pass the pointer to this SelectEntity method.

            ______________________

            Regards,

            Artem Taturevych

            Application Engineer at Intercad

            http://intercad.com.au/

            Tel: +61 2 9454 4444

            • Re: How to select vertex(es) on drawing?
              Laszlo Szucs

              Hi guys, Thank you for the quick response but I think I need something else. I will try to explain what the situation is. The problem started when I wanted to add notes to different vertices on a drawing. (Let's say that there is a simple cube and there is a drawing about it with two perspective views from different view angles.) First of all I select a few vertices on the different views and I would like to name them as "P1", "P2" and so on (I can solve it with adding annotations, no problem) . After this I would like to make a table with the correct X,Y,Z model coordinates of the cube.  If there is only one vertex selected I don't have any problems, my programme can handle both drawing and model coordinates but if there are more selected vertices on the drawing then the macro can't determine the model coordinates anymore. I use the following code for this:

               

              Set Measure = swDoc.Extension.CreateMeasure

              boolstatus = Measure.Calculate(Nothing)

                                  Xc = Measure.X

                Yc = Measure.Y

                                  Zc = Measure.Z

               

              It is logical that more selected points can't have X,Y,Z coordinates so I filled up an array with the drawing coordinates (that I get with the "PickPoint = swDoc.GetInsertionPoint" after I selected them one by one with the "mySelMgr.GetSelectedObject6" method) because I thought that I can select the vertices one by one using the   "boolstatus = swDoc.Extension.SelectByID2("", "swSelVERTICES", PickPoint(0), PickPoint(1), PickPoint(2), False, 0, Nothing, 0)" and get the model coordinates with the above mentioned method but it doesn't work. This is the point where I would need some help. Maybe there is a much easier solution for this and I just made my life difficult so please help to make it easier if you can  :-) Thanks in advance for that!

                • Re: How to select vertex(es) on drawing?
                  Artem Taturevych

                  Ok, so the preconditions of your macro is that the vertices selected? If so, just get the pointers to all the vertices via ISelectionManager::GetSelectedObject6 this will return you the pointer to IVertex (note that the first selected object will be the view). Next use the Vertex::GetPoint which returns you the array of doubles which corresponds to coordinate of the vertex in model view.

                  ______________________

                  Regards,

                  Artem Taturevych

                  Application Engineer at Intercad

                  http://intercad.com.au/

                  Tel: +61 2 9454 4444

                    • Re: How to select vertex(es) on drawing?
                      Laszlo Szucs

                      Hi Artem, thanks for your answer it works fine but I noticed something strange. I wanted to know how the macro works when a sketch point is also selected so I added it to a vertex of the cube (I did it on the drawing). After this I selected a few vertices like before. The "GetSelectedObjectCount2" gives me the correct number of the selected objects but when I check them one by one with the "GetSelectedObjectType3" it gives "0" for all the selected item. Do you have an idea how to handle it? Anyway thanks again for your help!