Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to create a revolute joint using custom joint axis, but I got an error:
RuntimeError: 2 : InternalValidationError : Utils::getObjectPath(object, objPath, nullptr, context)
And I searched at this forum, here are the relative posts:
https://forums.autodesk.com/t5/fusion-360-api-and-scripts/copy-body-and-move-by-code/m-p/10554409
But I did not get a solution from the posts above.
Here are my script:
#Author-
#Description-
import adsk.core, adsk.fusion, adsk.cam, traceback
import math
def generateBox(x, y, z, rootCom: adsk.fusion.Component) -> adsk.fusion.Component:
"""
generate a box component inside rootComponent
x, y, z unit: m
return: component generated by extrude object
"""
extrudes = rootCom.features.extrudeFeatures
x = x*100.0 # convert from m to cm
y = y*100.0
z = z*100.0
# Create a new sketch on the xy plane
sketches = rootCom.sketches
xyPlane = rootCom.xYConstructionPlane
sketch = sketches.add(xyPlane)
# Draw a rectangle on the xy plane
point1 = adsk.core.Point3D.create(-x/2, y/2, 0.0)
point2 = adsk.core.Point3D.create(x/2, y/2, 0.0)
point3 = adsk.core.Point3D.create(x/2, -y/2, 0.0)
point4 = adsk.core.Point3D.create(-x/2, -y/2, 0.0)
sketch_lines = sketch.sketchCurves.sketchLines
line1 = sketch_lines.addByTwoPoints(point1, point2)
line2 = sketch_lines.addByTwoPoints(point2, point3)
line3 = sketch_lines.addByTwoPoints(point3, point4)
line4 = sketch_lines.addByTwoPoints(point4, point1)
# Get the profile defined by the four lines
prof = sketch.profiles.item(0)
# Define the distance to extrude
distance = adsk.core.ValueInput.createByReal(z)
# extrude = extrudes.addSimple(prof, distance, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
extrude = extrudes.addSimple(prof, distance, adsk.fusion.FeatureOperations.NewComponentFeatureOperation)
return extrude.parentComponent
def rotateZ(degree)->adsk.core.Matrix3D:
"""
retrun a transform matrix to rotate about world frame's z-axis with degree
"""
rotZ = adsk.core.Matrix3D.create()
rotZ.setCell(0, 0, math.cos(math.radians(degree)))
rotZ.setCell(1, 0, math.sin(math.radians(degree)))
rotZ.setCell(2, 0, 0.0)
rotZ.setCell(3, 0, 0.0)
rotZ.setCell(0, 1, -math.sin(math.radians(degree)))
rotZ.setCell(1, 1, math.cos(math.radians(degree)))
rotZ.setCell(2, 1, 0.0)
rotZ.setCell(3, 1, 0.0)
rotZ.setCell(0, 2, 0.0)
rotZ.setCell(1, 2, 0.0)
rotZ.setCell(2, 2, 1.0)
rotZ.setCell(3, 2, 0.0)
rotZ.setCell(0, 3, 0.0)
rotZ.setCell(1, 3, 0.0)
rotZ.setCell(2, 3, 0.0)
rotZ.setCell(3, 3, 1.0)
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
textPalette = ui.palettes.itemById("TextCommands")
if not textPalette.isVisible:
textPalette.isVisible = True
# doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
# design.designType = adsk.fusion.DesignTypes.ParametricDesignType
# design.designType = adsk.fusion.DesignTypes.DirectDesignType
rootComp = design.rootComponent
extBox = generateBox(0.1, 0.1, 1, rootComp)
# textPalette.writeText("num of bRepBodies: {}".format(extBox.bRepBodies.count))
extBody = extBox.bRepBodies.item(0)
# textPalette.writeText("num of bRepFaces: {}".format(extBody.faces.count))
extJointFace1 = extBody.faces.item(4) # item 4 is the end extrude face, item 5 is the start extrude face
point1 = extJointFace1.centroid
# Define a axis of rotation
# This can be a linear BRepEdge, ConstructionAxis, or a SketchLine
sketches1 = extBox.sketches
sketch = sketches1.add(extJointFace1)
sketchOrigin = sketch.origin
sketchOriginPoint = sketch.originPoint
theta = 30 # degree
sketchPoint1 = adsk.core.Point3D.create(0.0, 0.0, 0.0)
sketchPoint2 = adsk.core.Point3D.create(math.cos(math.radians(theta))*10, math.sin(math.radians(theta))*10, 0.0)
sketchLine = sketch.sketchCurves.sketchLines.addByTwoPoints(sketchPoint1, sketchPoint2)
# jointGeo = adsk.fusion.JointGeometry.createByCurve(sketchLine, adsk.fusion.JointKeyPointTypes.StartKeyPoint)
# Create the joint geometry
jointGeo = adsk.fusion.JointGeometry.createByPlanarFace(extJointFace1, None, adsk.fusion.JointKeyPointTypes.CenterKeyPoint)
jointOrigins = extBox.jointOrigins
jointOriginInput = jointOrigins.createInput(jointGeo)
jointOrigin1 = jointOrigins.add(jointOriginInput)
# jointXAxis = jointOrigin1.secondaryAxisVector
extBox2 = generateBox(0.1, 0.1, 0.5, rootComp)
extBody2 = extBox2.bRepBodies.item(0)
extJointFace2 = extBody2.faces.item(4)
jointGeo2 = adsk.fusion.JointGeometry.createByPlanarFace(extJointFace2, None, adsk.fusion.JointKeyPointTypes.CenterKeyPoint)
jointOrigins2 = extBox2.jointOrigins
jointOriginInput2 = jointOrigins.createInput(jointGeo2)
jointOrigin2 = jointOrigins2.add(jointOriginInput2)
# Create jont
joints = rootComp.joints
jointInput = joints.createInput(jointOrigin1, jointOrigin2)
# jointInput.setAsRevoluteJointMotion(adsk.fusion.JointDirections.XAxisJointDirection)
jointInput.setAsRevoluteJointMotion(adsk.fusion.JointDirections.CustomJointDirection, sketchLine)
joint1 = joints.add(jointInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
In the script, I first generate two box and set up joint origins, then I draw a sketch line as the custom joint axis. After that, I joint them together, but got an error.
So, how to set up a custom joint axis for a revolute joint?
Thanks a lot.
Solved! Go to Solution.