I tested it.
import adsk.core, adsk.fusion, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
des = app.activeProduct
root :adsk.fusion.Component = des.rootComponent
# select
msg = 'select MeshBody'
mb :adsk.fusion.MeshBody = selectMeshBodies(ui, msg)
if not mb: return
mat3d :adsk.core.Matrix3D =getRootMatrix(mb.parentComponent)
# This is a clone
# nodes = mb.mesh.nodeCoordinates #NG!
nodes = mb.displayMesh.nodeCoordinates
# transform
[node.transformBy(mat3d) for node in nodes]
# Create a sketch at the root and create a point
skt = root.sketches.add(root.xYConstructionPlane)
skt.isComputeDeferred = True
[skt.sketchPoints.add(node) for node in nodes]
skt.isComputeDeferred = False
ui.messageBox('Done')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def getRootMatrix(
comp :adsk.fusion.Component) -> adsk.core.Matrix3D:
comp = adsk.fusion.Component.cast(comp)
des = adsk.fusion.Design.cast(comp.parentDesign)
root = des.rootComponent
mat = adsk.core.Matrix3D.create()
if comp == root:
return mat
occs = root.allOccurrencesByComponent(comp)
if len(occs) < 1:
return mat
occ = occs[0]
occ_names = occ.fullPathName.split('+')
occs = [root.allOccurrences.itemByName(name)
for name in occ_names]
mat3ds = [occ.transform for occ in occs]
mat3ds.reverse() #important!!
for mat3d in mat3ds:
mat.transformBy(mat3d)
return mat
def selectMeshBodies(
ui :adsk.core.UserInterface,
msg :str) -> adsk.fusion.MeshBody:
filtterStr = 'MeshBodies'
while True:
try:
sel :adsk.core.Selection = ui.selectEntity(msg, filtterStr)
return sel.entity
except:
return None
This did not get the correct position.
Meshbody.mesh.nodeCoordinates
Movements that are not visible on the timeline appear to be ignored.
If it is here, I think that it can be processed correctly.
Meshbody.displayMesh.nodeCoordinates
please make sure.