How to find origin point relative to design of a moved component

How to find origin point relative to design of a moved component

Anonymous
Not applicable
755 Views
1 Reply
Message 1 of 2

How to find origin point relative to design of a moved component

Anonymous
Not applicable

If a user moves a component (not just the bodies) the origin of the component moves with it. However from the Python Scripts if you ask for the geometry of the component's originConstructionPoint, it still reporst (0,0,0) and if you try to get the vector from the rootComponent's origin to the components origin, it is just <0,0,0> which is wrong?

 

How do you get the "world Geometry" of a component's origin after it has been moved?

0 Likes
Accepted solutions (1)
756 Views
1 Reply
Reply (1)
Message 2 of 2

liujac
Alumni
Alumni
Accepted solution

You need to create an object with assembly context. Please try the code below.

 

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

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        design = adsk.fusion.Design.cast(app.activeProduct)
        root = design.rootComponent
        occs = root.occurrences
        occ = occs[0]
        comp = occ.component
        origin = comp.originConstructionPoint
        originProxy = origin.createForAssemblyContext(occ)
        point = originProxy.geometry
        ui.messageBox('X:{}, Y:{}, Z:{}'.format(point.x, point.y, point.z));

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Jack

0 Likes