3 Posts

Divide Path into equal segments

82 Views, 2 Replies
12-15-2016 02:19 PM



I'm just starting off in Fusion, although experienced in solidworks/2d CAD. Enjoying the transition, great tool and a great price!


I am a complete novice a programming and trying to write a script in python to divide a path (not a single line) in equal sections. My workflow is to use the plane on path, followed by intersect tool in the sketch project/include and lastly points at each intersection.


My main focus is the plane on path bit. Ideally I would a requester box with select path and no division, but I think that is a bit beyond me at the moment!


Below is as far as I have managed to get, and it works up to a point!




#Author-Geoff Packer 
#Description-Select a path and divide using planes

import adsk.core, adsk.fusion, traceback
def run(context):
    ui = None
        app = adsk.core.Application.get()
        ui  = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        if not design:
            ui.messageBox('It is not supported in current workspace, please change to MODEL workspace and try again.')
        sel = ui.selectEntity('Select a path to divide', 'SketchCurves')
        selObj = sel.entity
        comp = design.rootComponent
        # create path
        feats = comp.features
        chainedOption = adsk.fusion.ChainedCurveOptions.connectedChainedCurves
        if adsk.fusion.BRepEdge.cast(selObj):
            chainedOption = adsk.fusion.ChainedCurveOptions.tangentChainedCurves
        path = adsk.fusion.Path.create(selObj, chainedOption)
        path = feats.createPath(selObj)
        # Get the root component of the active design
        rootComp = design.rootComponent
        # Get construction planes
        planes = rootComp.constructionPlanes
        # Create construction plane input
        planeInput = planes.createInput()
        # Add construction plane by distance on path
        No_of_Div = 17-1
        d2 = adsk.core.ValueInput.createByReal(1 / No_of_Div)
        d3 = adsk.core.ValueInput.createByReal( 2 * (1 / No_of_Div))
        d4 = adsk.core.ValueInput.createByReal( 3 * (1 / No_of_Div))        
        d5 = adsk.core.ValueInput.createByReal( 4 * (1 / No_of_Div))        
        d6 = adsk.core.ValueInput.createByReal( 5 * (1 / No_of_Div))
        d7 = adsk.core.ValueInput.createByReal( 6 * (1 / No_of_Div))
        d8 = adsk.core.ValueInput.createByReal( 7 * (1 / No_of_Div))
        d9 = adsk.core.ValueInput.createByReal( 8 * (1 / No_of_Div))
        d10 = adsk.core.ValueInput.createByReal( 9 * (1 / No_of_Div))
        d11 = adsk.core.ValueInput.createByReal( 10 * (1 / No_of_Div))
        d12 = adsk.core.ValueInput.createByReal( 11 * (1 / No_of_Div))
        d13 = adsk.core.ValueInput.createByReal( 12 * (1 / No_of_Div)) 
        d14 = adsk.core.ValueInput.createByReal( 13 * (1 / No_of_Div)) 
        d15 = adsk.core.ValueInput.createByReal( 14 * (1 / No_of_Div)) 
        d16 = adsk.core.ValueInput.createByReal( 15 * (1 / No_of_Div)) 
        #d17 = adsk.core.ValueInput.createByReal( 16 * (1 / No_of_Div)) 
        #d18 = adsk.core.ValueInput.createByReal( 17 * (1 / No_of_Div)) 
        #d19 = adsk.core.ValueInput.createByReal( 18 * (1 / No_of_Div))
        #d20 = adsk.core.ValueInput.createByReal( 19 * (1 / No_of_Div)) 
        #d21 = adsk.core.ValueInput.createByReal( 20 * (1 / No_of_Div)) 
        #d22 = adsk.core.ValueInput.createByReal( 21 * (1 / No_of_Div)) 
        #d23 = adsk.core.ValueInput.createByReal( 22 * (1 / No_of_Div))          
        planeInput.setByDistanceOnPath(selObj, d2)
        planeInput.setByDistanceOnPath(selObj, d3)
        planeInput.setByDistanceOnPath(selObj, d4)
        planeInput.setByDistanceOnPath(selObj, d5)
        planeInput.setByDistanceOnPath(selObj, d6)
        planeInput.setByDistanceOnPath(selObj, d7)
        planeInput.setByDistanceOnPath(selObj, d8)
        planeInput.setByDistanceOnPath(selObj, d9)
        planeInput.setByDistanceOnPath(selObj, d10)
        planeInput.setByDistanceOnPath(selObj, d11)
        planeInput.setByDistanceOnPath(selObj, d12)
        planeInput.setByDistanceOnPath(selObj, d13)
        planeInput.setByDistanceOnPath(selObj, d14)
        planeInput.setByDistanceOnPath(selObj, d15)
        planeInput.setByDistanceOnPath(selObj, d16)
        #planeInput.setByDistanceOnPath(selObj, d17)

        if ui:


Except I can only select a single line and not a path of multiple curves.


I have variable called path, which I have tried using in the lines like this: 

planeInput.setByDistanceOnPath(path, d2)

But I get errors

I have created this by copying and pasting and a little of my own work. I realise that the code is a bit crude, but we all have to start somewhere!

Can anyone advise how to select a joined curve like the plane on path command?


Thanks Geoff


Autodesk Support
1184 Posts
331 Kudos
353 Solutions

Re: Divide Path into equal segments

12-15-2016 07:00 PM in reply to: GeoffPacker7777

You should be able to create and use a Path to create a distance on path type of construction plane.  However, I just tried it and it's not working with a path.  I've logged a defect and we'll work on getting it fixed.  Here's my simplified script that I used to test with and that I would expect to work once we make the fix.


def planesAlongPath():
    ui = None
        app = adsk.core.Application.get()
        ui  = app.userInterface
        curve = ui.selectEntity('Select curve on path', 'SketchCurves').entity
        if curve:
            path = adsk.fusion.Path.create(curve, adsk.fusion.ChainedCurveOptions.connectedChainedCurves)
            des = adsk.fusion.Design.cast(app.activeProduct)
            root = des.rootComponent            
            numPlanes = 10
            for i in range(numPlanes):
                planeInput = root.constructionPlanes.createInput()
                planeInput.setByDistanceOnPath(path, adsk.core.ValueInput.createByReal(i/(numPlanes-1)))
                plane = root.constructionPlanes.add(planeInput)          
        if ui:

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
3 Posts

Re: Divide Path into equal segments

12-16-2016 05:30 AM in reply to: ekinsb

Thanks Brian for the really speedy response


I thought the range function was the way to go but was concentrating on the selecting part to start with.


I'll have to keep doing this manually for now!


How will I know when the defect is fixed?