Get all EdgeProxies of a given Edge

Get all EdgeProxies of a given Edge

Ralf_Krieg
Advisor Advisor
1,969 Views
4 Replies
Message 1 of 5

Get all EdgeProxies of a given Edge

Ralf_Krieg
Advisor
Advisor

Hello

 

I have an assembly containing subassemblies and parts. If i have an part edge, is there a way to get all edgeproxies representing this edge in context of the main assembly? I can circle through all edgeproxies in the assembly context and check if the native object is my edge, but this is very slow.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Accepted solutions (1)
1,970 Views
4 Replies
Replies (4)
Message 2 of 5

JhoelForshav
Mentor
Mentor

Hi @Ralf_Krieg 

Something like this maybe? 🙂

 

Sub Main
'Get a nativeobject for an edge, I dont know where you're getting the edge object from.
Dim oEdge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Pick edge.").NativeObject
Dim oPart As PartDocument = oEdge.Parent.ComponentDefinition.Document
Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oSelSet As SelectSet = oAsm.SelectSet

Dim oEdgeCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

For Each oOcc As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oPart)
	Dim oEdgeProx As EdgeProxy = CreateEdgeProxy(oOcc.OccurrencePath, oEdge)
	oEdgeCol.Add(oEdgeProx)
Next
oSelSet.SelectMultiple(oEdgeCol)
End Sub

Function CreateEdgeProxy(oOccList As ComponentOccurrencesEnumerator, oEdge As Edge) As Object
	Dim oProx As Object
	For i = oOccList.Count To 1 Step -1
		If i = oOccList.Count
			Call oOccList(i).CreateGeometryProxy(oEdge, oProx)
		Else
			Call oOccList(i).CreateGeometryProxy(oProx, oProx)
		End If

	Next
	Return oProx
End Function
Message 3 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

I just realized you don't have to send the proxy up through each occurrence of the occurrencepath.

This will do.

'Get a nativeobject for an edge.
Dim oEdge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Pick edge.").NativeObject
'Get the part document the edge belongs to.
Dim oPart As PartDocument = oEdge.Parent.ComponentDefinition.Document
'Get the top level assembly
Dim oAsm As AssemblyDocument = ThisDoc.Document
'Get the Assemblys select set.
Dim oSelSet As SelectSet = oAsm.SelectSet
'Create an ObjectCollection to add all edge proxies to.
Dim oEdgeCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

'Loop through all occurrences of the part.
For Each oOcc As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oPart)
	'Create a proxy for the edge
	Dim oEdgeProx As EdgeProxy
	oOcc.CreateGeometryProxy(oEdge, oEdgeProx)
	'Add proxy to the object collection
	oEdgeCol.Add(oEdgeProx)
Next
'Select everything in the object collection
oSelSet.SelectMultiple(oEdgeCol)

 

Message 4 of 5

Ralf_Krieg
Advisor
Advisor

Hello

 

Thank you. I have integrated your second code. Works perfect. 👍


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 5 of 5

sam
Advocate
Advocate
Thanks for this one - took me a while to figure out edgeproxy (:$)
0 Likes