<?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: Copy component originating within a referenced component? in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/copy-component-originating-within-a-referenced-component/m-p/7408559#M17539</link>
    <description>&lt;P&gt;Thanks; I'm successfully using &lt;FONT face="courier new,courier"&gt;localOcc = dst.occurrences.addByInsert(src.component.parentDesign.parentDocument.dataFile, foo, False)&lt;/FONT&gt; to create a temporary local&amp;nbsp;copy of the referenced component.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, because this copies the whole referenced component and not just the subcomponent I'm interested in (&lt;FONT face="courier new,courier"&gt;src.component&lt;/FONT&gt;), I now need to locate the component equivalent to&amp;nbsp;&lt;FONT face="courier new,courier"&gt;src.component&lt;/FONT&gt;&amp;nbsp;that's within &lt;FONT face="courier new,courier"&gt;localOcc&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Doing some kind of recursive iteration though &lt;FONT face="courier new,courier"&gt;localOcc.childOccurrences&lt;/FONT&gt;&amp;nbsp;and looking for something with a matching name seems inefficient and error-prone (as I understand it, the local equivalent I'm searching for may have been automatically renamed if the current document already contained a component of the same name). I suppose calculating a &lt;FONT face="courier new,courier"&gt;src.component.parentDesign.rootComponent.occurrences[x].childOccurrences[y].childOccurrences[z].…&lt;/FONT&gt; path back to &lt;FONT face="courier new,courier"&gt;src&lt;/FONT&gt;, and substituting into &lt;FONT face="courier new,courier"&gt;localOcc.childOccurrences[x].childOccurrences[y].…&lt;/FONT&gt; seems like it might work, if the ordering is consistent between the referenced component and the local copy, but I'm not sure if that's necessarily the case (also, this method seems inefficient, painfully so&amp;nbsp;if &lt;FONT face="courier new,courier"&gt;src&lt;/FONT&gt; was provided with NativeObjects such that &lt;FONT face="courier new,courier"&gt;src.assemblyContext.assemblyContext.…&lt;/FONT&gt; does not trace back up to its root).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Will the ordering of occurrences/childOccurrences be consistent between a referenced component and a local copy of that component? Or, better yet, am I missing an efficient solution here to finding a subcomponent of &lt;FONT face="courier new,courier"&gt;localOcc&lt;/FONT&gt; that is equivalent to &lt;FONT face="courier new,courier"&gt;src.component&lt;/FONT&gt;?&lt;/P&gt;</description>
    <pubDate>Tue, 26 Sep 2017 07:13:58 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-09-26T07:13:58Z</dc:date>
    <item>
      <title>Copy component originating within a referenced component?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/copy-component-originating-within-a-referenced-component/m-p/7408153#M17537</link>
      <description>&lt;P&gt;I'm trying to use Occurrences.addExistingComponent to copy a subcomponent of a referenced component into a (non-referenced) subcomponent of the current design. However, it appears that this operation is unsupported. What I'm doing appears to work fine when no referenced components are involved, or if the copy source&amp;nbsp;is itself a referenced component; but when the copy source is a subcomponent of a referenced component, I get a "RuntimeError: 3 : add operation failed".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trying to achieve the same thing by copying and pasting from the UI doesn't appear to work either, so this may not strictly be an API issue.&lt;BR /&gt;&lt;BR /&gt;(Relatedly, I'm finding that BRepBody.copyToComponent fails to copy bodies from within referenced components. This doesn't work in the UI either, as described in &lt;A href="https://forums.autodesk.com/t5/fusion-360-design-validate/copy-paste-body-from-linked-component/m-p/7176391" target="_blank"&gt;https://forums.autodesk.com/t5/fusion-360-design-validate/copy-paste-body-from-linked-component/m-p/7176391&lt;/A&gt;)&lt;BR /&gt;&lt;BR /&gt;Is there some sort of API call I'm missing that I can use to "localize" an external subcomponent to the current design? Or any other method/workaround for creating a local copy of an external subcomponent?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Tack-on tanget: I wanted to provide a script that demonstrated this issue, but I couldn't find API calls that would let me set up a referenced component between two Documents. If someone could point me in the right direction there, I'd be happy to add a demo&amp;nbsp;script.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 02:31:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/copy-component-originating-within-a-referenced-component/m-p/7408153#M17537</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-09-26T02:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: Copy component originating within a referenced component?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/copy-component-originating-within-a-referenced-component/m-p/7408233#M17538</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can create a local copy of referenced component by Occurrence.breakLink() API and then copy the sub component of copied component to sub component of current design. If you want to keep referenced component unchanged, you can create a new local occurrence of the referenced component and do copy operation and then delete the new local occurrence after copy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The codes as below demo how to create a new local occurrence of referenced component. I am assuming there is only one referenced document in current design.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;import adsk.core, adsk.fusion, traceback

