Script that makes a component from a face selection and extrude.

Script that makes a component from a face selection and extrude.

tookemtoni
Collaborator Collaborator
673 Views
2 Replies
Message 1 of 3

Script that makes a component from a face selection and extrude.

tookemtoni
Collaborator
Collaborator

Hello There, Is it possible to make a script that makes a component from face selection and extrude? See demo video.  The design intent is to make edge banding easier.

 

Fusion360_A68HeZar8p.jpg

 

 

 

0 Likes
Accepted solutions (1)
674 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi @tookemtoni -San.

 

I made a simple sample.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

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

        msg: str = 'Select Face'
        selFilter: str = 'Faces'
        sel: core.Selection = select_ent(msg, selFilter)
        if not sel:
            return

        create_extrude_with_new_component(sel.entity)

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


def create_extrude_with_new_component(
        face: fusion.BRepFace
) -> None:

    comp: fusion.Component = face.body.parentComponent
    extrudeFeats: fusion.ExtrudeFeatures = comp.features.extrudeFeatures
    extrudeFeats.addSimple(
        face,
        core.ValueInput.createByReal(1.0),
        fusion.FeatureOperations.NewComponentFeatureOperation,
    )


def select_ent(
    msg: str,
    filterStr: str
) -> core.Selection:

    try:
        app: core.Application = core.Application.get()
        ui: core.UserInterface = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None
Message 3 of 3

tookemtoni
Collaborator
Collaborator

Dear @kandennti,  Magic. Thank You.  See demo video