Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Offset Automation (Python?)

doorpoo2
Observer

Offset Automation (Python?)

doorpoo2
Observer
Observer

Hello all,

I have what I hope is a pretty simple question... I have to create multiple offsets of a sketch that is created from an SVG of a text. 

 

-.375

-.3

-.1

-.075

-.275
Which is then repeated for every single letter. Is there away to automate this using the script feature? I looked at the offset tutorial, but it uses a sketch it creates, and I am not sure how to use a sketch that I have already. (Maybe a selected sketch or something like that)

Thanks!

 

 

Screenshot 2023-01-15 123147.png

0 Likes
Reply
Accepted solutions (1)
541 Views
2 Replies
Replies (2)

kandennti
Mentor
Mentor
Accepted solution

Hi @doorpoo2 .

 

I made a script.

# Fusion360API Python script

import traceback
import adsk
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

        msg: str = 'Select Sketch Curve'
        selFilter: str = 'SketchCurves'
        sel: core.Selection = selectEnt(msg, selFilter)
        if not sel:
            return

        sktCrv: fusion.SketchCurve = sel.entity

        distanceList = [
            0.375,
            0.3,
            0.1,
            0.075,
        ]

        exec_multiple_offsets(sktCrv, distanceList)

        ui.messageBox('Done')

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


def exec_multiple_offsets(
    sktCrv: fusion.SketchCurve,
    distanceList: list) -> None:

    skt: fusion.Sketch = sktCrv.parentSketch

    des: fusion.Design = skt.parentComponent.parentDesign
    unitmgr: core.UnitsManager = des.unitsManager
    ratio = unitmgr.convert(
        1,
        unitmgr.defaultLengthUnits,
        unitmgr.internalUnits,
    )
    distLst = [d * ratio for d in distanceList]

    curves = skt.findConnectedCurves(sktCrv)

    dirPoint = adsk.core.Point3D.create(10000000, 10000000, 0)

    skt.isComputeDeferred = True
    for dist in distLst:
            skt.offset(curves, dirPoint, dist)
    skt.isComputeDeferred = False


def selectEnt(
        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


It works like this.


I haven't figured out how to use it, but if it were me, I would avoid making complex sketches and think about making offset bodies.

0 Likes

doorpoo2
Observer
Observer

@kandennti 

That worked perfectly! Thank you soooo much! What a huge time saver. 

 

 

doorpoo2_0-1673840938555.png

 

1 Like