Please help with ilogic window selection method and loop

Please help with ilogic window selection method and loop

xenocatalyst
Advocate Advocate
674 Views
6 Replies
Message 1 of 7

Please help with ilogic window selection method and loop

xenocatalyst
Advocate
Advocate

Hi,

 

I have developed a rule to place centerlines on slotted holes on the drawing sheet.

It works by selecting the curves of a single slot, (so i window over the slot and get 2 arcs and 2 lines)

then run the rule. The rule then adds a bisector between the pair of arcs and and another between the pair of lines.

 

This works well, but I would like improve the process by adding a loop where i can continuously window select slot curves and it will add the bisector in between selection events.

 

Could someone please help with the loop and the window selection code?

 

I am using INV Pro 2024

 

here is my code :

 

Dim oDoc As DrawingDocument = ThisDrawing.Document
Dim osheet As Sheet = oDoc.ActiveSheet
Dim oSSet As SelectSet = oDoc.SelectSet

Dim oArcsCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection 
Dim oLineCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection 


If oSSet.Count = 0 Then
    MessageBox.Show("You no pick stuff first", "Crap", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
		For Each obj As DrawingCurveSegment In oSSet
			If obj.GeometryType = 5253 Then
				oArcsCol.Add(osheet.CreateGeometryIntent(obj.Parent))
			Else
				oLineCol.Add(osheet.CreateGeometryIntent(obj.Parent))			
	        End If
	    Next
End If

osheet.Centerlines.AddBisector(oArcsCol.Item(1),oArcsCol.Item(2))
osheet.Centerlines.AddBisector(oLineCol.Item(1),oLineCol.Item(2))

 

 

0 Likes
Accepted solutions (2)
675 Views
6 Replies
Replies (6)
Message 2 of 7

A.Acheson
Mentor
Mentor

Here is a starting point with VBA API Sample. I suggest you run it in VBA first and select the geometry that it is identifying. Once you have it running then you can convert to VB.NET to run in the iLogic environment. If you have any trouble converting post up the error messages from the more info page. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 7

xenocatalyst
Advocate
Advocate

Hi Alan, thanks for your reply.

 

I  have already tried this and unfortunately I am out of my depth.

I just cant understand how to use subs and functions properly. 

This is when i decided to ask for help.

But I'll keep trying.

0 Likes
Message 4 of 7

yuzeaa
Advocate
Advocate
Accepted solution

GIF 2023-11-30 22-59-33.gif

Class ThisRule
	Sub main
       Dim oSelect As New Selectwindow(ThisApplication)
	   oSelect.WindowSelect
	End Sub
End Class

Class Selectwindow
	Private WithEvents oInteractEvents As InteractionEvents
	Private WithEvents oSelectEvents As SelectEvents
	Private ThisApplication As Inventor.Application

	Sub New(ThisApplication As Inventor.Application)
		Me.ThisApplication = ThisApplication
	End Sub

	Sub WindowSelect()
		oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents
		oInteractEvents.InteractionDisabled = False
		oSelectEvents = oInteractEvents.SelectEvents
		oSelectEvents.WindowSelectEnabled = True
		oInteractEvents.StatusBarText = "Window select. Esc to exit."
        oInteractEvents.Start
	End Sub
	
	Private Sub oInteractEvents_OnTerminate() Handles oInteractEvents.OnTerminate
		oSelectEvents = Nothing
		oInteractEvents = Nothing
    End Sub
	
	Private Sub oSelectEvents_OnSelect(JustSelectedEntities As ObjectsEnumerator, 
									   SelectionDevice As SelectionDeviceEnum, 
									   ModelPosition As Point, 
									   ViewPosition As Point2d, 
									   View As View) Handles oSelectEvents.OnSelect
		 If JustSelectedEntities.Count Mod 4 <> 0  OrElse  JustSelectedEntities.Count = 0 Then Return
		 SlotCenterLine(GroupLine(JustSelectedEntities.OfType(Of DrawingCurveSegment).ToList()))
	End Sub
  
	Function GroupLine(oSSet As List(Of DrawingCurveSegment)) As List(Of List(Of DrawingCurveSegment))
		Dim oList As New List(Of List(Of DrawingCurveSegment))
		For Each oCurve In oSSet 
			If oList.Any(Function(item) item.Contains(oCurve)) Then Continue For
			Dim Templist As New List(Of DrawingCurveSegment)
			Templist.Add(oCurve)
			Dim oEdge As Edge = oCurve.Parent.ModelGeometry
			For Each item In  oSSet
				Dim iEdge As Edge = item .Parent.ModelGeometry
				If oEdge.TangentiallyConnectedEdges.OfType(Of Edge).Any(Function(e) e.TransientKey = iEdge.TransientKey) Then
					If Not Templist.Contains(item) Then Templist.Add(item)
				End If
			Next
			oList.Add(Templist)
		Next
		Return oList
	End Function

	Private Sub SlotCenterLine(oSSet As List(Of List(Of DrawingCurveSegment)))
		Dim osheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet
		For Each LineGroup In oSSet
			Dim oArcsCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
		    Dim oLineCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
			For Each obj As DrawingCurveSegment In LineGroup
				If obj.GeometryType = 5253 Then
					oArcsCol.Add(osheet.CreateGeometryIntent(obj.Parent))
				Else
					oLineCol.Add(osheet.CreateGeometryIntent(obj.Parent))			
			    End If
		    Next
			osheet.Centerlines.AddBisector(oArcsCol.Item(1),oArcsCol.Item(2))
	        osheet.Centerlines.AddBisector(oLineCol.Item(1),oLineCol.Item(2))
	    Next
	End Sub
End Class
Message 5 of 7

xenocatalyst
Advocate
Advocate

Wow yuzeaa163_com that is fantastic.

 

Your code goes beyond what I asked for and makes it more usable.

 

Thankyou.

 

I like the part where you were able to check if the curves were part of the same edge.

I didn't realize that Edge's where a thing.

Looking through the API object model, I see they are part of the B-Rep group.

 

0 Likes
Message 6 of 7

HogueOne
Advocate
Advocate

Would you be willing to show me some syntax for how window selection could work to select occurrences in the assembly environment?

0 Likes
Message 7 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@HogueOne, I had this example to window select assembly components on hand ( I likely got a variation of it from this forum... thanks to whoever provided it).

 

Sub Main

	'create the selectionclass
	Dim oSelection As New clsSelect
	'call the window select sub in the class
	oSelection.WindowSelect(ThisApplication)

	'exit sub if getting the count creates an error ( user escaped with nothing selected)
	Try : iCount = oSelection.SelectedObjects.Count : Catch : Exit Sub : End Try

	MsgBox(iCount & " component(s) selected.", , "iLogic")

	'do something with the selected components
	For Each oOcc As ComponentOccurrence In oSelection.SelectedObjects
		If Component.Color(oOcc.Name) = "Red" Then
			Component.Color(oOcc.Name) = "Green"
		Else
			Component.Color(oOcc.Name) = "Red"
		End If
	Next

End Sub


Class clsSelect
	Private WithEvents oInteractEvents As InteractionEvents
	Private WithEvents oSelectEvents As SelectEvents
	Private bTooltipEnabled As Boolean
	Private ThisApplication As Inventor.Application
	Public SelectedObjects As ObjectsEnumerator
	Private stillSelecting As Boolean = True

	Public Sub WindowSelect(oApp As Inventor.Application)
		ThisApplication = oApp
		oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents
		oInteractEvents.InteractionDisabled = False
		oSelectEvents = oInteractEvents.SelectEvents

		'filters for only parts/ leaf occurrences
		oSelectEvents.AddSelectionFilter(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter)
		oSelectEvents.WindowSelectEnabled = True
		bTooltipEnabled = ThisApplication.GeneralOptions.ShowCommandPromptTooltips
		ThisApplication.GeneralOptions.ShowCommandPromptTooltips = True

		oInteractEvents.StatusBarText = "Select components. CTRL to deselect, ESC to finish."
		oInteractEvents.Start()
		While stillSelecting
			ThisApplication.UserInterfaceManager.DoEvents()
		End While
	End Sub

	Private Sub oInteractEvents_OnTerminate() Handles oInteractEvents.OnTerminate
		ThisApplication.GeneralOptions.ShowCommandPromptTooltips = bTooltipEnabled
		oSelectEvents = Nothing
		oInteractEvents = Nothing
		stillSelecting = False
	End Sub

	Private Sub oSelectEvents_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator,
		ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point,
		ByVal ViewPosition As Point2d, ByVal View As View) Handles oSelectEvents.OnSelect

		SelectedObjects = oSelectEvents.SelectedEntities
	End Sub

	Private Sub oSelectEvents_OnUnSelect(UnSelectedEntities As ObjectsEnumerator,
		SelectionDevice As SelectionDeviceEnum, ModelPosition As Point,
		ViewPosition As Point2d, View As View) Handles oSelectEvents.OnUnSelect

		SelectedObjects = oSelectEvents.SelectedEntities
	End Sub
End Class

 

EESignature