Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add move feature to base feature

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
ebunn3
192 Views, 2 Replies

Add move feature to base feature

Hello,

 

I am trying to add a move feature in conjunction with a base feature and I have something fundamentally wrong with my code.   I don't know if this is possible to do or not.  Can someone tell me if this is possible or not and how I would go about achieving this.  Ultimately the base feature will contain more than just a single move feature.  The example is just an attempt to work out the code.

 

Thanks in advance.

 

Eric

def moveBody_BF(body,x,y,z):
    """This function will move a single body. x,y and z should be in cm.
     """
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = app.activeProduct
        rootComp = design.rootComponent

        baseFeats = rootComp.features.baseFeatures
        baseFeat = baseFeats.add()
        baseFeat.startEdit()

        inputEnts = adsk.core.ObjectCollection.create()
        inputEnts.add(body)

        #create the Matrix3D
        mat = adsk.core.Matrix3D.create()

        #define the vector
        vector = adsk.core.Vector3D.create(x, y, z)
        mat.translation = vector

        #make the move
        moveFeatures = baseFeat.parentComponent.features.moveFeatures
        input = moveFeatures.createInput(inputEnts, mat)
        input.targetBaseFeature = baseFeat
        moveFeature = moveFeatures.add(input)

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


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

#Select body
body = ui.selectEntity('Select a body', 'Bodies').entity

#define the distances to move
x=20.00*2.54;y=0.00*2.54;z=0.00*2.54

#move body
moveBody_BF(body,x,y,z)
2 REPLIES 2
Message 2 of 3
BrianEkins
in reply to: ebunn3

Here's a modified version of your program that works.

 

I'm not sure what your intent is but you can't move a parametric body while a base feature is active. My code copies the selected body into the base feature. The copy is owned by the base feature and is not parametric and can be moved within the base feature. You'll see the same limitations when using the UI. If you want to move the parametric body, then there's no reason to have a base feature and you can use a move feature to move it.

 

def moveBody_BF(body,x,y,z):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design: adsk.fusion.Design = app.activeProduct
        rootComp = design.rootComponent

        # Create a new base feature.
        baseFeats = rootComp.features.baseFeatures
        baseFeat = baseFeats.add()

        # Set it to edit mode.
        baseFeat.startEdit()

        # Copy the selected body into the base feature.
        baseFeatBody = rootComp.bRepBodies.add(body, baseFeat)

        # Add the new body to a collection.
        inputEnts = adsk.core.ObjectCollection.create()
        inputEnts.add(baseFeatBody)

        # Define the transform.
        mat = adsk.core.Matrix3D.create()
        vector = adsk.core.Vector3D.create(x, y, z)
        mat.translation = vector

        # Move the body, using a move feature.
        moveFeatures = baseFeat.parentComponent.features.moveFeatures
        input = moveFeatures.createInput(inputEnts, mat)
        input.targetBaseFeature = baseFeat
        moveFeature = moveFeatures.add(input)

        # Finish the base feature edit.
        baseFeat.finishEdit()
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3
ebunn3
in reply to: BrianEkins

Thank you Brian.  I think this should do it.

 

Eric

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report