<?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: Transformation on occurrence getting reset? in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/transformation-on-occurrence-getting-reset/m-p/8402626#M15218</link>
    <description>&lt;P&gt;My guess is that the position of the component is being reset.&amp;nbsp; It's the same as in the UI when you see this dialog, except with the API, it's not displaying the dialog and is resetting everything to its previous position.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MovedComponent.png" style="width: 333px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/569684i8ACDFE7065E4FD51/image-size/large?v=v2&amp;amp;px=999" role="button" title="MovedComponent.png" alt="MovedComponent.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before creating the next occurrence, you can add the code below, which will capture the current position in a snapshot and then it won't move back. "des" is a reference to the currently active Design.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;des.snapshots.add()&lt;/PRE&gt;</description>
    <pubDate>Wed, 14 Nov 2018 21:10:28 GMT</pubDate>
    <dc:creator>BrianEkins</dc:creator>
    <dc:date>2018-11-14T21:10:28Z</dc:date>
    <item>
      <title>Transformation on occurrence getting reset?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/transformation-on-occurrence-getting-reset/m-p/8394257#M15216</link>
      <description>&lt;P&gt;I've been experimenting with the API a bit, and have run into a strange problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've created a minimally reproducible example here:&amp;nbsp;&lt;A href="https://hastebin.com/dataxefizi.py" target="_blank"&gt;https://hastebin.com/dataxefizi.py&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It creates a sphere as a new component, and then sets the component's occurrance's transform.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then, it creates another sphere as another new component, which seems to reset the transformation on the first sphere.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first print on line 34 prints "-5.0", while the second print on line 37 prints "0.0".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why is the transformation on the first component's occurrence getting reset in this case?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Nov 2018 08:24:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/transformation-on-occurrence-getting-reset/m-p/8394257#M15216</guid>
      <dc:creator>JesusFreke</dc:creator>
      <dc:date>2018-11-11T08:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation on occurrence getting reset?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/transformation-on-occurrence-getting-reset/m-p/8402514#M15217</link>
      <description>&lt;P&gt;The problem is the last line of sphere def&lt;/P&gt;&lt;P&gt;you refer to item 0&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 20:28:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/transformation-on-occurrence-getting-reset/m-p/8402514#M15217</guid>
      <dc:creator>masounmardini</dc:creator>
      <dc:date>2018-11-14T20:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation on occurrence getting reset?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/transformation-on-occurrence-getting-reset/m-p/8402626#M15218</link>
      <description>&lt;P&gt;My guess is that the position of the component is being reset.&amp;nbsp; It's the same as in the UI when you see this dialog, except with the API, it's not displaying the dialog and is resetting everything to its previous position.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MovedComponent.png" style="width: 333px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/569684i8ACDFE7065E4FD51/image-size/large?v=v2&amp;amp;px=999" role="button" title="MovedComponent.png" alt="MovedComponent.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before creating the next occurrence, you can add the code below, which will capture the current position in a snapshot and then it won't move back. "des" is a reference to the currently active Design.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;des.snapshots.add()&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Nov 2018 21:10:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/transformation-on-occurrence-getting-reset/m-p/8402626#M15218</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2018-11-14T21:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation on occurrence getting reset?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/transformation-on-occurrence-getting-reset/m-p/8402682#M15219</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3173637"&gt;@masounmardini&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;The problem is the last line of sphere def&lt;/P&gt;&lt;P&gt;you refer to item 0&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Thanks for taking a look! I don't think that's it though.&amp;nbsp;Since the revolve feature is using&amp;nbsp;&lt;/P&gt;&lt;P&gt;NewComponentFeatureOperation, feature.parentComponent should be a new, separate component, and root.allOccurrencesByComponent should return a list with a single item, containing the single occurrance of the new component. I added some logging to&amp;nbsp;my previous example and confirmed that this was the case.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 21:40:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/transformation-on-occurrence-getting-reset/m-p/8402682#M15219</guid>
      <dc:creator>JesusFreke</dc:creator>
      <dc:date>2018-11-14T21:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation on occurrence getting reset?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/transformation-on-occurrence-getting-reset/m-p/8402700#M15220</link>
      <description>&lt;P&gt;BrianEkins, that did the trick, thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the updated, working example, for posterity &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;import adsk.core, adsk.fusion, adsk.cam, math, traceback

app = adsk.core.Application.get()

root = adsk.fusion.Design.cast(app.activeProduct).rootComponent

design = adsk.fusion.Design.cast(app.activeProduct)


def sphere(radius) -&amp;gt; adsk.fusion.Occurrence:
    sketch = root.sketches.add(root.xYConstructionPlane)

    center_point = adsk.core.Point3D.create(0, 0, 0)
    start_point = adsk.core.Point3D.create(radius/10.0, 0, 0)
    arc = sketch.sketchCurves.sketchArcs.addByCenterStartSweep(center_point, start_point, math.pi)
    sketch.sketchCurves.sketchLines.addByTwoPoints(arc.startSketchPoint, arc.endSketchPoint)

    revolves = root.features.revolveFeatures
    revolve_input = revolves.createInput(sketch.profiles.item(0), root.xConstructionAxis,
                                         adsk.fusion.FeatureOperations.NewComponentFeatureOperation)

    angle = adsk.core.ValueInput.createByReal(math.pi)
    revolve_input.isSolid = True
    revolve_input.setAngleExtent(True, angle)

    feature = revolves.add(revolve_input)  # type: adsk.fusion.Feature

    return root.allOccurrencesByComponent(feature.parentComponent)[0]

def run(context):
    ui = None
    try:
        first = sphere(10)
        transform = first.transform
        transform.translation = adsk.core.Vector3D.create(-5, 0, 0)
        first.transform = transform
        design.snapshots.add()
        print(first.transform.translation.x)

        second = sphere(10)
        print(first.transform.translation.x)


    except:
        print(traceback.format_exc())&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Nov 2018 21:32:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/transformation-on-occurrence-getting-reset/m-p/8402700#M15220</guid>
      <dc:creator>JesusFreke</dc:creator>
      <dc:date>2018-11-14T21:32:45Z</dc:date>
    </item>
  </channel>
</rss>

