<?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: edit model parameter of imported file in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/edit-model-parameter-of-imported-file/m-p/11290716#M5793</link>
    <description>&lt;P&gt;The importToTarget2 method returns an ObjectCollection of Occurrence objects.&amp;nbsp; Here's a small sample I used to test the process. I have a local file that contains model parameters named "Length", "Width", and "Height". This imports the f3d into the currently active design and then changes the parameters associated with the imported occurrences.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def ImportTest():
    try:
        des: adsk.fusion.Design = app.activeProduct
        root = des.rootComponent
        
        impMgr = app.importManager
        f3dImpOpt = impMgr.createFusionArchiveImportOptions('C:\Temp\ImportParamTest.f3d')
        results: adsk.core.ObjectCollection
        results = impMgr.importToTarget2(f3dImpOpt, root)

        occ: adsk.fusion.Occurrence = results[0]
        comp = occ.component

        param: adsk.fusion.ModelParameter
        for param in comp.modelParameters:
            app.log(f'{param.name}, {param.expression}')
            if param.name.startswith('Length'):
                param.value = 10
            elif param.name.startswith('Width'):
                param.value = 6
            elif param.name.startswith('Height'):
                param.value = 1
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 11 Jul 2022 22:41:04 GMT</pubDate>
    <dc:creator>BrianEkins</dc:creator>
    <dc:date>2022-07-11T22:41:04Z</dc:date>
    <item>
      <title>edit model parameter of imported file</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/edit-model-parameter-of-imported-file/m-p/11276220#M5790</link>
      <description>&lt;P&gt;Just as the title says, Trying to edit the&amp;nbsp;parameter of imported file.&lt;/P&gt;&lt;P&gt;My code seems to work, But if the Model&amp;nbsp;parameter name is already being used it will crash my program&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;	Ptr&amp;lt;FileDialog&amp;gt; fileDialog = ui-&amp;gt;createFileDialog();
	if (!fileDialog)
		return false;

	fileDialog-&amp;gt;filter("fusion File (*.f3d);;All files (*.*)");
	if (fileDialog-&amp;gt;showOpen() == adsk::core::DialogResults::DialogOK)
	{
		std::string filename = fileDialog-&amp;gt;filename();

		Ptr&amp;lt;Component&amp;gt; rootComp = des-&amp;gt;rootComponent();
		if (!rootComp)
			return false;
		
		Ptr&amp;lt;FusionArchiveImportOptions&amp;gt; archive_options = im-&amp;gt;createFusionArchiveImportOptions(filename);
		if (!archive_options)
			return false;

		im-&amp;gt;importToTarget(archive_options, rootComp);

		size_t importOccurenceCount = rootComp-&amp;gt;occurrences()-&amp;gt;count();
		Ptr&amp;lt;Occurrence&amp;gt; importOccurence = rootComp-&amp;gt;occurrences()-&amp;gt;item(importOccurenceCount - 1);
		if (!importOccurence)
			return false;

		Ptr&amp;lt;ModelParameters&amp;gt; modelParameters = importOccurence-&amp;gt;component()-&amp;gt;modelParameters();
		if (!modelParameters)
			return false;

		std::string name = "test_" + std::to_string(importOccurenceCount - 1);
		if((importOccurenceCount-1) &amp;gt; 0)
			modelParameters-&amp;gt;itemByName(name)-&amp;gt;value(11);
		else
			modelParameters-&amp;gt;itemByName("test")-&amp;gt;value(11);
	}
	else
		ui-&amp;gt;messageBox("Canceled file dialog.");&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 04 Jul 2022 15:59:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/edit-model-parameter-of-imported-file/m-p/11276220#M5790</guid>
      <dc:creator>nClarke0101</dc:creator>
      <dc:date>2022-07-04T15:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: edit model parameter of imported file</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/edit-model-parameter-of-imported-file/m-p/11279154#M5791</link>
      <description>&lt;P&gt;I think the problem is with your logic in determining the name of the parameter. If the ModelParameters.itemByName method fails, it returns null, which will cause the value function to fail. I'm fairly certain that's what is happening.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Even though model parameters are owned by a specific component, their names must be unique with respect to the design. When you import an f3d, Fusion will create unique parameter names to guarantee they are unique. I don't know what the design looks like that you're importing so it's difficult to give specific advice about how to possibly determine the correct name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I would recommend using the importToTarget2 method, which returns the occurrences that were created by the import. You can then search those components for the parameters you're looking for.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 22:15:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/edit-model-parameter-of-imported-file/m-p/11279154#M5791</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2022-07-05T22:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: edit model parameter of imported file</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/edit-model-parameter-of-imported-file/m-p/11280199#M5792</link>
      <description>&lt;P&gt;I need a little help with&amp;nbsp;&lt;SPAN&gt;importToTarget2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;it returns the&amp;nbsp;ObjectCollection but how do i get the&amp;nbsp;Parameters from that?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 11:05:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/edit-model-parameter-of-imported-file/m-p/11280199#M5792</guid>
      <dc:creator>nClarke0101</dc:creator>
      <dc:date>2022-07-06T11:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: edit model parameter of imported file</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/edit-model-parameter-of-imported-file/m-p/11290716#M5793</link>
      <description>&lt;P&gt;The importToTarget2 method returns an ObjectCollection of Occurrence objects.&amp;nbsp; Here's a small sample I used to test the process. I have a local file that contains model parameters named "Length", "Width", and "Height". This imports the f3d into the currently active design and then changes the parameters associated with the imported occurrences.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def ImportTest():
    try:
        des: adsk.fusion.Design = app.activeProduct
        root = des.rootComponent
        
        impMgr = app.importManager
        f3dImpOpt = impMgr.createFusionArchiveImportOptions('C:\Temp\ImportParamTest.f3d')
        results: adsk.core.ObjectCollection
        results = impMgr.importToTarget2(f3dImpOpt, root)

        occ: adsk.fusion.Occurrence = results[0]
        comp = occ.component

        param: adsk.fusion.ModelParameter
        for param in comp.modelParameters:
            app.log(f'{param.name}, {param.expression}')
            if param.name.startswith('Length'):
                param.value = 10
            elif param.name.startswith('Width'):
                param.value = 6
            elif param.name.startswith('Height'):
                param.value = 1
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 11 Jul 2022 22:41:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/edit-model-parameter-of-imported-file/m-p/11290716#M5793</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2022-07-11T22:41:04Z</dc:date>
    </item>
  </channel>
</rss>

