Get outer profile loop in sketch

<?xml encoding=”UTF-8″>By Adam Nagy

If you want to find the outermost profile loop in a sketch then you can just create a temporary Profile from all the sketch entities and then check the first ProfilePath in it. That should be the outer loop. If there are multiple outer loops then you would need to check the other ProfilePath‘s too with AddsMaterial = True. Also if two paths are intersecting then you cannot be sure which one of those you’ll get back – see below pics.

Here is a VBA code that shows how to do it:

Sub HighlightOuterSketchLoop()
' You need to be inside the sketch
Dim sk As PlanarSketch
Set sk = ThisApplication.ActiveEditObject
Dim doc As Document
Set doc = ThisApplication.ActiveDocument
Dim tm As TransactionManager
Set tm = ThisApplication.TransactionManager
' Create a transaction that we'll abort
Dim tr As Transaction
Set tr = tm.StartTransaction(doc, "Temp")
' You should not leave a transaction
' hanging in the air. It will make Inventor
' unstable. So in case of error we'll
' skip to aborting the whole thing
On Error GoTo Oops
Dim tro As TransientObjects
Set tro = ThisApplication.TransientObjects
Dim p As Profile
Set p = sk.Profiles.AddForSolid()
Dim coll As ObjectCollection
Set coll = tro.CreateObjectCollection
' If there is a single outermost loop
' then that should be the first one
Dim pp As ProfilePath
Set pp = p(1)
Dim pe As ProfileEntity
For Each pe In pp
Call coll.Add(pe.SketchEntity)
Next
Oops:
Call tr.Abort
If Err <> 0 Then Exit Sub
' Let's select the lines in the UI
Call doc.SelectSet.SelectMultiple(coll)
End Sub

Here are pics showing the results:

Sketchprofile

 


Comments

One response to “Get outer profile loop in sketch”

  1. Vishal Gonsalves Avatar
    Vishal Gonsalves

    Hi
    I love your website. It’s full of useful information for beginners like me. Thanks
    Now to why I am writing to you guys. I found this interesting bit of code at https://forums.autodesk.com/t5/inventor-forum/fast-selection-of-closed-profiles-in-sketch/m-p/7215732#M650263 and was wondering if its possible to create surfaces rather than a solid.
    I have a sketch that contains open and closed shapes which may or may not be inside a block. Given that the extrude command ends after every selection the process of generating the surfaces gets tiresome. So I was wondering if anyone of you guys can figure out some code to achieve the surfaces in one go.
    Hope you can find the time to look at this request.
    Thank you

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading