7 Replies Latest reply on Apr 20, 2016 10:29 AM by Orcun Cakmak

    Selecting Edge in a Section View Drawing

    Di Anne

      Hello  SW community,


      I'm working on a macro to add dimensions in a drawing.

      But since it is  a section view I need to select 2 edges and create a dimension from the visible edges using the edge property name.

      But i just can't get my macro to select the edges.


      Does anybody here has an idea?


      Kind regards,


        • Re: Selecting Edge in a Section View Drawing
          Keith Rice

          In the future, please post what solution(s) you have already attempted.


          You should be able to use IView::SelectEntity to accomplish this.



          SolidWorks API Training

          • Re: Selecting Edge in a Section View Drawing
            Raghvendra Bhargava

            Hi Di,


            AS you have mentioned you are dealing with section view so i am assuming your edges are not contraint to select.

            Better you can use API 'GetVisibleEntities', it will return you all edges.


            Please let me know if you need any other help

            • Re: Selecting Edge in a Section View Drawing
              Di Anne

              Hi Keith Rice, Raghvendra Bhargava



              Ive been using this code and I'm using c#



                      public static Entity SelectEdgeDrawing(ModelDoc2 modelDoc, SolidWorks.Interop.sldworks.View swView, string edgename, string title)
                          string curFace = "";
                          Entity swEntity = default(Entity);
                          object[] vEdges;

                          modelDoc = (ModelDoc2)SldwCommonUtil.SwApp.ActivateDoc(title);

                          SelectionMgr swSelmgr = modelDoc.SelectionManager;        
                          swView = swSelmgr.GetSelectedObject6(1, 0);


                          object[] vComps = swView.GetVisibleComponents();

                          for (int i = 0; i < vComps.Count(); i++)

                              vEdges = swView.GetVisibleEntities((Component2)vComps[i],(int)swViewEntityType_e.swViewEntityType_Edge);

                              for (int j = 0; j < vEdges.Count(); j++)
                                  curFace = modelDoc.GetEntityName(vEdges[i]);

                                  if (curFace == edgename)
                                      swEntity = (Entity)vEdges[i];

                          return swEntity;







              But since the Drawing below is a pipe..

              I cannot name its edge, that's why I cant use GetEntityName





              And even though I will be able to get the visible edges how can i determine that this are the edges I needed ?



              Thank you very much.

              • Re: Selecting Edge in a Section View Drawing
                Orcun Cakmak

                your code helped me, but you need to correct it, you are using "i" in your nested loop, which should be "j".


                try changing them to :


                    curFace = modelDoc.GetEntityName(vEdges[j]);

                                    if (curFace == edgename)
                                        swEntity = (Entity)vEdges[j];