Hi @shutov441-vuz,
like @BrianEkins said, there is no method in the fusion API to move/rotate a MeshBody.
But you can use the trimesh-library to create a non-fusion-mesh, move/transform this and add this transformed mesh back to fusion.
You'll need the trimesh-lib, as well as the numpy-lib.
You can use a class I created recently:
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) -> 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
So you can add this to your code:
# 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
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.