<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: [InternalValidationError] Get RuntimeError when using custom joint direction axis in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12077737#M3344</link>
    <description>&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3787950"&gt;@kandennti&lt;/a&gt; -San&lt;BR /&gt;Again, thank you so much!</description>
    <pubDate>Tue, 04 Jul 2023 02:48:02 GMT</pubDate>
    <dc:creator>NuofanQiu</dc:creator>
    <dc:date>2023-07-04T02:48:02Z</dc:date>
    <item>
      <title>[InternalValidationError] Get RuntimeError when using custom joint direction axis</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12076115#M3338</link>
      <description>&lt;P&gt;I am trying to create a revolute joint using custom joint axis, but I got an error:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;RuntimeError: 2 : InternalValidationError : Utils::getObjectPath(object, objPath, nullptr, context)&lt;/LI-CODE&gt;&lt;P&gt;And I searched at this forum, here are the relative posts:&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/copy-body-and-move-by-code/m-p/10554409" target="_blank"&gt;https://forums.autodesk.com/t5/fusion-360-api-and-scripts/copy-body-and-move-by-code/m-p/10554409&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/trouble-scaling-after-copying-and-moving-component/m-p/11327405" target="_blank"&gt;https://forums.autodesk.com/t5/fusion-360-api-and-scripts/trouble-scaling-after-copying-and-moving-component/m-p/11327405&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/add-rectangular-pattern-feature-to-component/m-p/11355874" target="_blank"&gt;https://forums.autodesk.com/t5/fusion-360-api-and-scripts/add-rectangular-pattern-feature-to-component/m-p/11355874&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/rotate-imported-step-file-using-api-fully-scripted/m-p/9582766" target="_blank"&gt;https://forums.autodesk.com/t5/fusion-360-api-and-scripts/rotate-imported-step-file-using-api-fully-scripted/m-p/9582766&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But I did not get a solution from the posts above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are my script:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback
import math

