Incorrect transformation from Occurrence transform.

ProtoTechSolutions
Participant Participant
930 Views
2 Replies
Message 1 of 3

Incorrect transformation from Occurrence transform.

ProtoTechSolutions
Participant
Participant

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.

0 Likes
931 Views
2 Replies
Replies (2)
Message 2 of 3

rax2003_7
Participant
Participant

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

0 Likes
Message 3 of 3

kandennti
Mentor
Mentor

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.

1 Like