Message 1 of 2
asBuiltJoints.add seems to disrespect JointDirections.CustomJointDirection.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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.)
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()}")