def generateBox(x, y, z, rootCom: adsk.fusion.Component) -&amp;gt; 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)-&amp;gt;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()))&lt;/LI-CODE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, how to set up a custom joint axis for a revolute joint?&lt;/P&gt;&lt;P&gt;Thanks a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2023 09:49:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12076115#M3338</guid>
      <dc:creator>NuofanQiu</dc:creator>
      <dc:date>2023-07-03T09:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: [InternalValidationError] Get RuntimeError when using custom joint direction axis</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12076446#M3339</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13720789"&gt;@NuofanQiu&lt;/a&gt;&amp;nbsp;-San.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not understand what you want to do.&lt;BR /&gt;Could you please attach an f3d file with GUI manipulation of what state you want to achieve?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2023 13:08:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12076446#M3339</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2023-07-03T13:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: [InternalValidationError] Get RuntimeError when using custom joint direction axis</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12076561#M3340</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13720789"&gt;@NuofanQiu&lt;/a&gt;&amp;nbsp;-San.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I could not use sketchLine on the rotational axis of the joint even though I manipulated it in the GUI.&lt;BR /&gt;Therefore, we tried using ConstructionAxis.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;・・・
        # Create jont
        joints = rootComp.joints
        jointInput = joints.createInput(jointOrigin1, jointOrigin2)
        # jointInput.setAsRevoluteJointMotion(adsk.fusion.JointDirections.XAxisJointDirection)
        # jointInput.setAsRevoluteJointMotion(adsk.fusion.JointDirections.CustomJointDirection, sketchLine)

        axisLine: adsk.fusion.ConstructionAxis = get_revolute_axis(rootComp, sketchPoint1, sketchPoint2)
        jointInput.setAsRevoluteJointMotion(adsk.fusion.JointDirections.CustomJointDirection, axisLine)

        joint1 = joints.add(jointInput)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def get_revolute_axis(
    comp: adsk.fusion.Component,
    sPoint: adsk.core.Point3D,
    ePoint: adsk.core.Point3D,
) -&amp;gt; adsk.fusion.ConstructionAxis:

    app: adsk.core.Application = adsk.core.Application.get()
    des: adsk.fusion.Design = app.activeProduct

    vec: adsk.core.Vector3D = sPoint.vectorTo(ePoint)
    vec.normalize()

    infinite: adsk.core.InfiniteLine3D = adsk.core.InfiniteLine3D.create(
        sPoint,
        vec,
    )

    baseFeat: adsk.fusion.BaseFeature = None
    if des.designType == adsk.fusion.DesignTypes.ParametricDesignType:
        baseFeat = comp.features.baseFeatures.add()

    axes: adsk.fusion.ConstructionAxes = comp.constructionAxes
    axisIpt: adsk.fusion.ConstructionAxisInput = axes.createInput()
    axis: adsk.fusion.ConstructionAxis = None
    if baseFeat:
        try:
            baseFeat.startEdit()
            axisIpt.setByLine(infinite)
            axis = axes.add(axisIpt)
        except:
            pass
        finally:
            baseFeat.finishEdit()
    else:
        axisIpt.setByLine(infinite)
        axis = axes.add(axisIpt)

    return axis&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 03 Jul 2023 13:52:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12076561#M3340</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2023-07-03T13:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: [InternalValidationError] Get RuntimeError when using custom joint direction axis</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12076632#M3341</link>
      <description>&lt;P&gt;Thank you for your reply.&lt;/P&gt;&lt;P&gt;Actually what I want to do have post in this post: &lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/how-to-create-a-custom-joint-direction-for-a-revolute-joint/td-p/12059105" target="_blank"&gt;https://forums.autodesk.com/t5/fusion-360-api-and-scripts/how-to-create-a-custom-joint-direction-for-a-revolute-joint/td-p/12059105&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found it is not easy to create a custom joint axis for a revolute joint even use GUI(maybe I am not familiar with Fusion360).&lt;/P&gt;&lt;P&gt;I found the API description here:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NuofanQiu_0-1688393954865.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1236025iCA90496133895143/image-size/medium?v=v2&amp;amp;px=400" role="button" title="NuofanQiu_0-1688393954865.png" alt="NuofanQiu_0-1688393954865.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;A linear edge, planar face and cylindrical face seems not suitable for the Bennett mechanism, so I tried to use the sketch line as the custom rotation axis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try your method right now! And give you a response as soon as possible.&lt;/P&gt;&lt;P&gt;Thanks again! You are so nice!&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2023 14:23:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12076632#M3341</guid>
      <dc:creator>NuofanQiu</dc:creator>
      <dc:date>2023-07-03T14:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: [InternalValidationError] Get RuntimeError when using custom joint direction axis</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12076685#M3342</link>
      <description>Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3787950"&gt;@kandennti&lt;/a&gt; -San (I just learned 'San' is a respectful title in Japanese)&lt;BR /&gt;You code is elegant and easy to understand. I think it solved my problem(although I haven't finished it yet).&lt;BR /&gt;&lt;BR /&gt;I think you are very experienced in Fusion360 API. Do you have any suggestion or tutorial recommendation for learning Fusion360 API? I have read the introduction in Fusion360 API web-site and struggling with Fusion360 API.&lt;BR /&gt;I found that you have write several post about Fusion360API on your blog. I will read them. But I do not understand Japanese(I will try some translator), do you have any good English resources that can help me for learning Fusion360 API?&lt;BR /&gt;Thanks a lot!</description>
      <pubDate>Mon, 03 Jul 2023 14:45:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12076685#M3342</guid>
      <dc:creator>NuofanQiu</dc:creator>
      <dc:date>2023-07-03T14:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: [InternalValidationError] Get RuntimeError when using custom joint direction axis</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12077649#M3343</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13720789"&gt;@NuofanQiu&lt;/a&gt;&amp;nbsp;-San.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have not seen any solid tutorials.&lt;BR /&gt;The content I do know about is online documentation and &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2549199"&gt;@prainsberry&lt;/a&gt;&amp;nbsp;-San here.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/tapnair/Fusion360APIClass" target="_blank" rel="noopener"&gt;https://github.com/tapnair/Fusion360APIClass&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, this forum is a big help.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2023 01:17:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12077649#M3343</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2023-07-04T01:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: [InternalValidationError] Get RuntimeError when using custom joint direction axis</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12077737#M3344</link>
      <description>&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3787950"&gt;@kandennti&lt;/a&gt; -San&lt;BR /&gt;Again, thank you so much!</description>
      <pubDate>Tue, 04 Jul 2023 02:48:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/12077737#M3344</guid>
      <dc:creator>NuofanQiu</dc:creator>
      <dc:date>2023-07-04T02:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: [InternalValidationError] Get RuntimeError when using custom joint direction axis</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/13270976#M3345</link>
      <description>&lt;P&gt;Hi, I try this way, but still have runtime error when I&amp;nbsp; add&amp;nbsp;ConstructionAxis to a sub component(to root component is&amp;nbsp; ok). do you know why? Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 07:46:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/internalvalidationerror-get-runtimeerror-when-using-custom-joint/m-p/13270976#M3345</guid>
      <dc:creator>huzq1</dc:creator>
      <dc:date>2025-01-20T07:46:44Z</dc:date>
    </item>
  </channel>
</rss>

