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: 

Sketching on one sketch for sweeping feature

4 REPLIES 4
Reply
Message 1 of 5
100053800EC87E
201 Views, 4 Replies

Sketching on one sketch for sweeping feature

Hey,

 

Previously I was able to draw one full path as one sketch using connected lines using this command 

 

 

sketch_lines = theSketch.sketchCurves.sketchLines.addByTwoPoints(theSketchLine.endSketchPoint, linePoints[iPt])

 

It was working perfectly fine. 
Now the issue is that, in this same sketch there are small lines creating curves, so I planned to re-create the curve by using three points Arc command as seen below

 

arcStartPoint = theSketchLine.endSketchPoint
arcEndPoint = linePoints[iPt]
areJoiningPoint = linePoints[iPt-1]
sketch_curves = theSketch.sketchCurves.sketchArcs.addByThreePoints(arcStartPoint, areJoiningPoint, arcEndPoint)

 

 The issue is that the arcStartPoint is correct where it start at the endSketchpoint of the line, while the next line doesn't actually start at the end of the sketchpoint of the arc ! 
I think whats causing the issue is that sketchArcs and sketchLines are different skitches and they are not syncronized ? I don't know, Any ideas ?
Labels (4)
4 REPLIES 4
Message 2 of 5
kandennti
in reply to: 100053800EC87E

Hi @100053800EC87E .

 

I'm not sure what you are trying to do.

For now, I created a test code like this, but I could not find anything wrong with addByThreePoints.

 

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

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

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

        # get points
        crv: adsk.fusion.SketchCurve = sel.entity
        pnts = getPoints(crv, 0.1)

        # lines
        createLines(pnts)

        # arcs
        createArcs(pnts)

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


def createArcs(
        pnts: list):

    app: adsk.core.Application = adsk.core.Application.get()
    des: adsk.fusion.Design = app.activeProduct
    root: adsk.fusion.Component = des.rootComponent

    skt: adsk.fusion.Sketch = root.sketches.add(root.xYConstructionPlane)
    skt.name = 'Arcs'

    sktPnts = createPoints(pnts, skt)

    startPoints = sktPnts[0::2]
    joiningPoints = [p.geometry for p in sktPnts[1::2]]
    endPoints = sktPnts[2::2]

    for p1, p2, p3 in zip(startPoints, joiningPoints, endPoints):
        skt.sketchCurves.sketchArcs.addByThreePoints(p1, p2, p3)


def createLines(
        pnts: list):

    app: adsk.core.Application = adsk.core.Application.get()
    des: adsk.fusion.Design = app.activeProduct
    root: adsk.fusion.Component = des.rootComponent

    skt: adsk.fusion.Sketch = root.sketches.add(root.xYConstructionPlane)
    skt.name = 'Lines'

    sktPnts = createPoints(pnts, skt)

    startPoints = sktPnts[0::2]
    endPoints = sktPnts[2::2]

    for p1, p2 in zip(startPoints, endPoints):
        skt.sketchCurves.sketchLines.addByTwoPoints(p1, p2)


def createPoints(
        pnts: list,
        skt: adsk.fusion.Sketch) -> list:

    sktPnts = [skt.sketchPoints.add(p) for p in pnts]

    return sktPnts


def getPoints(
        crv: adsk.fusion.SketchEntity,
        tolerance: float = 0.01) -> list:

    eva: adsk.core.CurveEvaluator3D = crv.worldGeometry.evaluator
    _, startParameter, endParameter = eva.getParameterExtents()
    _, vertexCoordinates = eva.getStrokes(startParameter, endParameter, tolerance)
    pnts = [v for v in vertexCoordinates]

    return pnts


def selectEnt(
        msg: str,
        filtterStr: str) -> adsk.core.Selection:

    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        sel = ui.selectEntity(msg, filtterStr)
        return sel
    except:
        return None
Message 3 of 5

I ran the script you provided but nothing happend ! 

What I wanted to do is to sketch one full path that consists of both lines and arcs.

For example Imagine I want to draw a staright line then connect to it an arc then the end point of the arc has another straight line. 

What I'm getting is that the second line is starting from the end of the first line and not the end of the arc.  Eventhough I'm using the command of endSketchPoint in order to keep the sketch as one full path and not segments. 

The following example shows only lines connected to each other Solved: Python script to create a chain of lines - Autodesk Community - Fusion 360

Message 4 of 5
kandennti
in reply to: 100053800EC87E

@100053800EC87E .

 

I'd love to help, but I can't reproduce the situation with only partial code.

Message 5 of 5
BrianEkins
in reply to: 100053800EC87E

Arcs behave differently than lines. Once an arc is created, it ALWAYS exists in a counterclockwise direction. This can mean that you can create the arc specifying the start and end points but when you query the existing arc, the start and end point may be different.

 

In the example below, I can create the arc by three points using points 1, 2, 3, or 3, 2, 1.  However, when I query the arc to get the start and end sketch points, the start point will be 1 and the end will be point 3 because it is counterclockwise.

ArcSample.png

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com

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