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: 

Is there a way to extrude with stored shapes and lines?

1 REPLY 1
Reply
Message 1 of 2
matthewaudio
85 Views, 1 Reply

Is there a way to extrude with stored shapes and lines?

is there a way to only extrude rectangle A given the following variables?  All the code examples have a stage where they search the sketch items to make a profile.  I already have the sketch items I want to create a profile from 

tltrA = mySketch.sketchCurves.sketchLines.addByTwoPoints(tlA, trA)
tlblA = mySketch.sketchCurves.sketchLines.addByTwoPoints(tlA, blA)
trbrA = mySketch.sketchCurves.sketchLines.addByTwoPoints(trA, brA)
blbrA = mySketch.sketchCurves.sketchLines.addByTwoPoints(blA, brA)
tltrB = mySketch.sketchCurves.sketchLines.addByTwoPoints(tlB, trB)
tlblB = mySketch.sketchCurves.sketchLines.addByTwoPoints(tlB, blB)
trbrB = mySketch.sketchCurves.sketchLines.addByTwoPoints(trB, brB)
blbrB = mySketch.sketchCurves.sketchLines.addByTwoPoints(blB, brB)

 

1 REPLY 1
Message 2 of 2
kandennti
in reply to: matthewaudio

Hi @matthewaudio -San.

 

It is possible that you have the wrong meaning.
I tried to find a profile with the specified line.

# 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
        des: fusion.Design = app.activeProduct
        root: fusion.Component = des.rootComponent

        tlA: core.Point3D = core.Point3D.create(1,2,0)
        trA: core.Point3D = core.Point3D.create(3,2,0)
        blA: core.Point3D = core.Point3D.create(1,-2,0)
        brA: core.Point3D = core.Point3D.create(3,-2,0)
        tlB: core.Point3D = core.Point3D.create(5,2,0)
        trB: core.Point3D = core.Point3D.create(7,2,0)
        blB: core.Point3D = core.Point3D.create(5,-2,0)
        brB: core.Point3D = core.Point3D.create(7,-2,0)

        mySketch: fusion.Sketch = root.sketches.add(root.xYConstructionPlane)

        tltrA = mySketch.sketchCurves.sketchLines.addByTwoPoints(tlA, trA)
        tlblA = mySketch.sketchCurves.sketchLines.addByTwoPoints(tlA, blA)
        trbrA = mySketch.sketchCurves.sketchLines.addByTwoPoints(trA, brA)
        blbrA = mySketch.sketchCurves.sketchLines.addByTwoPoints(blA, brA)
        tltrB = mySketch.sketchCurves.sketchLines.addByTwoPoints(tlB, trB)
        tlblB = mySketch.sketchCurves.sketchLines.addByTwoPoints(tlB, blB)
        trbrB = mySketch.sketchCurves.sketchLines.addByTwoPoints(trB, brB)
        blbrB = mySketch.sketchCurves.sketchLines.addByTwoPoints(blB, brB)

        prof: fusion.Profile = find_profile_with_line(mySketch, tltrA)
        if not prof: return

        extrudeFeats: fusion.ExtrudeFeatures = root.features.extrudeFeatures
        extrudeFeats.addSimple(
            prof,
            core.ValueInput.createByReal(1),
            fusion.FeatureOperations.NewBodyFeatureOperation
        )

        mySketch.isLightBulbOn = True

        ui.messageBox("Done")

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


def find_profile_with_line(
    skt: fusion.Sketch,
    sktCrv: fusion.SketchCurve,
) -> fusion.Profile:

    if skt.profiles.count < 1: return None

    prof: fusion.Profile = None
    loop: fusion.ProfileLoop = None
    crv: fusion.ProfileCurve = None
    for prof in skt.profiles:
        for loop in prof.profileLoops:
            for crv in loop.profileCurves:
                if crv.geometry.isColinearTo(sktCrv.geometry):
                    return prof

    return None

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