Script Noob: trying to automate split body

Script Noob: trying to automate split body

StePhDen2020
Observer Observer
426 Views
1 Reply
Message 1 of 2

Script Noob: trying to automate split body

StePhDen2020
Observer
Observer

Hi All, 

 

I'm a long time Fusion 360 user wading into scripting for the first time. I study fish and need to slice up a model of a fish I built 100 times and export the relative masses of each segment (segment mass/total body mass). I need to do this for a total of nine fish and doing it by hand is really tedious.

 

So far I have a script where, as far as I can tell, I am able to:

 

enter the body length of the fish

enter the number of segments I want

select the main body and the starting face 

calculate the segment thickness

 

The next steps I need to do and am having trouble figuring out are:

 

1: Creating offset planes from the starting face

2: Splitting the body using the offset planes

3: exporting masses of each segment

 

I have experience coding in Python/MATLAB generally. But I do not know much about the Autodesk libraries or how to use them. I haven't found any good video tutorials that go beyond creating the first script. I know I'll need For Loops and things like that. I'm mainly having trouble figuring out how to create planes and things like that. I've been looking at some of the sample codes like bottle and pipe but they are of limited use. I don't necessarily need someone to write this for me, just point me toward some articles or templates that would help get me started.

 

Here is a screenshot of my code: 

ScubaStephe_0-1611348886921.png

and the model I am trying to slice (the face I'm using to offset planes highlighted in blue): 

ScubaStephe_1-1611348975233.png

 

Thanks a million,

 

Stephen

 

0 Likes
Accepted solutions (1)
427 Views
1 Reply
Reply (1)
Message 2 of 2

kandennti
Mentor
Mentor
Accepted solution

Hi @StePhDen2020 .

 

I have created a sample that creates multiple offset planes from a selected Construction Plane.

#Fusion360API Python script
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

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

        # selected plane
        basePlane :adsk.fusion.ConstructionPlane = sel.entity

        # get component
        comp :adsk.fusion.Component = basePlane.parent

        # get planes
        planes :adsk.fusion.ConstructionPlanes = comp.constructionPlanes

        # conditions
        step = 1 # unit Cm
        count = 10

        # create offset plane
        planeInput :adsk.fusion.ConstructionPlaneInput = planes.createInput()
        for idx in range(count):
            offsetValue = adsk.core.ValueInput.createByReal(idx * step)
            planeInput.setByOffset(basePlane, offsetValue)
            planes.add(planeInput)

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

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

    try:
        sel = _ui.selectEntity(msg, filtterStr)
        return sel
    except:
        return None
0 Likes