In this tutorial it is shown how to align two objects that are not positioned correctly after importing in 3-matic. Furthermore, additional operations and remeshing are performed for the preparation of the 3D model. The project Aorta_Hollow.mxp that is located in the 3-matic installation folder under folder DemoFiles is used.
import trimatic
import os
import numpy as np
def main():
#Open the project Aorta_Hollow
application_exe = trimatic.get_application_path()
application_path = os.path.dirname(application_exe)
demopath = os.path.join(application_path, "DemoFiles")
path = os.path.join(demopath, "Aorta_Hollow.mxp")
trimatic.open_project(path)
# Find the part Aorta
p = trimatic.find_part("Aorta")
# Create 3 points that will help to create the correct datum plane using interactive scripting
print("Select Point 1")
p1_coords=trimatic.indicate_coordinate()
p1=trimatic.create_point(p1_coords)
print("Select Point 2")
p2_coords =trimatic.indicate_coordinate()
p2=trimatic.create_point(p2_coords)
print("Select Point 3")
p3_coords = trimatic.indicate_coordinate()
p3=trimatic.create_point(p3_coords)
#Create the aortic plane
aor_plane = trimatic.create_plane_3_points(p1,p2,p3)
aor_plane.name = "Aortic plane"
mid_point = (np.array(p1.coordinates) + np.array(p2.coordinates))/2
#translate plane such that midpoint is origin
translation_vector = np.array(mid_point) - np.array(aor_plane.origin)
trimatic.translate(aor_plane, translation_vector)
#Import the flange
flange_path = os.path.join(demopath, "Flange.stl")
flange = trimatic.import_part_stl(flange_path, True)
surfaces = flange.get_surfaces()
# Find the top surface of the Flange
for s in surfaces:
if s.name == "Top-0":
break
# Fit a plane to the top surface
fl_t_plane = trimatic.create_plane_fit(s)
fl_t_plane.name = "Flange top plane"
# Find the bottom surface
for s in surfaces:
if s.name == "Bottom":
break
# Fit a plane to the bottom surface
fl_b_plane = trimatic.create_plane_fit(s)
fl_b_plane.name = "Flange bottom plane"
# Find the midplane
avg_fl_plane = trimatic.create_plane_average_existing([fl_t_plane,fl_b_plane])
avg_fl_plane.name = "Mid flange plane"
# Plane to plane align the flange to the aorta
trimatic.plane_to_plane_align(aor_plane,avg_fl_plane,[flange,fl_b_plane,fl_t_plane],False)
# Apply local offset to the inner surface
surface_list = []
for s in surfaces:
if s.name == "Mantle":
surface_list.append(s)
max_area_surface = surface_list[0].area
for s in surface_list:
if s.area > max_area_surface:
max_area_surface = s.area
trimatic.local_offset(surface_entities=s,offset_distance=3.5)
#Hide entites which are not needed
entities=[aor_plane,fl_b_plane,fl_t_plane,p1,p2,p3,avg_fl_plane]
for i in entities:
i.visible=False
# Boolean union
union = trimatic.boolean_union([flange,p])
union.name = "3D model"
# Remesh 3D model
trimatic.uniform_remesh(entities=union, target_triangle_edge_length=1, split_edge_factor = 0.5)
main()