Offset a projected sketch

Offset a projected sketch

victoriaN4VP7
Participant Participant
642 Views
3 Replies
Message 1 of 4

Offset a projected sketch

victoriaN4VP7
Participant
Participant

I am trying to offset a sketch of a projected spline 

 

import adsk.core, adsk.fusion, adsk.cam, traceback

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

        targetBody: adsk.fusion.BRepBodies= root.bRepBodies[4]
        skt: adsk.fusion.Sketch = root.sketches.add(root.xYConstructionPlane)
        skt.project(targetBody)
   
        SketchSel = ui.selectEntity('Select sketch to offset', 'Sketches')
        if SketchSel:
            sketchSel = SketchSel.entity
 
        sketch = adsk.fusion.Sketch.cast(sketchSel)
        points=adsk.core.ObjectCollection.create()
        points.add(sketch.sketchPoints)
        spline = sketch.sketchCurves.sketchFittedSplines.add(points)
        curve = sketch.findConnectedCurves(spline)
        dirPoint = adsk.core.Point3D.create(6, 0, 0)
        offsetCurves = sketch.offset(curve, dirPoint, -1)
0 Likes
643 Views
3 Replies
Replies (3)
Message 2 of 4

BrianEkins
Mentor
Mentor

I'm not sure what you're trying to do since your code seems to be model dependent. Here's a modified version of your code that successfully offsets a projected curve. To use it, create a new design and create a single spherical body in the root component. Run the code, and it will project the sphere onto a sketch and then offset the projected result.

BrianEkins_0-1687911395806.png

 

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

        targetBody: adsk.fusion.BRepBodies= root.bRepBodies[0]
        skt: adsk.fusion.Sketch = root.sketches.add(root.xYConstructionPlane)
        skt.project(targetBody)
   
        dirPoint = adsk.core.Point3D.create(6, 0, 0)
        curves = adsk.core.ObjectCollection.create()
        curves.add(skt.sketchCurves[0])
        offsetCurves = skt.offset(curves, dirPoint, -1)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) 
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 4

victoriaN4VP7
Participant
Participant

Thank you!

 

This is now working, however the projected curve that I am trying to offset is made up of multiple connected spline segments. With this code only one segment of the spline is being offset.  I'm not sure how to collect all of the projected curves to offset them all. 

 

victoriaN4VP7_0-1687956903125.png

 

0 Likes
Message 4 of 4

nathanieltsh
Explorer
Explorer

HI Hi 
i'm also having problems with the only 1 curves/lines is offseted. 
wondering if @BrianEkins and @victoriaN4VP7 have any solution? 

0 Likes