VB Adding Mate constraint using plane in subassembly occurrence to occurrence

VB Adding Mate constraint using plane in subassembly occurrence to occurrence

aspecchio
Explorer Explorer
433 Views
1 Reply
Message 1 of 2

VB Adding Mate constraint using plane in subassembly occurrence to occurrence

aspecchio
Explorer
Explorer

I'm building an assembly through code and I'm able to add constraints when the planes are at the top level of the sub assembly but not when its as plane in an occurrence of that sub assembly.

Example: Trying to add mate constraint to "Part1Plane1" & "AsmPart1Plane1" from Main Assembly

Main Assembly

-Part1

--"Part1Plane1"

-Assembly1

--AsmPart1

---"AsmPart1Plane1"

0 Likes
Accepted solutions (1)
434 Views
1 Reply
Reply (1)
Message 2 of 2

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @aspecchio 

In order to use a plane that is not in a first level component you have to create a proxy for that plane and use that.

See code below. You can use the function provided to create a proxy for a plane how deep down you want by passing an agrument as a string of the "path" to the occurrence containing the plane, separated by "¤" and one argument for  the name of the plane.

If you're not writing in iLogic, you cant use "ThisDoc.Document" for the main assembly, so that has to be changed to ActiveDocument or whatever in that case...

In the code below it is PlaneProx you should use to create the constraint.

 

Sub Main
	Dim PlaneProx As WorkPlaneProxy = CreatePlaneProxy("Assembly1¤AsmPart1", "AsmPart1Plane1")
End Sub
Function CreatePlaneProxy(occString As String, oWPName As String) As Object
	Dim occList As New List(Of ComponentOccurrence)
	Dim occArr() As String = occString.Split("¤")
	For i = 0 To occArr.Length - 1
		If i = 0 Then
			occList.Add(ThisDoc.Document.ComponentDefinition.Occurrences.ItemByName(occArr(i)))
		Else
			occList.Add(occList.Item(i - 1).Definition.Occurrences.ItemByName(occArr(i)))
		End If
	Next
	Dim oProx As Object
	For i = occList.Count - 1 To 0 Step -1
		If i = occList.Count - 1
			Call occList(i).CreateGeometryProxy(occList(i).Definition.WorkPlanes.Item(oWPName), oProx)
		Else
			Call occList(i).CreateGeometryProxy(oProx, oProx)
		End If

	Next
	Return oProx
End Function

 Hope this helps!