Using get_triangles on Marked Triangles

I’ve been trying to pull the indices of the nodes marked by a mark triangles tool from a part. A bug I’ve been coming across is with the “marked_triangles.get_triangles()” command. According to the 3-Matic scripting guide, this command should output a tuple containing two tuples, one being the points within the marked triangles, and one being the triangles within the marked triangles (each indicated by a trio of indices referring to the points within the first tuple that make up the three nodes of that triangle).

The bug that I encounter is that the first tuple output by this command is actually the entire list of points of the part (not just the nodes highlighted within the marked triangles).

Why does this bug occur? Am I misinterpreting the description of the command within the 3-Matic guide and this isn’t actually a bug, but an intentional feature? Perhaps I’m miscoding something that’s causing the command to behave adversely to my intentions?

Here’s the script I’ve been using to test out the command:
image

Thank you in advance for your assistance,
Ian Franczek

Hello Ian,

Fellow user here, but I have faced this before and can help. Your code does work and it is not a bug, just poorly explained. What MarkedTriangles.get_triangles() returns is all of the points for the Part that contains the MarkedTriangles and the subset of triangles in that Part that you marked. To get all of the vertices that you marked, you can use the following code. I myself use numpy for this type of thing, but made this with standard python in case you aren’t familiar with numpy.

import trimatic
from itertools import chain # chain is used to flatten nested lists into a single list.

marked_area = trimatic.activate_mark_freeform_area() # the activate function returns the marked triangles directly, no need for get selection
part_points, marked_triangles = marked_area.get_triangles() # points from the entire part, only the marked triangles
marked_point_indices = set(chain.from_iterable(marked_triangles)) # making a set here keeps only unique points.
coordinates = tuple(pts[index] for index in marked_point_indices)

1 Like