Divide Path into equal segments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
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
try:
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.')
return
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)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d3)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d4)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d5)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d6)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d7)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d8)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d9)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d10)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d11)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d12)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d13)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d14)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d15)
planes.add(planeInput)
planeInput.setByDistanceOnPath(selObj, d16)
planes.add(planeInput)
#planeInput.setByDistanceOnPath(selObj, d17)
#planes.add(planeInput)
app.activeViewport.refresh()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
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
