<?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 Rename component via API in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/rename-component-via-api/m-p/8971842#M13752</link>
    <description>&lt;P&gt;Hi there, I am trying to rename components via the API. this is what I tried but it doesn't seem to work. making a new file with two components&amp;nbsp; and running the below code gives me this output. any help would be appreciated:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;found component Component1:1&lt;BR /&gt;tried to rename to Comp1&lt;BR /&gt;but it is Component1:1&lt;BR /&gt;found component Component2:1&lt;BR /&gt;tried to rename to Comp2&lt;BR /&gt;but it is Component2:1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;components = adsk.fusion.Design.cast(app.activeProduct).rootComponent.allOccurrences&lt;/P&gt;&lt;P&gt;indx = 1&lt;/P&gt;&lt;P&gt;for c in components:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;cname = c.name&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;newName = "Comp{}".format(indx)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;c.name = newName&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;indx+=1&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;print("found component {} \ntried to rename to {} \nbut it is {}".format(cname,newName,c.name))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 17 Aug 2019 22:59:19 GMT</pubDate>
    <dc:creator>rbackman07</dc:creator>
    <dc:date>2019-08-17T22:59:19Z</dc:date>
    <item>
      <title>Rename component via API</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/rename-component-via-api/m-p/8971842#M13752</link>
      <description>&lt;P&gt;Hi there, I am trying to rename components via the API. this is what I tried but it doesn't seem to work. making a new file with two components&amp;nbsp; and running the below code gives me this output. any help would be appreciated:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;found component Component1:1&lt;BR /&gt;tried to rename to Comp1&lt;BR /&gt;but it is Component1:1&lt;BR /&gt;found component Component2:1&lt;BR /&gt;tried to rename to Comp2&lt;BR /&gt;but it is Component2:1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;components = adsk.fusion.Design.cast(app.activeProduct).rootComponent.allOccurrences&lt;/P&gt;&lt;P&gt;indx = 1&lt;/P&gt;&lt;P&gt;for c in components:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;cname = c.name&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;newName = "Comp{}".format(indx)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;c.name = newName&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;indx+=1&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;print("found component {} \ntried to rename to {} \nbut it is {}".format(cname,newName,c.name))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 22:59:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/rename-component-via-api/m-p/8971842#M13752</guid>
      <dc:creator>rbackman07</dc:creator>
      <dc:date>2019-08-17T22:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: Rename component via API</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/rename-component-via-api/m-p/8971878#M13753</link>
      <description>&lt;P&gt;The problem is that you're getting occurrences and trying to set the name of each occurrence.&amp;nbsp; The name property of the Occurrence object is read-only because the occurrence inherits its name from the component it references.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are a couple of alternatives in your case.&amp;nbsp; You can use the Design.allComponents property to get components instead of occurrences or you can use the component property of the Occurrence object to get the associated component and then change its name.&amp;nbsp; Just remember that if you have multiple occurrences of the same component, the last one will win since you're just continually changing the name of the same component.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To better understand the difference between occurrences and components take a look at the &lt;A href="http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A" target="_blank" rel="noopener"&gt;help document&lt;/A&gt; this discusses assembly structure.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2019 00:02:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/rename-component-via-api/m-p/8971878#M13753</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2019-08-18T00:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Rename component via API</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/rename-component-via-api/m-p/8972555#M13754</link>
      <description>&lt;P&gt;Thanks for the quick feedback Brian and thanks for the learning resource!&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2019 20:30:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/rename-component-via-api/m-p/8972555#M13754</guid>
      <dc:creator>rbackman07</dc:creator>
      <dc:date>2019-08-18T20:30:30Z</dc:date>
    </item>
  </channel>
</rss>

