<?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: Moving a Component Help in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-a-component-help/m-p/11820452#M4233</link>
    <description>&lt;P&gt;I Found the Issue it was with my transform.&amp;nbsp; Here is the updated code that works.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;trans: adsk.core.Matrix3D = adsk.core.Matrix3D.create() 
trans.translation = pnt1.vectorTo(pnt2)
        
transNew = body.transform2
transNew.transformBy(trans)
body.transform2 = transNew&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 14 Mar 2023 13:34:50 GMT</pubDate>
    <dc:creator>rusty.bird</dc:creator>
    <dc:date>2023-03-14T13:34:50Z</dc:date>
    <item>
      <title>Moving a Component Help</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-a-component-help/m-p/11818388#M4230</link>
      <description>&lt;P&gt;Hello I am making a script to move a component from a selected point to another selected point but I am getting an error at the end.&amp;nbsp; It works if I move a body but not a component.&amp;nbsp; Here is the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;# Get a body by having the user select one.
        body: adsk.fusion.Components = ui.selectEntity('Select a component.', 'Occurrences').entity
        
        # Have an entity selected that represents a point.
        # This can be a Vertex, Sketch Point, or Construction Point.
        pointEnt = ui.selectEntity('Select a point entity', 'ConstructionPoints, SketchPoints, Vertices').entity
        
        # Get the XYZ position of the point in model space.
        pnt1: adsk.core.Point3D = None
        if pointEnt.objectType == adsk.fusion.SketchPoint.classType():
            skPoint: adsk.fusion.SketchPoint = pointEnt
            pnt1 = skPoint.worldGeometry
        else:
            pnt1 = pointEnt.geometry
            
        # Select a Second Point
        pointEnt2 = ui.selectEntity('Select a point entity', 'ConstructionPoints, SketchPoints, Vertices').entity
        
        # Get the XYZ position of the point in model space.
        pnt2: adsk.core.Point3D = None
        if pointEnt2.objectType == adsk.fusion.SketchPoint.classType():
            skPoint2: adsk.fusion.SketchPoint = pointEnt2
            pnt2 = skPoint2.worldGeometry
        else:
            pnt2 = pointEnt2.geometry
        
        # Create a matrix that defines the translation from point 1 to point 
        trans: adsk.core.Matrix3D = adsk.core.Matrix3D.create()
        trans.translation = pnt1.vectorTo(pnt2)
        
        # Create a move feature using the matrix.
        moveFeatures = design.rootComponent.features.moveFeatures
        inputEnts = adsk.core.ObjectCollection.create()
        inputEnts.add(body)
        moveInput = moveFeatures.createInput(inputEnts, trans)
        moveFeatures.add(moveInput)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 17:36:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-a-component-help/m-p/11818388#M4230</guid>
      <dc:creator>rusty.bird</dc:creator>
      <dc:date>2023-03-13T17:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Moving a Component Help</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-a-component-help/m-p/11819127#M4231</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9974162"&gt;@rusty.bird&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems that the movement of occurrence is not done by MoveFeature, but by Occurrence.transform property or transform2 property.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-7fb9ea55-5c24-4c27-b1c4-2e92f42774f7" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-7fb9ea55-5c24-4c27-b1c4-2e92f42774f7&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-7231EE6E-FB14-4370-AEE5-F9AE7419B97B" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-7231EE6E-FB14-4370-AEE5-F9AE7419B97B&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;U&gt;※The document states that the transform property is obsolete, but I was able to use it. I don't think the transform property should be discontinued because what you get is different.&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After changing the transform/transform2 property, the position is not fixed, so you need to do the following.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;des.snapshots.add()&lt;/LI-CODE&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/transformation-on-occurrence-getting-reset/m-p/8402626#M6887" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/fusion-360-api-and-scripts/transformation-on-occurrence-getting-reset/m-p/8402626#M6887&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 00:11:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-a-component-help/m-p/11819127#M4231</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2023-03-14T00:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Moving a Component Help</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-a-component-help/m-p/11820279#M4232</link>
      <description>&lt;P&gt;Thanks, I removed the create move feature section in the code and it mostly worked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;body.transform2 = trans
