<?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:


Leave a Reply