Component's origin point.

Component's origin point.

Anonymous
Not applicable
2,860 Views
9 Replies
Message 1 of 10

Component's origin point.

Anonymous
Not applicable

Please, help.

 

How can I get origin point (starting point) for different components in design?

If I use originConstructionPoint it returns '(0, 0, 0)', but in UI origins are not  located in the same place.

This code in Python returns different names of components and the same coordinates (0, 0, 0) :

 

            design = adsk.fusion.Design.cast(app.activeProduct)
            components = design.allComponents
            countComp=0
            while countComp<components.count:
                component = components.item(countComp)
                p = component.originConstructionPoint.geometry
                ui.messageBox(str(component.name)+"  "+str(p.x)+"  "+str(p.y)+"  "+str(p.z))
                countComp+=1

Please, how can I get absolute value of coordinates of origins from UI?

0 Likes
Accepted solutions (1)
2,861 Views
9 Replies
Replies (9)
Message 2 of 10

ekinsb
Alumni
Alumni
Accepted solution

The terminology used in the UI is a bit confusing because there are actually components and instances of components.  What you see in the UI are the instances of components.  The API refers to these as "occurrences".  There's a topic in the API help that discusses this that should help.  http://help.autodesk.com/view/NINVFUS/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A  What you actually want in your case are occurrences because they're what define the position within the assembly.  Each occurrence has a transform property which returns a transformation matrix which contains the position and orientation of the occurrence.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 10

Anonymous
Not applicable

Thank you for solution.

0 Likes
Message 4 of 10

Anonymous
Not applicable

Good day.

 

Sorry for returning to this issue.

But I faced with the same  problem again. How can I get the "occurrence.transform" (i.e. origin point) for every body in "design.allComponents"? 

I tried to use:

 

design = adsk.fusion.Design.cast(app.activeProduct)
for comp in range(design.allComponents.count):
            component = design.allComponents.item(comp)
            bodies = component.bRepBodies
            for b in range(bodies.count):
                body = bodies.item(b)
                # here I need transformation matrix for body
                if design.rootComponent.allOccurrencesByComponent(component).count>0:
                     matrix = design.rootComponent.allOccurrencesByComponent(component).item(0).transform
                else:
                     matrix = adsk.core.Matrix3D.create()

 

But it doesn't provide what I need.

Please, help with the ending part of code.

 

 

0 Likes
Message 5 of 10

ekinsb
Alumni
Alumni

It's not clear to me what you're trying to do.  Bodies don't have an associated transform.  They just exist in the space of their parent component.  Any occurrences that reference that component will display the body since it's part of the component.  Transforming the occurrence will result in the body be repositioned.

 

Below is some code that gets and displays the translation for every occurrence in an assembly.  There are two sets of code.  The first does this by getting all of the components and then all occurrence that reference that component and displaying information about them.  The second just gets every occurrence.  The only difference in the result is that they're organized differently and the all components list also lists the root component, although it will never have any occurrences that reference it.

 

def getOccurrencePositions():
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        design = adsk.fusion.Design.cast(app.activeProduct)
        # Iterate through all of the components in this design.
        results = ''
        for comp in design.allComponents:
            results += 'Component: ' + comp.name + '\n'

            # Get the occurrences that reference this component.
            for occ in design.rootComponent.allOccurrencesByComponent(comp):
                trans = occ.transform
                results += '   Occ: ' + occ.name + ', (' + str(trans.translation.x) + ',' + \
                            str(trans.translation.y) + ',' + str(trans.translation.z) + ')\n'

        ui.messageBox(results, 'Results by component')

        results = ''
        for occ in design.rootComponent.allOccurrences:
            trans = occ.transform
            results += '   Occ: ' + occ.name + ', (' + str(trans.translation.x) + ',' + \
                       str(trans.translation.y) + ',' + str(trans.translation.z) + ')\n'

        ui.messageBox(results, 'Results by occurrence')

    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
Message 6 of 10

Anonymous
Not applicable

I am sorry for not clear explanation.

I really need  the position of the body within the assembly. But I get the list of all bodies from component, though not component but occurrence have the transform property. And one component is referenced by some occurrences. So I can't to conect the component what I get the list of bodies from and the necessary ocurrence.  And it's still not clear to me...

0 Likes
Message 7 of 10

Anonymous
Not applicable

My final problem occured because of I didn't consider that all occurrences in chain have own transform properties.

So I tried to solve it with this code:

 

occurrences= adsk.fusion.Design.cast(app.activeProduct).rootComponent.allOccurrences
for occurrence in occurrences:
      bodies = occurrence.component.bRepBodies
      matrix = GetMatrix(occurrence)


def GetMatrix(occurrence):            # method to get resulting matrix for the whole chain of occurrences
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        matrix = occurrence.transform
        while occurrence.assemblyContext:
            matrix.transformBy(occurrence.assemblyContext.transform)
            occurrence = occurrence.assemblyContext
        return matrix                                # returns resulting matrix
    except:
        if ui:
            ui.messageBox('Get Matrix failed:\n{}'.format(traceback.format_exc()))   

 

Hope, it will work for all models...

0 Likes
Message 8 of 10

ekinsb
Alumni
Alumni

I think there's a misunderstanding somewhere.  It might help if rather than talk about how to use certain API functionality if you can instead explain what it is that you're trying to accompish.  I might be able to better help with a solution then.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 9 of 10

Anonymous
Not applicable

My task is to collect the geometry for all bodies and meshes in current design and create the COLLADA file including all them. So I get all bodies and meshes from every component, then calculate triangle mesh from them, and use the coordinates of vertices to save geometry in COLLADA file. Model from COLLADA will have only one origin point (0, 0, 0) to be built, on the other hand bodies in different occurrences have different origin points.  So I use transform property of the occurrence to change the coordinates of bodies for saving them with one common origin point.

I apply the code above to get transform matrix in case of occurrence contains other occurrences with bodies.

 

I think that the misunderstanding caused by my bad English.

 

However, thank you for your answers and patience.

0 Likes
Message 10 of 10

liujac
Alumni
Alumni

According to your description above, it may be similar to the question here: Getting triangulated mesh data in world/object space

0 Likes