design.snapshots.add()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;But I noticed it is not moving to the correct position.&amp;nbsp; I am assuming something to do with the vectors is wrong.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 12:37:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-a-component-help/m-p/11820279#M4232</guid>
      <dc:creator>rusty.bird</dc:creator>
      <dc:date>2023-03-14T12:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Moving a Component Help</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-a-component-help/m-p/11820452#M4233</link>
      <description>&lt;P&gt;I Found the Issue it was with my transform.&amp;nbsp; Here is the updated code that works.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;trans: adsk.core.Matrix3D = adsk.core.Matrix3D.create() 
trans.translation = pnt1.vectorTo(pnt2)
        
transNew = body.transform2
transNew.transformBy(trans)
body.transform2 = transNew&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 14 Mar 2023 13:34:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-a-component-help/m-p/11820452#M4233</guid>
      <dc:creator>rusty.bird</dc:creator>
      <dc:date>2023-03-14T13:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: Moving a Component Help</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-a-component-help/m-p/11821964#M4234</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9974162"&gt;@rusty.bird&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am getting confused too, so I did a test to confirm.&lt;BR /&gt;This was tested based on ver 2.0.15509.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a component (level2) within the root component (level1) and then a component (level3).&lt;BR /&gt;Each component is created with XYZ+10.0.&lt;BR /&gt;Activate the level3 component, create a sketch on the XY plane, and draw a square.&lt;BR /&gt;Constrain only the lower left point by 10 mm in the XY direction.&lt;BR /&gt;Create the body by extrusion.&lt;BR /&gt;Create construction points at the vertices near the origin.&lt;BR /&gt;"Sketch point", "body vertex", and "construction point" all remain in the same position in the level3 component.&lt;BR /&gt;(The f3d file of this data is attached.)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 764px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1188801iFDF293829161C886/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using this data, the following script is executed.&lt;BR /&gt;The text command is designed to output the coordinate values of the selected points.&lt;BR /&gt;We expect the output to be the coordinate values (3.0,3.0,2.0) from the origin of level1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui = core.UserInterface.cast(None)
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface

        msg: str = 'Select Point'
        selFilter: str = 'ConstructionPoints, SketchPoints, Vertices'
        sel: core.Selection = selectEnt(msg, selFilter)
        if not sel:
            return

        pointEntity = sel.entity
        point: core.Point3D = get_point3d(pointEntity)
        dump_point(point, f'{pointEntity.objectType} -&amp;gt; ')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def get_point3d(
    pointEntity
) -&amp;gt; core.Point3D:

    point: core.Point3D = None
    if pointEntity.objectType == fusion.SketchPoint.classType():
        point = pointEntity.worldGeometry
    else:
        point = pointEntity.geometry

    return point


def selectEnt(
    msg: str,
    filterStr: str
) -&amp;gt; core.Selection:

    try:
        app: core.Application = core.Application.get()
        ui: core.UserInterface = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None


def dump_point(pnt: core.Point3D, msg: str = ''):
    app: core.Application = core.Application.get()
    app.log(f'{msg}{pnt.asArray()}')&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason why selectEntity is used to select an element is because the selected element will be a proxy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the actual output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt; adsk::fusion::SketchPoint -&amp;gt; (3.0, 3.0, 2.0)
 adsk::fusion::BRepVertex -&amp;gt; (3.0, 3.0, 2.0)
 adsk::fusion::ConstructionPoint -&amp;gt; (2.0, 2.0, 1.0)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SketchPoint(worldGeometry) and BRepVertex are as expected, but only the ConstructionPoint is different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The construction point coordinates are from the origin of the component one level above (level2).&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 425px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1188802iCF508880E516C55C/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;BR /&gt;I cannot determine if this is a bug or a specification. Unfortunately, the origin of each component is also greatly affected by the construction point.&lt;BR /&gt;I am sure this is a very confusing situation.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 02:46:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/moving-a-component-help/m-p/11821964#M4234</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2023-03-15T02:46:13Z</dc:date>
    </item>
  </channel>
</rss>

