Bodies, sketches, profiles and their relationship

Bodies, sketches, profiles and their relationship

chip.cox
Participant Participant
572 Views
2 Replies
Message 1 of 3

Bodies, sketches, profiles and their relationship

chip.cox
Participant
Participant

I have my addin that creates character stamps working as far as creating one stamp goes.  It draws 3 sketches one is a square outer box.  The second is a hex shape that mirrors the hex head of a screw ( see attached picture ).  The last sketch is just a text box with the letter that goes on the stamp. 

I then create profiles for each sketch, two for the letter sketch. 

I then extrude the box, the box using newbodyfeatureoperation for a distance of 10mm.

I then extrude the first letter profile using joinfeatureoperation for a distance of 12mm so it shows 2mm above the extruded box.

I then extrude the hex shape using the cutfeatureoperation for a distance of 5mm so it cuts out the hex shape from the box.

I then extrude the second letter profile using the cutfeatureoperation for a distance of 8mm so it cuts into the top of the hex shape.  This way you can tell what letter you are stamping while it's face down on the leather.

 

Now I want to put it in a loop so I can create more than one character at a time.  Easy enough, I put a loop around what I have.  That creates new sketches, but it doesn't create a new body.  It keeps applying everything to that one body.  Shouldn't the newbodyfeatureoperation create a new body?

 

I feel like I am doing this the hard way.  How should this be done?

0 Likes
573 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor

You're correct that creating an extrusion with the new body operation should result in a new body. Without seeing your code, I can't comment on what might be wrong. 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 3

kandennti
Mentor
Mentor

Hi @chip.cox .

 

It may be faster to have the completed f3d file attached than to explain it in words.

Please try running this script using the attached data.

# Fusion360API Python script

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

def run(context):
    ui = core.UserInterface.cast(None)
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface
        des: fusion.Design = app.activeProduct
        root: fusion.Component = des.rootComponent

        sktHex: fusion.sketch = root.sketches.itemByName('Hex')
        sktExterior: fusion.sketch = root.sketches.itemByName('Exterior')
        sktTextbox: fusion.sketch = root.sketches.itemByName('Textbox')

        extrudes: fusion.ExtrudeFeatures = root.features.extrudeFeatures

        exec_extrude(
            extrudes,
            sktExterior.profiles[0],
            10,
            fusion.FeatureOperations.NewBodyFeatureOperation,
        )

        exec_extrude(
            extrudes,
            sktTextbox.sketchTexts[0],
            12,
            fusion.FeatureOperations.JoinFeatureOperation,
        )

        exec_extrude(
            extrudes,
            sktHex.profiles[0],
            5,
            fusion.FeatureOperations.CutFeatureOperation,
        )

        exec_extrude(
            extrudes,
            sktTextbox.sketchTexts[0],
            8,
            fusion.FeatureOperations.CutFeatureOperation,
        )

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


def exec_extrude(
    extrudes: fusion.ExtrudeFeatures,
    profile: core.Base,
    distance: float, # units-mm
    operations: fusion.FeatureOperations,
) -> fusion.ExtrudeFeature:

    des: fusion.Design = core.Application.get().activeProduct
    unitMgr: core.UnitsManager = des.unitsManager

    extFeat: fusion.ExtrudeFeature = extrudes.addSimple(
        profile,
        core.ValueInput.createByReal(
            unitMgr.convert(
                distance,
                "mm",
                unitMgr.internalUnits,
            ),
        ),
        operations
    )

    return extFeat