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: 

Offset Automation (Python?)

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
doorpoo2
246 Views, 2 Replies

Offset Automation (Python?)

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

2 REPLIES 2
Message 2 of 3
kandennti
in reply to: doorpoo2

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.

Message 3 of 3
doorpoo2
in reply to: doorpoo2

@kandennti 

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

 

 

doorpoo2_0-1673840938555.png

 

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