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: 

Is Point Along Path not available from the API?

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
reisyu
620 Views, 9 Replies

Is Point Along Path not available from the API?

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?

Tags (1)
9 REPLIES 9
Message 2 of 10
MichaelT_123
in reply to: reisyu

Yes, it is, Mr Reisyu.

MichaelT
Message 3 of 10
kandennti
in reply to: reisyu

"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 

 

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

Message 4 of 10
MichaelT_123
in reply to: kandennti

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
Message 5 of 10
kandennti
in reply to: MichaelT_123

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.

Message 6 of 10
reisyu
in reply to: MichaelT_123

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

Message 7 of 10
reisyu
in reply to: kandennti

Thanks @kandennti 

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

Message 8 of 10
reisyu
in reply to: MichaelT_123

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

 

Message 9 of 10
MichaelT_123
in reply to: reisyu

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
Message 10 of 10
reisyu
in reply to: MichaelT_123

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

 

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