Occurrence creation failing: invalid argument transform

Occurrence creation failing: invalid argument transform

Joshua.mursic
Advocate Advocate
518 Views
2 Replies
Message 1 of 3

Occurrence creation failing: invalid argument transform

Joshua.mursic
Advocate
Advocate

Hello, I am having an issue creating a new occurrence using a matrix. I am getting this error

 

RuntimeError: 3 : invalid argument transform

 

I logged the matrices but I do not understand what the issue is. 

 

(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0)

transformBy

(0.9999181351095504, 0.00302995523422106, 0.01243151037958249, 0.12366421759092841, 0.0030299552616395655, 0.8878563476771933, -0.4601107749884012, -1.104974592816854, -0.012431510844021457, 0.46011078801444666, 0.8877744760302924, -3.4855238784639786, 0.0, 0.0, 0.0, 1.0)

 

new matrix:

(0.9999181351095504, 0.00302995523422106, 0.01243151037958249, 0.12366421759092841, 0.0030299552616395655, 0.8878563476771933, -0.4601107749884012, -1.104974592816854, -0.012431510844021457, 0.46011078801444666, 0.8877744760302924, -3.4855238784639786, 0.0, 0.0, 0.0, 1.0)

 

I am using this function to create the occurrence with the resulting matrix

newOccurence = root.occurrences.addNewComponent(matrix)
0 Likes
Accepted solutions (1)
519 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi @Joshua.mursic -San.

 

I have tried.

It seems that the vector of each axis obtained by the getAsCoordinateSystem method must be a unit vector and each axis must be orthogonal.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion
import math

def run(context):
    ui: core.UserInterface = None
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface
        des: fusion.Design = app.activeProduct
        root: fusion.Component = des.rootComponent

        mat: core.Matrix3D = core.Matrix3D.create()
        mat.setWithArray(
            [
                0.9999181351095504, 0.00302995523422106, 0.01243151037958249, 0.12366421759092841,
                0.0030299552616395655, 0.8878563476771933, -0.4601107749884012, -1.104974592816854,
                -0.012431510844021457,0.46011078801444666, 0.8877744760302924, -3.4855238784639786,
                0.0, 0.0, 0.0, 1.0
            ]
        )
        dump_matrix3d(mat, "--before--")
        create_occurrence(root, mat)

        origin, xAxis, yAxis, zAxis = mat.getAsCoordinateSystem()
        xAxis.normalize()
        yAxis.normalize()
        zAxis.normalize()
        yAxis = zAxis.crossProduct(xAxis)
        zAxis = xAxis.crossProduct(yAxis)
        mat.setWithCoordinateSystem(origin, xAxis, yAxis, zAxis)
        dump_matrix3d(mat, "--after--")
        create_occurrence(root, mat)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def create_occurrence(
    targetComp: fusion.Component,
    mat: core.Matrix3D,
) -> fusion.Occurrence:

    try:
        return targetComp.occurrences.addNewComponent(mat)
    except:
        print("**create_occurrence_error**")
        return None


def dump_matrix3d(
    mat: core.Matrix3D,
    msg: str,
) -> None:

    print("\n" + msg)
    _, xAxis, yAxis, zAxis = mat.getAsCoordinateSystem()
    print(f"xAxis.asArray:{xAxis.asArray()}")
    print(f"yAxis.asArray:{yAxis.asArray()}")
    print(f"zAxis.asArray:{zAxis.asArray()}")
    print(f"xAxis.length:{xAxis.length}")
    print(f"yAxis.length:{yAxis.length}")
    print(f"zAxis.length:{zAxis.length}")
    print(f"xAxis-yAxis:{math.degrees(xAxis.angleTo(yAxis))}deg")
    print(f"yAxis-zAxis:{math.degrees(yAxis.angleTo(zAxis))}deg")
    print(f"zAxis-xAxis:{math.degrees(zAxis.angleTo(xAxis))}deg")
Message 3 of 3

Joshua.mursic
Advocate
Advocate

Works perfectly as always @kandennti, thank you very much!