2 Replies Latest reply on Dec 17, 2015 11:42 AM by Charles Clark

    Macro to traverse imported model's faces for closed loops

    Charles Clark

      Going through an old library of parts where I want to verify the dimensions (and/or existence) of some features.

       

      These are STEP and IGS files, so everything is just an "imported" body.

       

      What I'm looking for are small rectangular and cross shaped "notches" of varying depth and dimensions on multiple faces. (basically Philips and regular head screwdriver marks)

       

      Of course, I don't expect someone to write this for me (though I won't turn it down either!), but some thoughts or guidance on the best approach and API extensions to use for the various steps would be appreciated!

       

      How I'm envisioning this working:

       

      1) Create and process a new SW part(s) from specified file (or folder)

       

      2) Open each file and do the following:

       

      3) Identify and traverse all faces to identify closed loops on them (<- This is my biggest challenge.)

       

      4) If an identified closed loop's edge lengths are all within a specified range (or just less than something), append the following values to a text file (or return them somehow):

       

        - specific part and face containing the closed loop (and possibly the loop's location on face)

        - Total number of edges in the closed loop

        - list of all closed loop edge lengths

       

      5) (bonus) automatic annotation identifying all the part's criteria-matched closed loops

       

      ----

       

      Using SW 2016

       

      Thanks!

      Charlie

        • Re: Macro to traverse imported model's faces for closed loops
          Amen Allah Jlili

          If you have an extruded-cut-through-all hole, that will account for the same loop of edges twice, right? Perhaps you can filter out the duplicates with a measure of the area loop or something similar?


          But I seem to have a problem when you said "all faces", or do you mean the outer boxing faces of your part?

           

          Anyhow, I think this can help with the challenging part:

           

          You can use .GetFaces2 to get the faces of the part bodies (object Body2).
          After that, you get the loops of on the faces GetLoops and use Loop2.IsOuter to filter out the outermost loop since that is the surface edges.

           

          or you can do like this:

           

           

           

          Set swLoop = swFace.GetFirstLoop
              Do While Not swLoop Is Nothing
                  i = i + 1
                  
                  If Not swLoop.IsOuter Then
                    ' Do Stuff here
                  End If
                  
                  Set swLoop = swLoop.GetNext
              Loop
          

           

          Hope this helps!

            • Re: Macro to traverse imported model's faces for closed loops
              Charles Clark

              Thanks Amen! 

               

              This is tremendously helpful.

               

              Regarding your questions, (I believe that) I do mean the outer boxing faces.  All the exposed faces basically.  (If it was an open ended cylinder for example, this would include the inside faces.)

               

              None of these would be a "through-all" cut, so I don't expect duplicates.  (But I will make sure to look for all the desired edge length constraints and such within the "do stuff here")

               

              Thanks again!