<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Script Noob: trying to automate split body in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-noob-trying-to-automate-split-body/m-p/10023651#M9628</link>
    <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I have a script where, as far as I can tell, I am able to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;enter the body length of the fish&lt;/P&gt;&lt;P&gt;enter the number of segments I want&lt;/P&gt;&lt;P&gt;select the main body and the starting face&amp;nbsp;&lt;/P&gt;&lt;P&gt;calculate the segment thickness&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The next steps I need to do and am having trouble figuring out are:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1: Creating offset planes from the starting face&lt;/P&gt;&lt;P&gt;2: Splitting the body using the offset planes&lt;/P&gt;&lt;P&gt;3: exporting masses of each segment&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a screenshot of my code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ScubaStephe_0-1611348886921.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/870530i148506D797C83202/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ScubaStephe_0-1611348886921.png" alt="ScubaStephe_0-1611348886921.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and the model I am trying to slice (the face I'm using to offset planes highlighted in blue):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ScubaStephe_1-1611348975233.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/870531i143DEC430832321A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ScubaStephe_1-1611348975233.png" alt="ScubaStephe_1-1611348975233.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a million,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stephen&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Jan 2021 21:00:02 GMT</pubDate>
    <dc:creator>StePhDen2020</dc:creator>
    <dc:date>2021-01-22T21:00:02Z</dc:date>
    <item>
      <title>Script Noob: trying to automate split body</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-noob-trying-to-automate-split-body/m-p/10023651#M9628</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I have a script where, as far as I can tell, I am able to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;enter the body length of the fish&lt;/P&gt;&lt;P&gt;enter the number of segments I want&lt;/P&gt;&lt;P&gt;select the main body and the starting face&amp;nbsp;&lt;/P&gt;&lt;P&gt;calculate the segment thickness&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The next steps I need to do and am having trouble figuring out are:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1: Creating offset planes from the starting face&lt;/P&gt;&lt;P&gt;2: Splitting the body using the offset planes&lt;/P&gt;&lt;P&gt;3: exporting masses of each segment&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a screenshot of my code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ScubaStephe_0-1611348886921.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/870530i148506D797C83202/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ScubaStephe_0-1611348886921.png" alt="ScubaStephe_0-1611348886921.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and the model I am trying to slice (the face I'm using to offset planes highlighted in blue):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ScubaStephe_1-1611348975233.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/870531i143DEC430832321A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ScubaStephe_1-1611348975233.png" alt="ScubaStephe_1-1611348975233.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a million,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stephen&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 21:00:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-noob-trying-to-automate-split-body/m-p/10023651#M9628</guid>
      <dc:creator>StePhDen2020</dc:creator>
      <dc:date>2021-01-22T21:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: Script Noob: trying to automate split body</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-noob-trying-to-automate-split-body/m-p/10024891#M9629</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4512982"&gt;@StePhDen2020&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have created a sample that creates multiple offset planes from a selected Construction Plane.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;#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
    ) -&amp;gt; adsk.core.Selection :

    try:
        sel = _ui.selectEntity(msg, filtterStr)
        return sel
    except:
        return None&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 23 Jan 2021 14:47:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-noob-trying-to-automate-split-body/m-p/10024891#M9629</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2021-01-23T14:47:34Z</dc:date>
    </item>
  </channel>
</rss>

