Share

Create rotational assembly joint

Description

This sample demonstrates creating an assembly joint. It connects the midpoints of the edges of two faces using a rotational joint. To do this it first creates a geometry intent object of the midpoint of the edge and then creates another intent using the face and the midpoint intent. It does this to create to midpoint intents which it then uses to create the rotational connection.

The sample uses and existing part that must be set up to allow it to work correctly. To create the sample part you can use any part that has a planar face and a linear edge connected to that planar face. A simple box is sufficient. In this part Add a mate iMate to the planar face and rename the iMate to "Face1". Also add a mate iMate to a linear edge that is on the face previously named and rename this iMate to "Edge1". Save the part to "C:\Temp\SamplePart.ipt" or any other name and edit the code below to reference the file. You can then run the sample code which will create a new assembly, insert two instances of the part and create a rotational connection between them. Then it will animation the rotation by driving the connection.

Code Samples

Public Sub AssemblyJointSample()
    ' Create a new assembly document.
    Dim asmDoc As AssemblyDocument
    Set asmDoc = ThisApplication.Documents.Add(kAssemblyDocumentObject, _
                  ThisApplication.FileManager.GetTemplateFile(kAssemblyDocumentObject))
    Dim asmDef As AssemblyComponentDefinition
    Set asmDef = asmDoc.ComponentDefinition
    
    ' Place an occurrence into the assembly.
    Dim occ1 As ComponentOccurrence
    Dim occ2 As ComponentOccurrence
    Dim trans As Matrix
    Set trans = ThisApplication.TransientGeometry.CreateMatrix
    Set occ1 = asmDef.Occurrences.Add("C:\Temp\SamplePart.ipt", trans)
    
    ' Place a second occurrence with the matrix adjusted so it fits correctly with the first occurrence.
    trans.Cell(1, 4) = 6 * 2.54
    Set occ2 = asmDef.Occurrences.Add("C:\Temp\SamplePart.ipt", trans)
    
    ' Get Face 1 from occ1 and create a FaceProxy.
    Dim faceOnOcc1 As Face
    Set faceOnOcc1 = GetNamedEntity(occ1, "Face1")
    
    ' Get Face 1 from occ2 and create a FaceProxy.
    Dim faceOnOcc2 As Face
    Set faceOnOcc2 = GetNamedEntity(occ2, "Face1")
    
    ' Get Edge 1 from occ2 and create an EdgeProxy.
    Dim edgeOnOcc2 As Edge
    Set edgeOnOcc2 = GetNamedEntity(occ2, "Edge1")
    
    ' Get Edge 3 from occ1 and create an EdgeProxy.
    Dim edgeOnOcc1 As Edge
    Set edgeOnOcc1 = GetNamedEntity(occ1, "Edge1")
    
    ' Create an intent to the center of Edge1.
    Dim edgeOcc2Intent As GeometryIntent
    Set edgeOcc2Intent = asmDef.CreateGeometryIntent(edgeOnOcc2, PointIntentEnum.kMidPointIntent)
    
    ' Create an intent to the center of Edge3.
    Dim edgeOcc1Intent As GeometryIntent
    Set edgeOcc1Intent = asmDef.CreateGeometryIntent(edgeOnOcc1, PointIntentEnum.kMidPointIntent)
    
    ' Create two intents to define the geometry for the joint.
    Dim intentOne As GeometryIntent
    Set intentOne = asmDef.CreateGeometryIntent(faceOnOcc2, edgeOcc2Intent)
    Dim intentTwo As GeometryIntent
    Set intentTwo = asmDef.CreateGeometryIntent(faceOnOcc1, edgeOcc1Intent)

    ' Create a rotational jont between the two parts.
    Dim jointDef As AssemblyJointDefinition
    Set jointDef = asmDef.Joints.CreateAssemblyJointDefinition(kRotationalJointType, _
                                                                           intentOne, intentTwo)
    jointDef.FlipAlignmentDirection = False
    jointDef.FlipOriginDirection = True
    Dim joint As AssemblyJoint
    Set joint = asmDef.Joints.Add(jointDef)

    ' Make the joint visible.
    joint.Visible = True
    
    ' Drive the joint to animate it.
    joint.DriveSettings.StartValue = "0 deg"
    joint.DriveSettings.EndValue = "180 deg"
    joint.DriveSettings.GoToStart
    joint.DriveSettings.PlayForward
    joint.DriveSettings.PlayReverse
End Sub


' This finds the entity associated with an iMate of a specified name.  This
' allows iMates to be used as a generic naming mechansim.
Private Function GetNamedEntity(Occurrence As ComponentOccurrence, Name As String) As Object
    ' Look for the iMate that has the specified name in the referenced file.
    Dim iMate As iMateDefinition
    Dim partDef As PartComponentDefinition
    Set partDef = Occurrence.Definition
    For Each iMate In partDef.iMateDefinitions
        ' Check to see if this iMate has the correct name.
        If UCase(iMate.Name) = UCase(Name) Then
            ' Get the geometry assocated with the iMate.
            Dim entity As Object
            Set entity = iMate.entity
            
            ' Create a proxy.
            Dim resultEntity As Object
            Set resultEntity = Nothing
            Call Occurrence.CreateGeometryProxy(entity, resultEntity)
            
            Exit For
        End If
    Next
    
    ' Return the found entity, or Nothing if a match wasn't found.
    Set GetNamedEntity = resultEntity
End Function


Was this information helpful?