def run(context):
  ui = None
  try:
    app = adsk.core.Application.get()
    ui  = app.userInterface
    des = adsk.fusion.Design.cast(app.activeProduct)
    root = des.rootComponent
    
    sourceFile = app.activeDocument.documentReferences.item(0).dataFile  
    root.occurrences.addByInsert(sourceFile, adsk.core.Matrix3D.create(), False)

  except:
    if ui:
      ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;
&lt;P&gt;BTW: we have a new api to get document reference from an occurrence. Unfortunately it wasn't implemented yet. It would be available in future versions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Marshal&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 03:31:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/copy-component-originating-within-a-referenced-component/m-p/7408233#M17538</guid>
      <dc:creator>marshaltu</dc:creator>
      <dc:date>2017-09-26T03:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Copy component originating within a referenced component?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/copy-component-originating-within-a-referenced-component/m-p/7408559#M17539</link>
      <description>&lt;P&gt;Thanks; I'm successfully using &lt;FONT face="courier new,courier"&gt;localOcc = dst.occurrences.addByInsert(src.component.parentDesign.parentDocument.dataFile, foo, False)&lt;/FONT&gt; to create a temporary local&amp;nbsp;copy of the referenced component.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, because this copies the whole referenced component and not just the subcomponent I'm interested in (&lt;FONT face="courier new,courier"&gt;src.component&lt;/FONT&gt;), I now need to locate the component equivalent to&amp;nbsp;&lt;FONT face="courier new,courier"&gt;src.component&lt;/FONT&gt;&amp;nbsp;that's within &lt;FONT face="courier new,courier"&gt;localOcc&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Doing some kind of recursive iteration though &lt;FONT face="courier new,courier"&gt;localOcc.childOccurrences&lt;/FONT&gt;&amp;nbsp;and looking for something with a matching name seems inefficient and error-prone (as I understand it, the local equivalent I'm searching for may have been automatically renamed if the current document already contained a component of the same name). I suppose calculating a &lt;FONT face="courier new,courier"&gt;src.component.parentDesign.rootComponent.occurrences[x].childOccurrences[y].childOccurrences[z].…&lt;/FONT&gt; path back to &lt;FONT face="courier new,courier"&gt;src&lt;/FONT&gt;, and substituting into &lt;FONT face="courier new,courier"&gt;localOcc.childOccurrences[x].childOccurrences[y].…&lt;/FONT&gt; seems like it might work, if the ordering is consistent between the referenced component and the local copy, but I'm not sure if that's necessarily the case (also, this method seems inefficient, painfully so&amp;nbsp;if &lt;FONT face="courier new,courier"&gt;src&lt;/FONT&gt; was provided with NativeObjects such that &lt;FONT face="courier new,courier"&gt;src.assemblyContext.assemblyContext.…&lt;/FONT&gt; does not trace back up to its root).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Will the ordering of occurrences/childOccurrences be consistent between a referenced component and a local copy of that component? Or, better yet, am I missing an efficient solution here to finding a subcomponent of &lt;FONT face="courier new,courier"&gt;localOcc&lt;/FONT&gt; that is equivalent to &lt;FONT face="courier new,courier"&gt;src.component&lt;/FONT&gt;?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 07:13:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/copy-component-originating-within-a-referenced-component/m-p/7408559#M17539</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-09-26T07:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: Copy component originating within a referenced component?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/copy-component-originating-within-a-referenced-component/m-p/7408746#M17540</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately I didn't find good solution for that. We had an API to get full path name of occurrence. However as you said, the name of occurrence would be changed(index will increment) if it is duplicated to existing one. Theoretically the hierarchy of new copy should be same with the original one if the original one is not out of date. So you have to position the source occurrence in the hierarchy of original sub component and find the new occurrence by same position in the hierarchy of new copy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will create an enhancement task in our backlog to improve that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Marshal&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 08:35:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/copy-component-originating-within-a-referenced-component/m-p/7408746#M17540</guid>
      <dc:creator>marshaltu</dc:creator>
      <dc:date>2017-09-26T08:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Copy component originating within a referenced component?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/copy-component-originating-within-a-referenced-component/m-p/7408965#M17541</link>
      <description>&lt;P&gt;Thanks for the help. In my particular case, I think I can modify my&amp;nbsp;script to have the relevant occurrence-index-path available, so that should work for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A&amp;nbsp;future&amp;nbsp;enhancement to&amp;nbsp;make copying subcomponents/geometry from other documents more direct would be appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 09:37:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/copy-component-originating-within-a-referenced-component/m-p/7408965#M17541</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-09-26T09:37:05Z</dc:date>
    </item>
  </channel>
</rss>

