3 Replies Latest reply on Sep 28, 2017 1:45 PM by Jacob Corder

    questions about getsketchregions and outloop

    Moon Wang

      hello,

       

      I get the sketch by 3DIntersections.when I used  getsketchregions ,it shows that the SketchRegionCount is 2,I doubt how it allocate regions(I thought the regioncount is 1),however when I get the firstloop and get the loop‘s edgecout ,the edgecount is 1,and OuterLoop isTRUE.So,the squence of loop is also a puzzle to me .who can help me,thank you

      my code is as below.

      .......

      swSketch = (ISketch)swFeature.GetSpecificFeature2();

      .......

      if ((swSketch != null))

                          {

                              regionCount = swSketch.GetSketchRegionCount();

                              vSkRegions = (object[])swSketch.GetSketchRegions();

                              for (i = vSkRegions.GetLowerBound(0); i <= vSkRegions.GetUpperBound(0); i++)

                              {

                                  skRegion = (SketchRegion)vSkRegions[i];

       

                                  if ((skRegion != null))

                                  {

                                      j = 0;

                                      myLoop = skRegion.GetFirstLoop();

                                      while ((myLoop != null))

                                      {

                                          edgeCount = myLoop.GetEdgeCount();

                                          vertexCount = myLoop.GetVertexCount();

                                          outer = myLoop.IsOuter();

                                          if (outer == false)

                                          {

                                              strOuter = "Inner loop";

                                          }

                                          else

                                          {

                                              strOuter = "Outer loop";

                                          }

                                          vEdges = (object[])myLoop.GetEdges();

                                          for (k = vEdges.GetLowerBound(0); k <= vEdges.GetUpperBound(0); k++)

                                          {

                                              myEdge = (Edge)vEdges[k];

                                              if ((myEdge != null))

                                              {

                                                  test1 = (Vertex)myEdge.GetStartVertex();

                                                  test2 = (Vertex)myEdge.GetEndVertex();

                                                  //vPoint = (double[])test1.GetPoint();

                                               }

                                          }

                                          vVertices = (object[])myLoop.GetVertices();

                                          for (k = vVertices.GetLowerBound(0); k <= vVertices.GetUpperBound(0); k++)

                                          {

                                              myVertex = (Vertex)vVertices[k];

                                              if ((myVertex != null))

                                              {

                                                  vPoint = myVertex.GetPoint();

                                                  X = vPoint[0];

                                                  Y = vPoint[1];

                                                  Z = vPoint[2];

                                        

                                              }

                                          }

                                          myLoop = (Loop2)myLoop.GetNext();

                                          j = j + 1;

                                      }

        • Re: questions about getsketchregions and outloop
          Manikandan Babu

          Hi Wang,

           

          Lets try this code to get the edges.

           

          I hope its helps you

           

          class Program

              {

                  static void Main(string[] args)

                  {

                     SldWorks Swapp=(SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application.25");

                    

                      ModelDoc2 SwModel = Swapp.ActiveDoc;

           

                      PartDoc SwPart = (PartDoc)SwModel;

           

                      Feature SwFeat = SwPart.FeatureByName("Sketch1");

           

                      Sketch SwSketch = SwFeat.GetSpecificFeature2();

           

                      Debug.Print(SwSketch.GetSketchContourCount().ToString());

           

                      object[] vSkContours = (object[]) SwSketch.GetSketchContours();

           

                      foreach (SketchContour SwSketcontour in vSkContours)

                      {

                          object[] VEdges = (object[])SwSketcontour.GetEdges();

           

                          Debug.Print(SwSketcontour.GetEdgesCount().ToString());

           

                          foreach (Edge SwEdge in VEdges)

                          {

                             

                              Entity SwEnt = (Entity)SwEdge;

                        

                          }

                      }

                  }

           

          Manikandan