Highlighting patterned and source edges of a feature pattern

Highlighting patterned and source edges of a feature pattern

pmartick
Advocate Advocate
153 Views
0 Replies
Message 1 of 1

Highlighting patterned and source edges of a feature pattern

pmartick
Advocate
Advocate

Inventor 2023 (Soon to be 2025 if there's new API that could potentially help)

 

As part of a larger tool I'm creating I need code that highlights the occurrence edges of a feature pattern and the source edge of the feature pattern when the user hovers their mouse over a circular edge.

 

So far I have figured out a method to highlight all matching edges of a feature pattern when the user hovers their mouse over an occurrence edge.  The initial highlight of all matching occurrence edges seems to work well but the process of un-highlighting the edges when the user moves their mouse off of the occurrence edge does introduce some significant lag.  You can see the attached video to witness the performance of my code so far.

 

As far as I can see in the API there's also no direct link between the source and occurrence edges of a feature pattern.  The first element of the feature pattern does not contain any geometry so I cannot simply use the same code as every other element.  This also means when the user highlights the source edge of a feature pattern there's no direct link to find and highlight all of the matching occurrence edges of the feature pattern.

 

If anyone has any ideas on how to identify the source edge of a feature pattern, identify all occurrence edges of a source edge, and how to improve the code to maximize performance please let me know.  Thanks ahead of time.

 

Here's the code I have so far:

Run this rule on a part file that has a rectangular pattern of holes.

Run the rule and a small minitoolbar will appear with a cancel button.  Click this button or press Esc to exit the rule.  Once the rule is started you can hover your mouse over the pattern of holes.

Sub Main
	oApp = ThisApplication : With oApp : oCurDoc = .ActiveDocument : cFeats = oCurDoc.ComponentDefinition.Features : oComMgr = .CommandManager : oView = .ActiveView : End With
	With oComMgr
		evInteract = .CreateInteractionEvents : evToolbar = .CreateMiniToolbar
	End With
	With evToolbar
		.Position = oApp.TransientGeometry.CreatePoint2d(oView.Left - 200, oView.Top - 50)
		.ShowOptionBox = False: .ShowOK = False: .ShowApply = False
		.Controls.AddLabel("sMainLbl", "", "")
		.Visible = True
	End With
	cPreHighlight = oCurDoc.CreateHighlightSet
	cPreHighlight.Color = oApp.ActiveColorScheme.HighlightColor
	With evInteract : evSelect = .SelectEvents : .Start : End With
	evSelect.AddSelectionFilter(SelectionFilterEnum.kAllCircularEntities)
	Do : oApp.UserInterfaceManager.DoEvents : Loop Until bCancel
	evToolbar.Delete
	With evSelect : .ResetSelections : .ClearSelectionFilter : .ClearWindowSelectionFilter : End With
	cPreHighlight.Delete
	evInteract.Stop
	oComMgr.StopActiveCommand
End Sub
Dim bCancel As Boolean
Dim oCurDoc As PartDocument
Dim cFeats As PartFeatures
Dim cPreHighlight As HighlightSet
Dim WithEvents evToolbar As MiniToolbar
Dim WithEvents evInteract As InteractionEvents
Dim WithEvents evSelect As SelectEvents
Sub subCancel Handles evToolbar.OnCancel, evInteract.OnTerminate
	bCancel = True
End Sub
Sub evSelect_OnPreSelect(ByRef PreSelectEntity As Object, ByRef DoHighlight As Boolean, ByRef MorePreSelectEntities As ObjectCollection, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As Inventor.View) Handles evSelect.OnPreselect
	bHighlight = False
	If TypeOf PreSelectEntity Is Edge
		bHighlight = True
		For Each oFeat As PartFeature In cFeats
			For Each oFace As Face In oFeat.Faces
				For Each oEdge As Edge In oFace.Edges
					If TypeOf oFeat Is RectangularPatternFeature
						For Each oElem As FeaturePatternElement In oFeat.PatternElements
							With oElem.Faces
								For iFace = 1 To .Count
									With .Item(iFace).Edges
										For iEdge = 1 To .Count
											If .Item(iEdge) Is PreSelectEntity
												With oFeat.PatternElements
													For i = 2 To .Count
														With .Item(i)
															If Not .Suppressed Then cPreHighlight.AddItem(.Faces(iFace).Edges(iEdge))
														End With
													Next
												End With
												For Each oObject In oFeat.Definition.ParentFeatures
													Try
														For Each oSourceFace As Face In oObject.Faces
															For Each oSourceEdge As Edge In oSourceFace.Edges
																'if oSourceEdge Matches PreSelectEntity Then cPreHighlight.AddItem(oSourceEdge)
															Next
														Next
													Catch
													End Try
												Next
												GoTo jLoopEnd
											End If
										Next
									End With
								Next
							End With
						Next
						jLoopEnd :
					ElseIf TypeOf oFeat Is HoleFeature
						For Each oPatt As RectangularPatternFeature In cFeats.RectangularPatternFeatures
							For Each oObject In oPatt.Definition.ParentFeatures
								If oObject Is oFeat
									With oPatt.PatternElements
										For i = 2 To .Count
											With .Item(i)
												If Not .Suppressed
													For Each oPattFace As Face In .Faces
														For Each oPattEdge As Edge In oPattFace.Edges
															'If oPattEdge Matches PreSelectEntity Then cPreHighlight.AddItem(oPattEdge)
														Next
													Next
												End If
											End With
										Next
									End With
								End If
							Next
						Next
					End If
				Next
			Next
		Next
	End If
	DoHighlight = bHighlight
End Sub
Sub evSelect_OnStopPreSelect(ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As Inventor.View) Handles evSelect.OnStopPreSelect
	cPreHighlight.Clear
End Sub
0 Likes
154 Views
0 Replies
Replies (0)