xbit wrote: ↑Wed Jan 20, 2021 7:47 pm
Unfortunately, your snippet did not work.
And with my attempt, that makes it two different aproaches that did not work.
Works good here. You may have to had some extra lines to manage the rotation center though.
[/quote]
1. Why are you using a scaling_matrix, for rotation only operations?
[/quote]
Because you said you want
also a rotation and a move. Not only a rotation
2. Is this line necessary?
See above
3. Why do you use global_matrix.move()?
Because you said you want a translation...
Here's a complete detailed snippet with comments
Code: Select all
import Part
import FreeCAD as App
import math
sh = Part.read(PATH_TO_STEP) # replace with correct path
ssh = sh.SubShapes.copy()
### Define the center point used for transformations
trans_center = ssh[0].BoundBox.Center # replace by what you want to get as center for transformations
### Define the scaling transformation matrix
scaling_matrix = App.Matrix(2,0,0,0, 0,2,0,0, 0,0,2,0, 0,0,0,1) # replace '2" by scaling factor
### Define the rotation transformation matrix
rotx = App.Matrix()
rotx.rotateX(45*math.pi/180) # replace '45' by rotation angle around x in degrees
roty = App.Matrix()
roty.rotateY(45*math.pi/180) # replace '45' by rotation angle around y in degrees
rotz = App.Matrix()
rotz.rotateZ(45*math.pi/180) # replace '45' by rotation angle around z in degrees
### Define the translation transformation vector
move_vector = App.Vector(10,10,10) # replace '10' by needed translation
### Compute the global matrix
global_matrix = App.Matrix() # initialize the global transformation matrix
global_matrix.transform(trans_center, scaling_matrix) # apply scaling first (so axis are still correct, before rotation)
global_matrix.transform(trans_center, rotx) # apply rotation then (so center is still correct, before move)
global_matrix.transform(trans_center, roty) # apply rotation then (so center is still correct, before move)
global_matrix.transform(trans_center, rotz) # apply rotation then (so center is still correct, before move)
global_matrix.move(move_vector)
### Apply the matrix to the subshape
ssh[0] = ssh[0].transformGeometry(global_matrix)
newPart = Part.Compound(ssh)
newPart.exportStep(STEP_FilenameAndPath)