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: 

basic script: copy a sketch in a component.

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
jean-michel_legoff
227 Views, 6 Replies

basic script: copy a sketch in a component.

Hi,

 

I achieved to create a new comonent with a body extruded from each sketch aof a design.

I just was wondering how I can move/copy this sketch in my component
Any Help?

jeanmichellegoff_0-1695716196281.png

 

6 REPLIES 6
Message 2 of 7

this line in Yellow don't works...

Message 3 of 7

Hi @jean-michel_legoff -San.

 

In parametric mode, you should know from the GUI that it is not possible to copy-paste an entire sketch.
For this reason, we have created a sample that draws a sketch curve using the include method.

# Fusion360API Python script
import adsk.core, adsk.fusion, traceback

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

        # Get the active design
        design = app.activeProduct

        # Get the root component of the active design
        root_comp = design.rootComponent

        # Get the sketches in the design
        sketches = root_comp.sketches

        # Iterate through each sketch
        sketch: adsk.fusion.Sketch = None
        for sketch in sketches:

            # get sketch curves
            curves: adsk.core.ObjectCollection = adsk.core.ObjectCollection.createWithArray(
                list(
                    sketch.sketchCurves
                )
            )

            # create occurrence
            new_occ: adsk.fusion.Occurrence = root_comp.occurrences.addNewComponent(
                adsk.core.Matrix3D.create()
            )
            new_comp: adsk.fusion.Component = new_occ.component

            # create new sketch
            new_sketch: adsk.fusion.Sketch = new_comp.sketches.add(
                new_comp.xYConstructionPlane
            )

            # include sketch curves
            new_sketch.include(curves)

            # Name the component with the sketch name
            new_comp.name = sketch.name

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

 

I thought about using the Sketch.copy method, but gave up because Skecth drawn on a flat surface of the body would not be drawn at the desired position.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-899a5797-8bc8-4060-9321-5f81697e0dec 

Message 4 of 7

Hi,

Why if I add this :
# Extrude the sketch
extrudes = new_comp.component.features.extrudeFeatures
ext_input = extrudes.createInput(sketch.profiles.item(0), adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
distance = adsk.core.ValueInput.createByReal(.1)
ext_input.setDistanceExtent(False, distance)
extrudes.add(ext_input)

I can't extrude the sketch?
Message 5 of 7

Hi,
I've successsketch fully edited the script and I'm able to extrude the sketch too

Many thnaks for the help.

there is one ennoying thing remaining...
how to prevent displaying points in the new sketches?
Message 6 of 7

jeanmichellegoff_0-1695739639264.png

 

Message 7 of 7

@jean-michel_legoff -San.

 

Add the following line.

            new_sketch.arePointsShown = False

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