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: 

Incorrect transformation from Occurrence transform.

2 REPLIES 2
Reply
Message 1 of 3
ProtoTechSolutions
576 Views, 2 Replies

Incorrect transformation from Occurrence transform.

We are taking transformation matrix from the occurrences.
But when the joints in assembly are not correct, but In GUI it shows correct position of parts.
And when we try to get the transformation matrix from APIs, it gives incorrect transformation. Please refer attached screenshot.
We are using following code snippet.

 

adsk::core::Ptr<adsk::core::Product> activeProduct = app->activeProduct();
adsk::core::Ptr<adsk::fusion::Design> design = activeProduct;
adsk::core::Ptr<adsk::fusion::Component> rootComp = design->rootComponent();

adsk::core::Ptr<adsk::fusion::Occurrences> occurrences = rootComp->occurrences();
if (occurrences != nullptr)
{
       int occurancesCount = (int)occurrences->count();
       if (occurancesCount > 0)
       {
              for (int childOccurancesCnt = 0; childOccurancesCnt < occurancesCount; childOccurancesCnt++)
              {
                      adsk::core::Ptr<adsk::fusion::Occurrence> occ = occurrences->item(childOccurancesCnt);
                      if (occ != nullptr)
                             std::vector<double> transMat = child->transform()->asArray();

              }
       }
}


Please guide us to get correct transformation.
Please let us know if we are missing anything.

2 REPLIES 2
Message 2 of 3

hey, i hae the same issue. did you solve it?

Message 3 of 3
kandennti
in reply to: rax2003_7

Hi rax2003_7.

I hope it will be transmitted well.

 

The body of the image is in [Component2: 1].
1.png

 

Move [Component1:1] to the image state.
2.png

 

Next, move [Component2:1] to the image state.
3.png

 

It will be in this state.
Red arrow : the origin of the root component
Blue arrow : the origin of the ’’Component1:1'
Green arrow : the origin of the ’Component2:1’
4.png

 

 

I will explain in this situation.
Attach the created script.

 

When you execute the script and click the Body of the model data, the [Component2: 1] Matrix3D is displayed from the root component.
Also, a sketch is created on the root component for confirmation, and a point is created so that it is the same position as the origin of [Component2: 1].

 

'GetRootMatrix' function gets Matrix3D from root component to any component.

def GetRootMatrix(comp):
    comp = adsk.fusion.Component.cast(comp)
    des = adsk.fusion.Design.cast(comp.parentDesign)
    root = des.rootComponent

    mat = adsk.core.Matrix3D.create()
  
    if comp == root:
        return mat

    occs = root.allOccurrencesByComponent(comp)
    if len(occs) < 1:
        return mat

    occ = occs[0]
    occ_names = occ.fullPathName.split('+')
    occs = [root.allOccurrences.itemByName(name) 
                for name in occ_names]
    mat3ds = [occ.transform for occ in occs]
    mat3ds.reverse() #important!!
    for mat3d in mat3ds:
        mat.transformBy(mat3d)

    return mat

 

I looked for a way to get root component relationships from deep components like this one.
Only Occurrence.fullPathName (return string) could be found.

5.png

Get a list of Matrix3D based on the obtained occurrence name.

    occ_names = occ.fullPathName.split('+')
    occs = [root.allOccurrences.itemByName(name) 
                for name in occ_names]
    mat3ds = [occ.transform for occ in occs]

From there, it transform in the order of deep position.

    mat = adsk.core.Matrix3D.create()

      ・・・

    mat3ds.reverse() #important!!
    for mat3d in mat3ds:
        mat.transformBy(mat3d)

6.png

 

I believe that the Matrix3D obtained this way is correct.
The linked script was created using this way.

https://github.com/kantoku-code/ExportWire 

https://github.com/kantoku-code/Fusion360-ExportSketchPointsCoordinate 

 

I would like to know if there is an easier way to get it.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report