<?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 Re: Script to create Cam setups in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7957870#M16164</link>
    <description>&lt;P&gt;Ah...&amp;nbsp; I have it now.&lt;/P&gt;&lt;P&gt;&lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://forums.autodesk.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;P&gt;Create all the setups, then run the script once, and it updates the names of the set up based on the body or component that is in the "model"&lt;/P&gt;&lt;P&gt;If there is nothing in the model... the name does not change.&lt;/P&gt;&lt;P&gt;If there is more than one component inthe model, it seems to use the first one selected as the name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is great, probably easier to use than my suggested method.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much.&lt;/P&gt;</description>
    <pubDate>Wed, 25 Apr 2018 09:14:27 GMT</pubDate>
    <dc:creator>JYZMT</dc:creator>
    <dc:date>2018-04-25T09:14:27Z</dc:date>
    <item>
      <title>Script to create Cam setups</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7956880#M16161</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently I'm having to&amp;nbsp;create&amp;nbsp;a lot of Cam setups manually for each component in my assembly.&amp;nbsp;The worst part of this for me is naming the set ups correctly, because I want the set-up to be named specifically as the component name. I've meticulously named the components in the model space. Is it possible to write a script/add that pulls the name of the part into the name of the setup?&amp;nbsp;Its not a problem to confirm the other options in setup dialogue box, because I need to align the orientation axis manually anyway, but to have&amp;nbsp;the name fill out automatically would be so helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was hoping either&amp;nbsp;I select the component, then run the add in, or I click an add in button and then click on a component? Or is there a better way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this possible, and where do I start?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Interestingly, I've noticed that when you start a set up manually, you can right click on the list of components, and add it to the "model", and also the x axix and the y axis etc, but I can't find a way to name it in the same method, so I thought maybe a script could do it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll also put a right click "add name to set up" request on the ideas stations, but its not exactly the most exciting of requests, so likely will get few votes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks everyone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 21:19:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7956880#M16161</guid>
      <dc:creator>JYZMT</dc:creator>
      <dc:date>2018-04-24T21:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create Cam setups</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7957132#M16162</link>
      <description>&lt;P&gt;I can't guarantee that this will work in all cases but it seems to work correctly in my test.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's a Python script.&amp;nbsp; The easiest way to use it is to use the "Scripts and Add-Ins" command and create a new Python script named whatever you want.&amp;nbsp; Then select it from the list and choose the "Edit" button.&amp;nbsp; In the Python editor, replace all of the code with the code below and save it.&amp;nbsp; Now you can run it by running the "Scripts and Add-Ins" command, choose the script, and click the "Run" button.&amp;nbsp; It expects the CAM workspace to be active.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        # Make sure CAM is active.
        if not type(app.activeProduct) is adsk.cam.CAM:
            ui.messageBox('The CAM workspace must be active.')

        cam = adsk.cam.CAM.cast(app.activeProduct)
        des = adsk.fusion.Design.cast(app.activeDocument.products.itemByProductType("DesignProductType"))

        # Iterate through the setups.
        setup = adsk.cam.Setup.cast(None)
        for setup in cam.setups:
            # Get the first element that the setup references.
            model = setup.models.item(0)
            
            if type(model) is adsk.fusion.BRepBody:
                body = adsk.fusion.BRepBody.cast(model)

                # Get the parent component this body is in.
                parentComp = body.parentComponent
                if parentComp != des.rootComponent:
                    setup.name = parentComp.name                
            elif type(model) is adsk.fusion.Occurrence:
                occ = adsk.fusion.Occurrence.cast(model)
                setup.name = occ.component.name
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Apr 2018 00:22:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7957132#M16162</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2018-04-25T00:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create Cam setups</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7957727#M16163</link>
      <description>&lt;P&gt;Thanks so much for taking the time to help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately I can't get this to do anything. Although this is most likely due to user error. I have followed your steps,&amp;nbsp;created a python script, replaced the code, saved it. But when I run it, nothing happens. But there is no "failed:" alert either.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried running it outside the CAM space, and it does bring up the alert "the CAM space must be active" as expected so something is happening.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the CAM space however, nothing happens? I've tried pre selecting a component and running the script, pre selecting a body and running the script, running the script and clicking on the&amp;nbsp; browser, and on the model ??? nothing happens - no error alert either of failed: alert.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my guess is I'm not using it as you intended? Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 08:20:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7957727#M16163</guid>
      <dc:creator>JYZMT</dc:creator>
      <dc:date>2018-04-25T08:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create Cam setups</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7957870#M16164</link>
      <description>&lt;P&gt;Ah...&amp;nbsp; I have it now.&lt;/P&gt;&lt;P&gt;&lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://forums.autodesk.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;P&gt;Create all the setups, then run the script once, and it updates the names of the set up based on the body or component that is in the "model"&lt;/P&gt;&lt;P&gt;If there is nothing in the model... the name does not change.&lt;/P&gt;&lt;P&gt;If there is more than one component inthe model, it seems to use the first one selected as the name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is great, probably easier to use than my suggested method.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 09:14:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7957870#M16164</guid>
      <dc:creator>JYZMT</dc:creator>
      <dc:date>2018-04-25T09:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create Cam setups</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7957963#M16165</link>
      <description>&lt;P&gt;Ah, this is awesome. Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next problem....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On this basis, it looks to me like the api can run iteratively through names, and grab text strings? So I hoping the following might also be possible, based on this script as a starting point?:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- iteratively run through the names of the parts in the model space, and re-name them based on a&amp;nbsp;&lt;EM&gt;CONCATENATE&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;(this is what it would be in excel anyway), combining&amp;nbsp;the part number and the material name.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;my beginner thoughts below your code (you will quickly see coding is new to me, but I'm keen to learn)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import adsk.core, adsk.fusion, adsk.cam, traceback&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;- adsk.cam changed to model space? adsk.model ??? whats the handle here?&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface&lt;/PRE&gt;&lt;P&gt;- no changes here?&lt;/P&gt;&lt;PRE&gt;# Make sure CAM is active.
        if not type(app.activeProduct) is adsk.cam.CAM:
            ui.messageBox('The CAM workspace must be active.')&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;- the CAM has to change to Model space, so its whatever the adsk.model.MODEL handle is?&lt;/P&gt;&lt;PRE&gt;cam = adsk.cam.CAM.cast(app.activeProduct)
        des = adsk.fusion.Design.cast(app.activeDocument.products.itemByProductType("DesignProductType"))&lt;/PRE&gt;&lt;P&gt;- again the cam bit changed to the model handle.&lt;/P&gt;&lt;P&gt;- not sure what the des bit is ??&lt;/P&gt;&lt;PRE&gt;# Iterate through the setups.
        setup = adsk.cam.Setup.cast(None)
        for setup in cam.setups:
            # Get the first element that the setup references.
            model = setup.models.item(0)&lt;/PRE&gt;&lt;P&gt;name = adsk.model.name.item.cast(none)&lt;/P&gt;&lt;P&gt;??? nope I'm lost!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if type(model) is adsk.fusion.BRepBody:
                body = adsk.fusion.BRepBody.cast(model)

                # Get the parent component this body is in.
                parentComp = body.parentComponent
                if parentComp != des.rootComponent:
                    setup.name = parentComp.name                
            elif type(model) is adsk.fusion.Occurrence:
                occ = adsk.fusion.Occurrence.cast(model)
                setup.name = occ.component.name&lt;/PRE&gt;&lt;P&gt;I can read what your code is doing I think, i.e. getting the component name, or if a body get the the parent component name.&amp;nbsp; But I'm lost transferring it across to the new script. Its needs to be:&lt;/P&gt;&lt;P&gt;new name = get part number, get material name and combine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;&lt;P&gt;And this bit seems to be in all the script samples, so I guess its needed at the end.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, miles off as you can see. needless to say it does not work when I try it! But at least I'm trying - I'll get there. Any tips?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 09:53:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7957963#M16165</guid>
      <dc:creator>JYZMT</dc:creator>
      <dc:date>2018-04-25T09:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create Cam setups</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7959208#M16166</link>
      <description>&lt;P&gt;I think the best tip that I can give you that will hopefully help you with any project you might want to do in the future is to point you to the existing documentation.&amp;nbsp; This describes and points you to the various pieces of the documentation and provides some links to additional resources.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-A92A4B10-3781-4925-94C6-47DA85A4F65A" target="_blank"&gt;http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-A92A4B10-3781-4925-94C6-47DA85A4F65A&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you get stuck, the forum here is always a good place to ask questions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 16:40:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7959208#M16166</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2018-04-25T16:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create Cam setups</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7959234#M16167</link>
      <description>&lt;P&gt;Thanks, I'll start the journey!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 16:51:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-create-cam-setups/m-p/7959234#M16167</guid>
      <dc:creator>JYZMT</dc:creator>
      <dc:date>2018-04-25T16:51:48Z</dc:date>
    </item>
  </channel>
</rss>

