<?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: API for Component Save Copy As in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-component-save-copy-as/m-p/5697847#M21079</link>
    <description>&lt;P&gt;There is an API for Save As, although as I was testing it to respond to your question I found some issues.&amp;nbsp; Luckily there is also a workaround so you can use it now.&amp;nbsp; The code below uses the file that is currently open, has a .csv file selected, reads the data from the .csv file and uses it to update parameters in the open model.&amp;nbsp; It then saves the model using the name specified in the csv file and then does it all over again for the next row in the csv file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;import adsk.core, adsk.fusion, traceback
import os

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        # Have the table file selected.
        dialog = ui.createFileDialog()
        dialog.filter = 'Comma Separated Values (*.csv)'
        dialog.initialDirectory = os.path.dirname(os.path.realpath(__file__))
        if dialog.showOpen() != adsk.core.DialogResults.DialogOK:
            return
            
        filename = dialog.filename
        
        # The project and folder is hard coded.
        projectName = 'ParamBlockTest'
        folderName = 'Test7'
        
        proj = None
        for project in app.data.dataProjects:
            if project.name == projectName:
                proj = project
                break

        targetFolder = None            
        if proj:
            if folderName == '':
                targetFolder = project.rootFolder
            else:
                for folder in project.rootFolder.dataFolders:
                    if folder.name == folderName:
                        targetFolder = folder
                        break

            if not targetFolder:
                return
        else:
            return

        # Open the file.
        f = open(filename, 'r')

        # Read the first line, which is the header row.
        # This contains the names of the parameters that
        # will be edited.  The first column is the name
        # of that row and each additional column is a parameter.
        firstLine = f.readline()
        firstLine = firstLine.rstrip('\n')
        paramNames = firstLine.split(',')
        paramNames = paramNames[1:]
              
        # Iterate through the value lines.
        line = f.readline()
        while line:
            doc = app.activeDocument
            design = app.activeProduct
            params = design.allParameters        

            line = line.rstrip('\n')
            values = line.split(',')

            # Iterate through the values and change the corresponding parameter.            
            for i in range(1,len(values)):
                param = params.itemByName(paramNames[i-1])
                param.expression = values[i]

            # Save the file.
            adsk.doEvents()
            doc.saveAs(values[0], targetFolder, '', '')
            adsk.doEvents()
            
            line = f.readline()
        
        f.close()        

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the contents of my test csv file.&amp;nbsp; It's assumes that the first column is the name that will be used when doing the save as.&amp;nbsp; The next columns are the values for the parameters to change, with the first row being the names of the parameters.&amp;nbsp; In my case, there are three parameters; "Width", "Height", and "Length".&lt;/P&gt;
&lt;PRE&gt;Name,Width,Height,Length
Size1,1 in,1 in,0.25 in
Size2,1 in,1 in,0.5 in
Size3,1 in,1 in,1 in
Size4 ,1 in,1 in,2 in&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The workaround is the doEvents calls around the saveAs call.&amp;nbsp; They shouldn't be needed.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 29 Jun 2015 15:29:53 GMT</pubDate>
    <dc:creator>ekinsb</dc:creator>
    <dc:date>2015-06-29T15:29:53Z</dc:date>
    <item>
      <title>API for Component Save Copy As</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-component-save-copy-as/m-p/5694191#M21078</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Is there a API for Component "save copy as"?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Context:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;At the moment, I have a script that takes a CSV with User Parameters and generate a whole family of parts&amp;nbsp;and saved as .f3d files. These automatically generated&amp;nbsp;parts&amp;nbsp;are then uploaded (manually) back into Fusion360 as separate designs. Subsequent updates of these automated generated&amp;nbsp;parts are (manually since API is not yet available) uploaded into Fusion360&amp;nbsp;using the "Import New Version" functionality.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You might argue that my workflow is unnatural, however I have to do this becaue Fusion 360 does not allow to replace a component with another component at the moment, but only a different version of the component. I tried to get around the compoment replacement limitation while retaining the ability to&amp;nbsp;automatically generate component family by utilizing the "Import New Version" functionality.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now because of the "Clone" limitation as described in &lt;A target="_blank" href="https://forums.autodesk.com/t5/design-and-documentation/insert-into-current-desing-clone-error/m-p/5692863/highlight/true#M26528"&gt;http://forums.autodesk.com/t5/design-and-documentation/insert-into-current-desing-clone-error/m-p/5692863/highlight/true#M26528&lt;/A&gt; I am stuck. Fusion360 thinks the automatically generated parts are all clone of each other. As such I can't build anything&amp;nbsp;that use more than one of these generated parts; unfortunately this is a very common scenario for us. The work around is to use "Save Copy As" which I have verified that it works, but this is very time consuming to do manually for each iteration of automatically generated parts, and it pretty much breaks the workflow from a practical point of view.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What would be a suggested workaround the combination of inability to replace a component with another component, and the inability to import more than one clone into a design? Is there an API for Save Copy As?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Stephen&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2015 21:46:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-component-save-copy-as/m-p/5694191#M21078</guid>
      <dc:creator>schengnz</dc:creator>
      <dc:date>2015-06-25T21:46:34Z</dc:date>
    </item>
    <item>
      <title>Re: API for Component Save Copy As</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-component-save-copy-as/m-p/5697847#M21079</link>
      <description>&lt;P&gt;There is an API for Save As, although as I was testing it to respond to your question I found some issues.&amp;nbsp; Luckily there is also a workaround so you can use it now.&amp;nbsp; The code below uses the file that is currently open, has a .csv file selected, reads the data from the .csv file and uses it to update parameters in the open model.&amp;nbsp; It then saves the model using the name specified in the csv file and then does it all over again for the next row in the csv file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;import adsk.core, adsk.fusion, traceback
