Proxy from UserInterface.selectEntity?

Proxy from UserInterface.selectEntity?

CADacombs
Enthusiast Enthusiast
373 Views
1 Reply
Message 1 of 2

Proxy from UserInterface.selectEntity?

CADacombs
Enthusiast
Enthusiast

The script below allows the selection of a BrepBody using UserInterface.selectEntity.  It then duplicates the body to the root component.  The new body is at the component definition's position and orientation.  Shouldn't it instead be coincident with the proxy?

 

proxyStudy.gif

import adsk.core as ac
import adsk.fusion as af
import traceback


app: ac.Application = ac.Application.get()
ui: ac.UserInterface = app.userInterface
design: af.Design = app.activeProduct
rootComp = design.rootComponent


def addBody_toRoot(body: af.BRepBody):
    bodies: af.BRepBodies = rootComp.bRepBodies
    
    if design.designType == af.DesignTypes.ParametricDesignType:
        baseFeat = rootComp.features.baseFeatures.add()
        baseFeat.startEdit()
        bodies.add(body, baseFeat)
        baseFeat.finishEdit()
    else:
        # DirectDesignType.
        bodies.add(body)


def run(context):
    try:
        while True:
            try:
                sel = ui.selectEntity('Select body', 'Bodies')
            except:
                break

            body: af.BRepBody = sel.entity

            if body.assemblyContext is None:
                app.log("Native object picked.  Try again.")
                continue

            addBody_toRoot(body)
      
    except:
        app.log('Failed:\n{}'.format(traceback.format_exc()))

    app.log("End of script.")

 

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

kandennti
Mentor
Mentor
Accepted solution

Hi @CADacombs .

 

I think this is a specification.

An easy way to perform that operation is to use the TemporaryBRepManager.copy method.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-26E53439-9DE5-4A11-93AD-7E0570BAA657 

def addBody_toRoot(body: af.BRepBody):
    bodies: af.BRepBodies = rootComp.bRepBodies

    tmpMgr: af.TemporaryBRepManager = af.TemporaryBRepManager.get()
    clone: af.BRepBody = tmpMgr.copy(body)

    if design.designType == af.DesignTypes.ParametricDesignType:
        baseFeat = rootComp.features.baseFeatures.add()
        baseFeat.startEdit()
        bodies.add(clone, baseFeat)
        baseFeat.finishEdit()
    else:
        # DirectDesignType.
        bodies.add(clone)

 

The copy method always returns the result on the RootComponent.