<?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: How do I move / rotate the mesh? in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-move-rotate-the-mesh/m-p/9931927#M10344</link>
    <description>&lt;P&gt;I made a misstake in the transform-function&lt;/P&gt;&lt;P&gt;instead of&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def transform(self, matrix:adsk.core.Matrix3D):
        """executes a transformation on the trimeshBody"""
        self.trimesh.apply_transform(np.reshape(matrix,(-1,3)))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it should be&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def transform(self, matrix:adsk.core.Matrix3D):
        """executes a transformation on the trimeshBody"""
        self.trimesh.apply_transform(np.reshape(matrix.asArray(),(-1,4)))&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 11 Dec 2020 08:12:32 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-12-11T08:12:32Z</dc:date>
    <item>
      <title>How do I move / rotate the mesh?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-move-rotate-the-mesh/m-p/9820728#M10341</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a task. I need to rotate and move imported stl model, i do it like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;...
dlg = ui.createFileDialog()
dlg.title = 'Open STL File'
dlg.filter = 'Model (*.stl);;All Files (*.*)'
if dlg.showOpen() != adsk.core.DialogResults.DialogOK :
   return
filename = dlg.filename
ModelStl = root.meshBodies
ModelStl.add(filename, adsk.fusion.MeshUnits.CentimeterMeshUnit)
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and then i should to rotate and move this model. I found this topic&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/bug-move-feature-is-broken/m-p/9223668" target="_blank"&gt;https://forums.autodesk.com/t5/fusion-360-api-and-scripts/bug-move-feature-is-broken/m-p/9223668&lt;/A&gt;&lt;/P&gt;&lt;P&gt;it works fine, but i need to do it inside one script.&amp;nbsp;I tried to move the mesh like a default object, but it throws errors.&lt;/P&gt;&lt;P&gt;something like this...&lt;/P&gt;&lt;LI-CODE lang="python"&gt;rotateModel = adsk.core.Matrix3D.create()
rotateModel.setToRotation(math.pi / 2.0, adsk.core.Vector3D.create(1,0,0), adsk.core.Point3D.create(0,0,0))

moveFeats = root.features.moveFeatures
moveFeatureInput = moveFeats.createInput(ModelStl, rotateModel)
moveFeats.add(moveFeatureInput)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2020 14:47:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-move-rotate-the-mesh/m-p/9820728#M10341</guid>
      <dc:creator>shutov441-vuz</dc:creator>
      <dc:date>2020-10-23T14:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I move / rotate the mesh?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-move-rotate-the-mesh/m-p/9820764#M10342</link>
      <description>&lt;P&gt;Unfortunately, the API doesn't currently support moving a mesh body.&amp;nbsp; There have been significant changes/enhancements made to the move command and the API has not yet been updated to support these.&amp;nbsp; Hopefully, not too far in the future.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2020 15:00:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-move-rotate-the-mesh/m-p/9820764#M10342</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2020-10-23T15:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I move / rotate the mesh?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-move-rotate-the-mesh/m-p/9929450#M10343</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9643223"&gt;@shutov441-vuz&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;like &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5741855"&gt;@BrianEkins&lt;/a&gt; said, there is no method in the fusion API to move/rotate a MeshBody.&lt;/P&gt;&lt;P&gt;But you can use the trimesh-library to create a non-fusion-mesh, move/transform this and add this transformed mesh back to fusion.&lt;/P&gt;&lt;P&gt;You'll need the trimesh-lib, as well as the numpy-lib.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use a class I created recently:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import numpy as np
import trimesh as tri
import adsk.core, adsk.fusion

