Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inconsistency between Matrix3D.translation documentation and actual behavior

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
nnikbin
1067 Views, 6 Replies

Inconsistency between Matrix3D.translation documentation and actual behavior

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

6 REPLIES 6
Message 2 of 7
jan_priban
in reply to: nnikbin

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();
}

 

 

Message 3 of 7
ekinsb
in reply to: nnikbin

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
Message 4 of 7
nnikbin
in reply to: ekinsb

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

Message 5 of 7
nnikbin
in reply to: jan_priban

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

Message 6 of 7
keqingsong
in reply to: nnikbin

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



Message 7 of 7
nnikbin
in reply to: keqingsong

Hi Keqing,

 

Thanks for your good news 🙂

 

Regards,

Navid

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report