import os

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        # Have the table file selected.
        dialog = ui.createFileDialog()
        dialog.filter = 'Comma Separated Values (*.csv)'
        dialog.initialDirectory = os.path.dirname(os.path.realpath(__file__))
        if dialog.showOpen() != adsk.core.DialogResults.DialogOK:
            return
            
        filename = dialog.filename
        
        # The project and folder is hard coded.
        projectName = 'ParamBlockTest'
        folderName = 'Test7'
        
        proj = None
        for project in app.data.dataProjects:
            if project.name == projectName:
                proj = project
                break

        targetFolder = None            
        if proj:
            if folderName == '':
                targetFolder = project.rootFolder
            else:
                for folder in project.rootFolder.dataFolders:
                    if folder.name == folderName:
                        targetFolder = folder
                        break

            if not targetFolder:
                return
        else:
            return

        # Open the file.
        f = open(filename, 'r')

        # Read the first line, which is the header row.
        # This contains the names of the parameters that
        # will be edited.  The first column is the name
        # of that row and each additional column is a parameter.
        firstLine = f.readline()
        firstLine = firstLine.rstrip('\n')
        paramNames = firstLine.split(',')
        paramNames = paramNames[1:]
              
        # Iterate through the value lines.
        line = f.readline()
        while line:
            doc = app.activeDocument
            design = app.activeProduct
            params = design.allParameters        

            line = line.rstrip('\n')
            values = line.split(',')

            # Iterate through the values and change the corresponding parameter.            
            for i in range(1,len(values)):
                param = params.itemByName(paramNames[i-1])
                param.expression = values[i]

            # Save the file.
            adsk.doEvents()
            doc.saveAs(values[0], targetFolder, '', '')
            adsk.doEvents()
            
            line = f.readline()
        
        f.close()        

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the contents of my test csv file.&amp;nbsp; It's assumes that the first column is the name that will be used when doing the save as.&amp;nbsp; The next columns are the values for the parameters to change, with the first row being the names of the parameters.&amp;nbsp; In my case, there are three parameters; "Width", "Height", and "Length".&lt;/P&gt;
&lt;PRE&gt;Name,Width,Height,Length
Size1,1 in,1 in,0.25 in
Size2,1 in,1 in,0.5 in
Size3,1 in,1 in,1 in
Size4 ,1 in,1 in,2 in&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The workaround is the doEvents calls around the saveAs call.&amp;nbsp; They shouldn't be needed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2015 15:29:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-component-save-copy-as/m-p/5697847#M21079</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2015-06-29T15:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: API for Component Save Copy As</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-component-save-copy-as/m-p/5698330#M21080</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/116141"&gt;@ekinsb﻿&lt;/a&gt;&amp;nbsp;Thanks for such detail reply. One question: does your example achieve "Save As" or "Save a Copy As"? I need the saved copy to be no longer considered as a clone by Fusion360. Does your proposed solution achieve that? Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2015 19:39:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-component-save-copy-as/m-p/5698330#M21080</guid>
      <dc:creator>schengnz</dc:creator>
      <dc:date>2015-06-29T19:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: API for Component Save Copy As</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-component-save-copy-as/m-p/5699117#M21081</link>
      <description>&lt;P&gt;You're right, it's doing a Save As.&amp;nbsp; I glossed over that issue when I first read your initial question.&amp;nbsp; Unfortunately, the API doesn't currently support the Save Copy As functionality.&amp;nbsp; I've finished the API design and development team is starting to look at it but I don't know if we'll have time to make it into the next release.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2015 05:40:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-component-save-copy-as/m-p/5699117#M21081</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2015-06-30T05:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: API for Component Save Copy As</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-component-save-copy-as/m-p/5699186#M21082</link>
      <description>I really hope that either this or &lt;A href="http://forums.autodesk.com/t5/fusion-360-ideastation-request-a/breaking-parent-child-relation-in-situ-without-quot-saving-a/idi-p/5696986" target="_blank"&gt;http://forums.autodesk.com/t5/fusion-360-ideastation-request-a/breaking-parent-child-relation-in-situ-without-quot-saving-a/idi-p/5696986&lt;/A&gt; would make it to the next release. Having either one of them would (partially) solve a major short-coming of Fusion 360 which is stopping the creation of large assemblies using part families/interchangable parts. Of course if Fusion360 has proper Inventor iParts capability all these are moot.</description>
      <pubDate>Tue, 30 Jun 2015 07:05:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-component-save-copy-as/m-p/5699186#M21082</guid>
      <dc:creator>schengnz</dc:creator>
      <dc:date>2015-06-30T07:05:42Z</dc:date>
    </item>
  </channel>
</rss>

