Thursday, December 14, 2017

iLogic to Select all of the Closed Profiles Found in a Sketch

iLogic to Select all of the Closed Profiles Found in a Sketch


Issue:
You find yourself needing to select a large number of closed profiles in a sketch of a logo or something similar. This is quite tedious and because you reuse the sketch over and over, you find yourself wishing you had a better way to do this.

Here is an example of a logo that was copied from AutoCAD and placed in an Inventor sketch block. Its a bit tedious to select all of these profiles each time the logo is used on a laser engraved part.




Solution:
You can use the following iLogic rule to select all of the closed profiles found in the sketch, and create an Extrude feature from them.




----start of ilogic -------
If Typeof ThisApplication.ActiveEditObject Is Sketch Then
Do nothing
Else
MessageBox.Show("Activate a Sketch First then Run this Rule", "ilogic")
Return
End If

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

Dim oSketch As PlanarSketch
oSketch = ThisApplication.ActiveEditObject

Create a profile.
Dim oProfile As Profile
On Error Goto NoProfile
oProfile = oSketch.Profiles.AddForSolid

get user input
oDistance = InputBox("Enter Extrude Distance", "iLogic", "10 mm")
oDirection  = InputRadioBox("Select Extrude Direction", "Up (+)", "Down (-)", True, Title := "iLogic")
oJoinOrCut  = InputRadioBox("Select Extrude Solution", "Join", "Cut", True, Title := "iLogic")

If oDirection = True then
oDirection = kPositiveExtentDirection
Else
oDirection = kNegativeExtentDirection
End if

If oJoinOrCut = True then
oJoinOrCut = kJoinOperation
Else
oJoinOrCut = kCutOperation
End if

Create an extrusion
Dim oExtrude As ExtrudeFeature
On Error Goto NoExtrude
oExtrude = oCompDef.Features.ExtrudeFeatures.AddByDistanceExtent( _
oProfile, oDistance, oDirection, oJoinOrCut)

ThisApplication.CommandManager.ControlDefinitions.Item("FinishSketch").Execute

iLogicVb.UpdateWhenDone = True

exit sub

NoProfile: