getting the origin point of the rootComponent

getting the origin point of the rootComponent

Josh3GG88
Enthusiast Enthusiast
592 Views
2 Replies
Message 1 of 3

getting the origin point of the rootComponent

Josh3GG88
Enthusiast
Enthusiast

hello, 

could anyone help me here? i am trying to get the Global z value and use this as a base for my script. the code i have here works like i expect it to, only that it takes the local origin point where I want the global.

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

app = adsk.core.Application.get()
ui = app.userInterface

def ColorWhite(j):

    
        j.appearance = app.favoriteAppearances.itemByName("WHITE")


        
    




def run(context):
    try:
        
        design = adsk.fusion.Design.cast(app.activeProduct)

        rootComp = design.rootComponent
        for i in range(0, rootComp.allOccurrences.count):

            occ = rootComp.allOccurrences.item(i)
            
            subComp = occ.component

            for k in range(0, subComp.bRepBodies.count):
                bodies = subComp.bRepBodies.item(k)
                boundBox = bodies.boundingBox.maxPoint.z - bodies.boundingBox.minPoint.z
                faces = bodies.faces

                for j in faces:
                      if j.centroid.z < .001 or abs(j.centroid.z-boundBox) < .001:
                        ColorWhite(j)
    
    
    
    
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
    
    
    
0 Likes
Accepted solutions (1)
593 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor
Accepted solution

I don't see in your code where you're attempting to get an origin point.

 

The global coordinate system (or the coordinate system of the root component) is always (0,0,0).

 

Because of how you're iterating through the assembly (getting the occurrences from the root component, getting the component from the occurrence, and then getting the bounds), the bounds are returned in the context of the component referenced by the occurrence. If you want the bounds in the context of the root component, change the following lines:

            subComp = occ.component

            for k in range(0, subComp.bRepBodies.count):

to:

            for k in range(0, occ.bRepBodies.count):
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3

Josh3GG88
Enthusiast
Enthusiast

nice. thanks. that was an easy solution. by the way, i am new to python and new to fusion API so i might ask some basic (maybe dumb) questions.

0 Likes