Drive Joint from Top Level Assembly

Drive Joint from Top Level Assembly

Anonymous
Not applicable
844 Views
6 Replies
Message 1 of 7

Drive Joint from Top Level Assembly

Anonymous
Not applicable

Hello

 

I need to drive a Rotational Joint 3 sub-assemblies down.

 

I am able to drive this joint independently within that sub-assembly with this code:

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oJoint As AssemblyJoint = oCompDef.Joints.Item("Rotational:2")
oJoint.DriveSettings.StartValue = 0
oJoint.DriveSettings.GoToStart
oJoint.DriveSettings.PlayForward
oJoint.DriveSettings.PlayReverse

 

However, I need to drive it from the Top Level Assembly.

I'm not sure how to target that Joint from here.

 

Looking forward to some solutions.

 

Thanks

 

 

Rotational.jpg

 

 

 

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

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

This is actually a tricky problem. What we have to do is create a proxy for the Joint, to have it represented in the top level assembly. In my example below, I take the occurrence path to the occurrence containing the joint, separated by "." and creates this proxy step by step through the occurrences all the way up to the last one. From there, we can use the AssemblyJointProxy object the same way we'd use an AssemblyJoint object 🙂

 

See iLogic below. I basically just took your rule and added a function to get the proxy.

Sub Main
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oJoint As AssemblyJointProxy = CreateJointProxy("@Copy of Extended Arm With Top (Custom).@Extended_Arm_RH:1", oDoc, "Rotational:2")
oJoint.DriveSettings.StartValue = 0
oJoint.DriveSettings.GoToStart
oJoint.DriveSettings.PlayForward
oJoint.DriveSettings.PlayReverse
oDoc.Update
End Sub
Function CreateJointProxy(pathString As String, oAsm As AssemblyDocument, JointName As String) As AssemblyJointProxy
	Dim occList As New List(Of ComponentOccurrence)
	Dim pathArray() As String = pathString.Split(".")
	For i = 0 To pathArray.Length - 1
		If i = 0 Then
			occList.Add(oAsm.ComponentDefinition.Occurrences.ItemByName(pathArray(i)))
		Else
			occList.Add(occList.Item(i - 1).Definition.Occurrences.ItemByName(pathArray(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.Joints.Item(JointName), oProx)
		Else
			Call occList(i).CreateGeometryProxy(oProx, oProx)
		End If
	Next
	Return oProx
End Function

 

Message 3 of 7

Anonymous
Not applicable

Thanks for your reply.

I have tried this.

 

It is giving this error:

System.ArgumentException: The Parameter Is incorrect. (Exception From HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.ComponentOccurrences.get_ItemByName(String Name)
at ThisRule.CreateJointProxy(String pathString, AssemblyDocument oAsm, String JointName)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

On debugging, I see that this error is given at this line:

occList.Add(oAsm.ComponentDefinition.Occurrences.ItemByName(pathArray(i)))

 

Please suggest what may be the reason.

0 Likes
Message 4 of 7

JhoelForshav
Mentor
Mentor

@Anonymous 

I think I figured it out... The "(Custom)" part of the name is the level of detail... That shouldn't be in there 🙂

Try this:

Sub Main
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oJoint As AssemblyJointProxy = CreateJointProxy("@Copy of Extended Arm With Top.@Extended_Arm_RH:1", oDoc, "Rotational:2")
oJoint.DriveSettings.StartValue = 0
oJoint.DriveSettings.GoToStart
oJoint.DriveSettings.PlayForward
oJoint.DriveSettings.PlayReverse
oDoc.Update
End Sub
Function CreateJointProxy(pathString As String, oAsm As AssemblyDocument, JointName As String) As AssemblyJointProxy
	Dim occList As New List(Of ComponentOccurrence)
	Dim pathArray() As String = pathString.Split(".")
	For i = 0 To pathArray.Length - 1
		If i = 0 Then
			occList.Add(oAsm.ComponentDefinition.Occurrences.ItemByName(pathArray(i)))
		Else
			occList.Add(occList.Item(i - 1).Definition.Occurrences.ItemByName(pathArray(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.Joints.Item(JointName), oProx)
		Else
			Call occList(i).CreateGeometryProxy(oProx, oProx)
		End If
	Next
	Return oProx
End Function
Message 5 of 7

Anonymous
Not applicable

Yes this is working perfectly.

Thankyou.

 

I have used this same code in another assembly (picture attached)

noveldecor_0-1599568749375.pngHere I am driving the hinges (in blue arrow)

The Left Door is constrained to the hinges via "Mate:116"

So I expect the door to also drive with the hinge.

 

On running the rule, only the hinge drives.

The door stays where it is. (The door is not Grounded)

 

If I make all the Hinges 'Flexible', and then pull on the door, it makes the door & hinge open/close perfectly.

So it means all constraints are ok.

Anything I am doing wrong here?

I want the hinge to drive along with the door.

0 Likes
Message 6 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

If the door is not in the Hinge-assembly I think the best solution would be to drive the joint in increments and update the assembly for each increment.

 

Edit the value for numberOfIncrements to control the speed of the drive 🙂

 

Sub Main
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oJoint As AssemblyJointProxy = CreateJointProxy("occ1.occ2.occ3", oDoc, "Rotational:1")
oJoint.DriveSettings.StartValue = 0
Dim numberOfIncrements As Integer = 30
oJoint.DriveSettings.SetIncrement(IncrementTypeEnum.kNumberOfStepsIncrement, numberOfIncrements )
oJoint.DriveSettings.GoToStart
For i = 1 To numberOfIncrements
oJoint.DriveSettings.StepForward
oDoc.Update
Next

For i = 1 To numberOfIncrements
oJoint.DriveSettings.StepReverse
oDoc.Update
Next

End Sub
Function CreateJointProxy(pathString As String, oAsm As AssemblyDocument, JointName As String) As AssemblyJointProxy
	Dim occList As New List(Of ComponentOccurrence)
	Dim pathArray() As String = pathString.Split(".")
	For i = 0 To pathArray.Length - 1
		If i = 0 Then
			occList.Add(oAsm.ComponentDefinition.Occurrences.ItemByName(pathArray(i)))
		Else
			occList.Add(occList.Item(i - 1).Definition.Occurrences.ItemByName(pathArray(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.Joints.Item(JointName), oProx)
		Else
			Call occList(i).CreateGeometryProxy(oProx, oProx)
		End If
	Next
	Return oProx
End Function

 

Message 7 of 7

Anonymous
Not applicable

@JhoelForshav worked perfectly

Thanks a ton 😁

0 Likes