class MyTrimesh():
    """Class handles the trimesh functionality """
    
    def __init__(self):
        self.trimesh = tri.base.Trimesh()


    def create_from_fMesh(self, fmesh:adsk.fusion.MeshBody):
        """creates a Trimesh from a Fusion-MeshBody"""
        self.trimesh = tri.base.Trimesh(
            vertices=np.reshape(fmesh.mesh.nodeCoordinatesAsDouble,(-1,3)),
            faces=np.reshape(fmesh.mesh.triangleNodeIndices,(-1,3)),
            vertex_normals=np.reshape(fmesh.mesh.normalVectorsAsDouble, (-1,3)))
        self.trimesh.merge_vertices(merge_tex=True, merge_norm=True)


    def create_from_bRep(self, brep:adsk.fusion.BRepBody):
        """creates a Trimesh from a bRepBody"""
        mgr = brep.meshManager.createMeshCalculator()
        mgr.setQuality(adsk.fusion.TriangleMeshQualityOptions.LowQualityTriangleMesh)
        meshbody = mgr.calculate()

        self.trimesh = tri.base.Trimesh(
            vertices=np.reshape(meshbody.nodeCoordinatesAsDouble, (-1, 3)),
            faces=np.reshape(meshbody.nodeIndices, (-1, 3)),
            vertex_normals=np.reshape(meshbody.normalVectorsAsDouble, (-1, 3)))

        self.trimesh.merge_vertices(merge_tex=True,merge_norm=True)
        

    def transform(self, matrix:adsk.core.Matrix3D):
        """executes a transformation on the trimeshBody"""
        self.trimesh.apply_transform(np.reshape(matrix,(-1,3)))


    def add_to_component(self, comp:adsk.fusion.Component) -&amp;gt; adsk.fusion.MeshBody:
        """adds the Trimesh to the components meshBodies and returns the created fMeshBody"""
        
        nodeCoordinates = self.trimesh.vertices.flatten().tolist()
        nodeIndices = self.trimesh.faces.flatten().tolist()
        normalVectors = self.trimesh.vertex_normals.flatten().tolist()

        meshBody = comp.meshBodies.addByTriangleMeshData(nodeCoordinates, nodeIndices, normalVectors, nodeIndices)
        return meshBody


    def deleteMe(self):
        """sets the trimesh-value to None"""
        self.trimesh = None
        &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So you can add this to your code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# if you added the class as separate file to your folder
from . import MyTrimesh as tri

#root = adsk.core.Application.get().activeProduct.rootComponent

mesh0 = ModelStl[0]   # or any other body

trimesh = tri.MyTrimesh()   # creates Instance
trimesh.create_from_fMesh(mesh0)   # add meshbody to trimesh
trimesh.transform(rotateModel)   # move/rotate trimesh
trimesh.add_to_component(root)   # add rotated meshbody to root.meshBodies

del trimesh&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this works for you, I´m using this class and it works fine for me. The only issue is, the Meshbody will added to the root.meshBodies, no matter what component you put in to the add_to_component-function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 12:11:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-move-rotate-the-mesh/m-p/9929450#M10343</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-12-10T12:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I move / rotate the mesh?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-move-rotate-the-mesh/m-p/9931927#M10344</link>
      <description>&lt;P&gt;I made a misstake in the transform-function&lt;/P&gt;&lt;P&gt;instead of&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def transform(self, matrix:adsk.core.Matrix3D):
        """executes a transformation on the trimeshBody"""
        self.trimesh.apply_transform(np.reshape(matrix,(-1,3)))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it should be&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def transform(self, matrix:adsk.core.Matrix3D):
        """executes a transformation on the trimeshBody"""
        self.trimesh.apply_transform(np.reshape(matrix.asArray(),(-1,4)))&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 11 Dec 2020 08:12:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-move-rotate-the-mesh/m-p/9931927#M10344</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-12-11T08:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I move / rotate the mesh?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-move-rotate-the-mesh/m-p/9933715#M10345</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous, thank you for your solution. I solved this problem. &lt;SPAN&gt;All I needed to do was move and rotate the model. I did it like this.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def move_mesh_model(vector3D, mesh_item):
    design.designType = adsk.fusion.DesignTypes.DirectDesignType

    temp_mesh_models.add(mesh_models.item(mesh_item))

    transform = adsk.core.Matrix3D.create()
    transform.translation = vector3D

    moveFeats = root.features.moveFeatures
    moveFeatureInput = moveFeats.createInput(temp_mesh_models, transform)
    moveFeats.add(moveFeatureInput)

    temp_mesh_models.clear()&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;All you had to do was switch the design mode.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;design.designType&amp;nbsp;=&amp;nbsp;adsk.fusion.DesignTypes.DirectDesignTyp&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 21:08:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-move-rotate-the-mesh/m-p/9933715#M10345</guid>
      <dc:creator>shutov441-vuz</dc:creator>
      <dc:date>2020-12-11T21:08:58Z</dc:date>
    </item>
  </channel>
</rss>

