Python Reference Guide
 
Loading...
Searching...
No Matches
Samples\Math\FreezeLocalRotation.py
1# Copyright 2023 Autodesk, Inc. All rights reserved.
2# Use of this software is subject to the terms of the Autodesk license agreement
3# provided at the time of installation or download, or which otherwise accompanies
4# this software in either electronic or hard copy form.
5#
6# Script description:
7# Show how to transfer, in a hierarchy of selected objects, all their local rotation properties to their pre-rotation properties
8# and then zero-out their local rotation properties. This can be seen as "freezing" the location rotation properties of the selected objects.
9# Tested only with the Rotation Order being Euler XYZ and with limited scenarios.
10#
11# Topic: operators and utility functions for FBVector3d, FBMatrix,
12# FBModelList, FBModelTransformationType, FBGetSelectedModels, FBMatrixMult.
13#
14
15
16from pyfbsdk import FBVector3d, FBMatrix, FBModelList, FBModelTransformationType, FBGetSelectedModels, FBMatrixMult
17
18
19def freeze_local_rotation(model):
20 model.PropertyList.Find("Enable Rotation DOF").Data = True
21
22 result_vector = FBVector3d()
23
24 if not model.Parent:
25 gRot = FBVector3d()
26 model.GetVector(gRot, FBModelTransformationType.kModelRotation, True)
27
28 result_vector = gRot
29 else:
30 prerot = model.PreRotation
31
32 model_DOF2LRM = FBMatrix()
33 model.DofToLRM(model_DOF2LRM, prerot)
34
35 model_globalMatrix = FBMatrix()
36 model.GetMatrix(model_globalMatrix, FBModelTransformationType.kModelRotation, False)
37
38 model_multMatrix = FBMatrix()
39 FBMatrixMult(model_multMatrix, model_DOF2LRM, model_globalMatrix)
40
41 model.LRMToDof(result_vector, model_multMatrix)
42
43 model.PropertyList.Find("Pre Rotation").Data = result_vector
44 model.Rotation = FBVector3d()
45
46
47modelList = FBModelList()
48FBGetSelectedModels(modelList)
49for model in modelList:
50 freeze_local_rotation(model)
Four x Four (double) Matrix.
Definition: pyfbsdk_generated.h:10558
FBMatrixMult(FBMatrix pMatrix, FBMatrix pA, FBMatrix pB)
Multiply two matrices.
FBGetSelectedModels(FBModelList pList, FBModel pParent=None, bool pSelected=True, bool pSortBySelectOrder=False)
Find all models that are selected (if pSelected is true) Searches recursively from a root model for m...