Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am looking for ilogic that would ideally be ran from the assembly edit environment and allow me to choose a face (maybe in the active sketch?) and then delete and/or trim all lines or geometry found outside of that face. I am looking for a quick way to do scribed lines. I have ilogic code that already projects cut edges on to the face of the part I select (it runs in the assembly part edit environment) but I would like to take it a step further and trim down the excess lines. I feel like this is possible. Any ideas? Here is my ilogic code that runs in an assembly while editing a part for reference:
Dim oApp As Inventor.Application = ThisApplication
Dim oDoc As Inventor.Document = oApp.ActiveDocument
Dim oAssDoc As Inventor.AssemblyDocument = oApp.ActiveDocument
Dim oAssDocDef As Inventor.AssemblyComponentDefinition = oAssDoc.ComponentDefinition
' Prompt user to select a face
Dim oFaceProxy As FaceProxy = oApp.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a face")
' Check if a face was selected
If oFaceProxy Is Nothing Then
MessageBox.Show("No face was selected.")
Return
End If
' Create a new sketch on the selected face, in the context of the part
Dim oSketch As PlanarSketch = Nothing
Try
' Access the occurrence containing the face
Dim oOcc As ComponentOccurrence = oFaceProxy.ContainingOccurrence
' Access the part document's component definition
Dim oPartCompDef As PartComponentDefinition = oOcc.Definition
oSketch = oPartCompDef.Sketches.Add(oFaceProxy.NativeObject)
oSketch.Edit() ' This will start the sketch editing mode
Catch ex As Exception
MessageBox.Show("Failed to create a sketch. Error: " & ex.Message)
Return
End Try
' Check if there is an active sketch
If oSketch Is Nothing Then
MessageBox.Show("There is no active sketch.")
Return
End If
' Iterate through the occurrences in the assembly to find which parts are touching the selected face
Dim oOccurrenceList As New List(Of ComponentOccurrence)
For Each oOccurrence As ComponentOccurrence In oAssDocDef.Occurrences
Dim oOccCompDef As ComponentDefinition = oOccurrence.Definition
' Check if the occurrence is touching the selected face by checking for interference
If oApp.MeasureTools.GetMinimumDistance(oOccurrence, oFaceProxy) = 0 Then
' Add the occurrence to our list
oOccurrenceList.Add(oOccurrence)
End If
Next
' Start a transaction to project cut edges
Dim oTrans As Transaction = oApp.TransactionManager.StartTransaction(oDoc, "Project Cut Edges")
Try
' Attempt to project the touching parts' cut edges onto the sketch
Dim oControlDef As ControlDefinition = oApp.CommandManager.ControlDefinitions.Item("SketchProjectCutEdgesCmd")
' Clear current selection
oApp.ActiveDocument.SelectSet.Clear()
' Select the occurrences that are touching
For Each oOcc In oOccurrenceList
oApp.ActiveDocument.SelectSet.Select(oOcc)
Next
' Execute the command to project cut edges
oControlDef.Execute()
' Commit the transaction if we were successful
oTrans.End()
MessageBox.Show("Cut edges projected!")
Catch ex As Exception
' Abort the transaction if there was an error
oTrans.Abort()
MessageBox.Show("An error occurred while trying to project cut edges: " & ex.Message)
End Try
Solved! Go to Solution.