Inconsistency between Matrix3D.translation documentation and actual behavior

nnikbin
Collaborator
Collaborator

Inconsistency between Matrix3D.translation documentation and actual behavior

nnikbin
Collaborator
Collaborator

Hi,

Based on Matrix3D.translation documentation:

it "Gets and sets the translation component of the matrix"

 

but setting it actually resets the matrix to an identify matrix, then sets the translation.

 

Here is a code block showing this inconsistency:

 

import adsk.core, adsk.fusion, adsk.cam, traceback, math

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        transform = adsk.core.Matrix3D.create()
        transform.setToRotation(math.pi/3, adsk.core.Vector3D.create(0, 1, 0), adsk.core.Point3D.create(0, 0, 0))
        ui.messageBox(str(transform.asArray()))
        transform.translation = adsk.core.Vector3D.create(20, 20, 20)
        ui.messageBox(str(transform.asArray()))

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

 

The following picture shows the result:

Capture_09.png

 

Thanks,

Navid

0 Likes
Reply
Accepted solutions (1)
1,090 Views
6 Replies
Replies (6)

jan_priban
Autodesk
Autodesk

Hi Navid,

 

I can share my script that creates copy of component in the active document. There is also Matrix3D.translation and it works as expected. So you can use it for your propose.

 

It modifies translation matrix by setCell method

 

trans.setCell(0, 3, 15.0);

 

Regards

 

Jan (Autodesk Fusion 360 team)

 

//Author-JP
//Description-tocite schody

function run(context) {

"use strict";
if (adsk.debug === true) {
/*jslint debug: true*/
debugger;
/*jslint debug: false*/
}

var ui;
try {
var app = adsk.core.Application.get();
ui = app.userInterface;

var product = app.activeProduct;
var design = adsk.fusion.Design(product);
if (!design) {
ui.messageBox('No active Fusion design', 'No Design');
return;
}

// Get the root component of the active design.
var rootComp = design.rootComponent;
var occs = rootComp.allOccurrences;

// Gather information about each unique component
var count = occs.count;
ui.messageBox(count.toString(), 'pocet');

//jmena vsech component
var i;
for (i = 0;i < count;++i) {
var comp = occs.item(i).component;
ui.messageBox(comp.name, 'jmeno');
}

//var comp = occs.item(0).component;
//var jmeno = comp.name
//ui.messageBox(jmeno,'jmeno');


// Create a new occurrence.
var trans = adsk.core.Matrix3D.create();
//var occ = rootComp.occurrences.addNewComponent(trans);

// Get the associated component.
//var newComp = occs.item(i).component;
//var newComp = occ.component;

// Create a new occurrence for the component, offset by 15 cm in the X direction.
trans.setCell(0, 3, 15.0);
var newOcc = rootComp.occurrences.addExistingComponent(occs.item(0).component, trans);



//ui.messageBox('Hello script');
}
catch (e) {
if (ui) {
ui.messageBox('Failed : ' + (e.description ? e.description : e));
}
}

adsk.terminate();
}

 

 

0 Likes

ekinsb
Alumni
Alumni
Accepted solution

Thank you for reporting this.  This is not expected behavior and I've logged a bug for the problem.  Following up with Jan's response, a workaround is to set the specific cells of the matrix that define the translation.  Here's a modified version of your code that creates the correct result.

 

import adsk.core, adsk.fusion, adsk.cam, traceback
import math

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        transform = adsk.core.Matrix3D.create()
        transform.setToRotation(math.pi/3, adsk.core.Vector3D.create(0, 1, 0), adsk.core.Point3D.create(0, 0, 0))
        ui.messageBox(str(transform.asArray()))
        
        #transform.translation = adsk.core.Vector3D.create(20, 20, 20)
        transform.setCell(0, 3, 20) # X component of translate
        transform.setCell(1, 3, 20) # Y component of translate
        transform.setCell(2, 3, 20) # Z component of translate
        ui.messageBox(str(transform.asArray()))

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

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes

nnikbin
Collaborator
Collaborator

Hi Brian,

 

Thanks for logging the bug. I was aware of the workaround by using setcell. I just wanted to report the issue.

 

Best regards,

Navid

0 Likes

nnikbin
Collaborator
Collaborator

Hi Jan,

 

Thanks for your reply,


@jan.priban wrote:

There is also Matrix3D.translation and it works as expected.

 

As Brian confirmed,  "This is not expected behavior"

 

Best regards,

Navid

0 Likes

keqingsong
Community Manager
Community Manager

Good news! We are getting this fixed in the next update coming this December! 


Keqing Song
Autodesk Fusion Community Manager
Portland, Oregon, USA

Become an Autodesk Fusion Insider



0 Likes

nnikbin
Collaborator
Collaborator

Hi Keqing,

 

Thanks for your good news 🙂

 

Regards,

Navid

0 Likes