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

Is Point Along Path not available from the API?

reisyu
Participant Participant
1,272 Views
10 Replies
Message 1 of 11

Is Point Along Path not available from the API?

reisyu
Participant
Participant

I want to use Point Along Path with the Fusion360 API.

 

reisyu_0-1595749916671.png

I looked at the ConstructionPointInput Object page.

But I didn't see Point Along Path in the reference manual.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-b3ffae9a-d7d7-48ee-bd66-b1138536767f

Is Point Along Path not available from the API?

Reply
Reply
1 Like
Accepted solutions (2)
1,273 Views
10 Replies
Replies (10)
Message 2 of 11

MichaelT_123
Advisor
Advisor

Yes, it is, Mr Reisyu.

MichaelT
Reply
Reply
2 Likes
Message 3 of 11

kandennti
Mentor
Mentor
Accepted solution

"Application.executeTextCommand" can be used to create it to some extent. I've created a sample.

#Fusion360API python script
#Description-create PointAlongPath sample

import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        # new doc
        _app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des  :adsk.fusion.Design = _app.activeProduct
        des.designType = adsk.fusion.DesignTypes.ParametricDesignType
        root :adsk.fusion.Component = des.rootComponent

        # create sketch
        crv = initSktCircle(root)

        # create pipe
        initPointAlongPath(crv, 0.5)

        # create sketch
        crv = initSktSpline(root)

        # create pipe
        initPointAlongPath(crv, 0.3)

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

def initSktSpline(comp :adsk.fusion.Component):
    skt :adsk.fusion.Sketch = comp.sketches.add(comp.xYConstructionPlane)

    poss = [[-1,2,5], [2,1,0], [0,-4,2], [-2,5,-2]]

    pnt3D = adsk.core.Point3D
    objs = adsk.core.ObjectCollection.create()
    [objs.add(pnt3D.create(x,y,z)) for (x,y,z) in poss]
        
    crvs :adsk.fusion.SketchCurves = skt.sketchCurves
    crv = crvs.sketchFittedSplines.add(objs)

    return crv

def initSktCircle(comp :adsk.fusion.Component):
    skt :adsk.fusion.Sketch = comp.sketches.add(comp.xYConstructionPlane)

    pnt3D = adsk.core.Point3D
    crvs :adsk.fusion.SketchCurves = skt.sketchCurves
    crv = crvs.sketchCircles.addByCenterRadius(pnt3D.create(-5.0,-5,0), 4.0)

    return crv

def initPointAlongPath(path, ratio):

    txtCmds = [
        u'Commands.Start WorkPointAlongPathCommand', # show dialog
        u'Commands.SetDouble WORKGEOM_POP_ALONG {}'.format(ratio), # input distance
        u'NuCommands.CommitCmd' # execute command
    ]
    
    sels = _ui.activeSelections
    sels.clear()
    sels.add(path)

    for cmd in txtCmds:
        _app.executeTextCommand(cmd)

    sels.clear()


Here's how to use TextCommands and how to find the ID.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/use-textcommands/td-p/9645688 

 

後、ブログ紹介してくれてありがとう。

Reply
Reply
2 Likes
Message 4 of 11

MichaelT_123
Advisor
Advisor

Hi Kandennti-San,


... you work extremely hard on this forum! :)... so hard that others have become a little bit lazy.
Regarding the code... it is excellent, but there is a more straightforward way to perform the task. I am sure that you know it!

Do you give the chance to find the way by Mr. Reisyu himself? :).


Regards
MichaelT

MichaelT
Reply
Reply
1 Like
Message 5 of 11

kandennti
Mentor
Mentor

Thanks @MichaelT_123 .

 

I was dimly aware that some people were not happy with my methods.
I am grateful for this, as no one has ever come along to warn me as clearly as you have.
I will change my style in the future.

Reply
Reply
0 Likes
Message 6 of 11

reisyu
Participant
Participant

Thanks @MichaelT_123

I found the ConstructionPlaneInput.setByDistanceOnPath Method. I'm going to create a point of intersection between this plane and the path
http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-46dd5f0a-e384-4707-b431-37c0e596f328

Reply
Reply
1 Like
Message 7 of 11

reisyu
Participant
Participant

Thanks @kandennti 

I was surprised to see a solution like this.
Fusion360's APIs are very deep !!

Reply
Reply
0 Likes
Message 8 of 11

reisyu
Participant
Participant
Accepted solution

I created point along path in the following way.

Create a plane with ConstructionPlaneInput.setByDistanceOnPath Method.

Add a sketch to this plane.

Create the intersection of the sketch plane and the path using Sketch.intersectWithSketchPlane Method.

 

import adsk.core, adsk.fusion, traceback

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

        # Get the root component of the active design.
        rootComp = design.rootComponent

        # Get the crvPath.
        sketch1 = rootComp.sketches.item(0)
        crvPath = sketch1.sketchCurves.sketchFittedSplines.item(0)

        # Get construction planes
        planes = rootComp.constructionPlanes
        
        # Create construction plane input
        planeInput = planes.createInput()

        # Add construction plane by distance on path
        distance = adsk.core.ValueInput.createByReal(0.5)
        planeInput.setByDistanceOnPath(crvPath, distance)
        plane = planes.add(planeInput)

        # Add NewSketch
        sketch2 = rootComp.sketches.add(plane)

        # intersect With Sketch Plane
        entities = []
        entities.append(crvPath)
        skPoints = sketch2.intersectWithSketchPlane(entities)
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

reisyu_0-1596288892363.png

 

Reply
Reply
1 Like
Message 9 of 11

MichaelT_123
Advisor
Advisor

Hi Mr. Reisyu,

 

... the code is much simpler  than the original proposal.

It can be simplified even more, and even, it will be likely faster by avoiding:

sketch2.intersectWithSketchPlane(entities) 

 

Just use: 

point3D = constructionPlane.geometry.origin

 

Regards

MichaelT

 

MichaelT
Reply
Reply
1 Like
Message 10 of 11

reisyu
Participant
Participant

Hi @MichaelT_123 
Thanks for the very good advice!
Combined with sketchPoints.add(poind3D), it's a very simple way to do it!

reisyu_0-1596554522601.png

 

Reply
Reply
0 Likes
Message 11 of 11

marekveg
Explorer
Explorer

To be fair, point along path is not really available in API. There is a substitute approach where you can use plane along the path and then use sketches to do points on it, but this just adds another layer of complexity and I'm actually bit surprised they have decided not to make it into the API.

 

And yes it is possible to place points on the path using setByPoint, but this requires the whole design to be direct design. Very unfortunate, as I actually would like to keep it parametric. So creating planes and sketches to get points it is. Or using the approach to run text commands, but that would require looking up created points in the app, so that's also cumbersome :/.

Reply
Reply
1 Like