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: 

SCALE selected faces

1 REPLY 1
Reply
Message 1 of 2
ritacashia
187 Views, 1 Reply

SCALE selected faces

Hello!

I'm developing an add-in for my thesis, and I have to scale a selected face. And that new face will replace the old one that was firstly selected. How can I do it?
Do I scale the face or the boundingBox?

please help me 🤗

1 REPLY 1
Message 2 of 2
BrianEkins
in reply to: ritacashia

You can't scale an individual face in a body.  However, you can copy a face out of a body to create a new body and then scale the new body and use the face in the new body for the replace.  I was curious if the API supports everything you would need to do that and wrote a small script to test it out.  It works.  Besides scaling, I also rotate it a bit and then use it for the face replacement.  Here's the code and I've attached the model I tested it with.  I used the contoured face on the top of the model.  The script has you select it.

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

        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        root = design.rootComponent

        # Have a face selected.
        faceSel = ui.selectEntity('Select a face', 'Faces')
        face = adsk.fusion.BRepFace.cast(faceSel.entity)

        # Create an offset of the face to copy it.
        objs = adsk.core.ObjectCollection.create()
        objs.add(face)
        offsetInput = root.features.offsetFeatures.createInput(objs, adsk.core.ValueInput.createByReal(0), adsk.fusion.FeatureOperations.NewBodyFeatureOperation, False)
        offsetFeature = root.features.offsetFeatures.add(offsetInput)

        # Scale the face body.
        offsetBody = offsetFeature.bodies[0]
        objs.clear()
        objs.add(offsetBody)
        scaleInput = root.features.scaleFeatures.createInput(objs, root.originConstructionPoint, adsk.core.ValueInput.createByReal(1.5))
        scaleFeature = root.features.scaleFeatures.add(scaleInput)

        # Define a transform to rotate the face body.
        newFace = adsk.fusion.BRepFace.cast(scaleFeature.faces[0])
        bnds = newFace.boundingBox
        center = adsk.core.Point3D.create((bnds.minPoint.x + bnds.maxPoint.x)/2,
                                            (bnds.minPoint.y + bnds.maxPoint.y)/2,
                                            (bnds.minPoint.z + bnds.maxPoint.z)/2)
        current = adsk.core.Matrix3D.create()
        current.translation = center.asVector()
        trans = current.copy()
        trans.invert()

        rot = adsk.core.Matrix3D.create()
        rot.setToRotation(math.pi/16, adsk.core.Vector3D.create(1,0,0), adsk.core.Point3D.create(0,0,0))

        # Use a move feature to rotate it.
        trans.transformBy(rot)
        trans.transformBy(current)
        moveInput = root.features.moveFeatures.createInput(objs, trans)
        moveFeature = root.features.moveFeatures.add(moveInput)

        # Replace the original face with the new face.
        sourceColl = adsk.core.ObjectCollection.create()
        sourceColl.add(face)
        targetColl = adsk.core.ObjectCollection.create()
        targetColl.add(moveFeature.faces[0])
        replaceInput = root.features.replaceFaceFeatures.createInput(sourceColl, False, targetColl)
        root.features.replaceFaceFeatures.add(replaceInput)

        # Hide the new face.
        moveFeature.bodies[0].isVisible = False
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com

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