-
-
Save Sjoerd-Kolk/68285dc9da5d215abaf24608d6b2725f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script will align two objects according to their inertia axis. This is especially useful when aligning identical objects. | |
# Input: A project where there are two objects object_1 and object_2. | |
# Output: object_2 is aligned to object_1, taking a single object or a list of objects along with it. | |
# Author: Sjoerd Kolk (Materialise) | |
# Version: 3.0 (11 June 2018) --> Now uses 3-matic 13's latest API's, saving a few lines of code and no longer needing numpy. | |
import trimatic | |
def InertiaAxisAlign(object_1, object_2, move_along_entities): | |
object1 = trimatic.find_part(object_1) | |
object2 = trimatic.find_part(object_2) | |
print('Inertia axis aligning: ' + object2.name + ' to: ' + object1.name) | |
trimatic.update_ocs_to_cs(object1, trimatic.UpdateOCSMethod.Inertia_axes, None) | |
trimatic.update_ocs_to_cs(object2, trimatic.UpdateOCSMethod.Inertia_axes, None) | |
# This is all for moving entities that need to be taken along | |
movelist = [] | |
if type(move_along_entities) is list: | |
print('Moving along objects ' + str(move_along_entities)) | |
for i in range(len(move_along_entities)): | |
temp = trimatic.find_object(move_along_entities[i]) | |
movelist = movelist + [temp] | |
elif type(move_along_entities) is str: | |
movelist = trimatic.find_object(move_along_entities) | |
print('Moving along single object: ' + movelist.name) | |
movelist = [movelist] | |
trimatic.plane_to_plane_align(plane_on_fixed_entity=object1.object_coordinate_system.xy_plane, | |
plane_on_moving_entity=object2.object_coordinate_system.xy_plane, | |
move_along_entities=movelist) | |
print('Succesfully inertia axis aligned ' + object2.name + ' to ' + object1.name) | |
# For easy testing purposes, this is what input should look like | |
InertiaAxisAlign('Bone1_org', 'Bone1_copy', ['Point-001', 'Point-002', 'Point-003', 'Point-004', 'Point-005']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment