asBuiltJoints.add seems to disrespect JointDirections.CustomJointDirection.

asBuiltJoints.add seems to disrespect JointDirections.CustomJointDirection.

osamuETYQY
Explorer Explorer
172 Views
1 Reply
Message 1 of 2

asBuiltJoints.add seems to disrespect JointDirections.CustomJointDirection.

osamuETYQY
Explorer
Explorer

Hi, everyone,

 

I would like to add an as-built revolute joint between a parent component and a child component along a specific axis with using `Component.asBuiltJoints.add` with `JointDirections.CustomJointDirection`.

 

 I wrote the following code and it runs without error but the revolute axis is always along the z-axis.

 

It is not pointing the wrong direction but just neglects the specified axis and points exactly the z-axis for some reason as the figure.

 

Screenshot_2025-03-09A.pngScreenshot_2025-03-09B.png

 

When I manually specify the Rotation axis as `Custom` and select the plane, it rotates around the preferred axis. (Somehow, the sketch edge is not selectable on GUI.)

 

Screenshot_2025-03-09C.gif

 

Can anyone point which part of my code is wrong or the way to work around the issue?

Thanks in advance!

 

 

"""Show `asBuiltJoints.add` disrespect `JointDirections.CustomJointDirection`."""
from math import pi
from typing import cast
import traceback
import adsk.core
import adsk.fusion


def run(_context: str):
    """Create a revolute as-built joint between the parent and the child components."""
    try:
        app = adsk.core.Application.get()
        design = adsk.fusion.Design.cast(app.activeProduct)

        # create the parent component under the root component

        parent = design.rootComponent.occurrences.addNewComponent(
            adsk.core.Matrix3D.create()
        )
        parent.component.name = "Parent"

        # create the child component under the parent component

        child = parent.component.occurrences.addNewComponent(
            adsk.core.Matrix3D.create()
        )
        child.component.name = "Child"
        child.isGroundToParent = False

        # create a polygonal prism

        sketch = child.component.sketches.add(child.component.xYConstructionPlane)
        sketch.sketchCurves.sketchLines.addScribedPolygon(
            adsk.core.Point3D.create(), 10, 0, 5, False
        )
        child.component.features.extrudeFeatures.addSimple(
            sketch.profiles[0],
            adsk.core.ValueInput.createByReal(1),
            cast(
                adsk.fusion.FeatureOperations,
                adsk.fusion.FeatureOperations.NewBodyFeatureOperation,
            ),
        )

        # draw the axis of the prism

        axis = sketch.sketchCurves.sketchLines.addByTwoPoints(
            adsk.core.Point3D.create(), adsk.core.Point3D.create(z=1)
        )
        axis.isConstruction = True

        # rotate the child and capture the position

        matrix = adsk.core.Matrix3D.create()
        matrix.setToRotation(
            pi / 3, adsk.core.Vector3D.create(x=1), adsk.core.Point3D.create()
        )
        design.rootComponent.transformOccurrences(
            [child.createForAssemblyContext(parent)], [matrix], False
        )
        design.snapshots.add()

        # create a revolute as-built joint around the axis

        geo = adsk.fusion.JointGeometry.createByPoint(
            axis.startSketchPoint.createForAssemblyContext(child)
        )
        inp = parent.component.asBuiltJoints.createInput(
            child.createForAssemblyContext(parent), parent, geo
        )
        inp.setAsRevoluteJointMotion(
            cast(
                adsk.fusion.JointDirections,
                adsk.fusion.JointDirections.CustomJointDirection,
            ),
            axis.createForAssemblyContext(child),
            # sketch.createForAssemblyContext(child).profiles[0] # this doesn't work as well
        )
        parent.component.asBuiltJoints.add(inp)

    except:  # pylint:disable=bare-except
        app.userInterface.messageBox(f"Failed:\n{traceback.format_exc()}")

 

 

 
 

 

 

0 Likes
173 Views
1 Reply
Reply (1)
Message 2 of 2

osamuETYQY
Explorer
Explorer

While struggling, I learned the "Z-axis direction" specified in `setAsRevoluteJointMotion` is not always based on the construction coordinate system of the specified component. Instead, the temporary coordinate system is determined based on the `JointGeometry` given to `asBuiltJoints.createInput`.

 

From the observation, I found a workaround. I generate JointGeometry from a sketch profile, which is made under the parent component, to arrange the temporary coordinate having its Z-axis to the preferred rotation axis direction, i.e. to have the sketch origin to locate at the joint position and the sketch normal parallel to the rotation axis.

 

Well, it is far from smart. By this way, I need to create a dedicated sketch just to specify the axis, which is not needed by using GUI.

 

0 Likes