I am interested in the total length of the inner curve (green) and the outer curve (blue) on the edges of the ribbon defined in the .stp file.
The problem I am facing is that the ribbon volume is made of smaller surfaces, making it really complicated to select the curves of interest, in order to measure their length that should add up to desired quantity.
Here is a python script that does what I think you want… We could use some additional methods in the interface to make selecting continuous curves easier. This will only work on surfaces as it uses the num_parents method to find the exterior edges.
The input is the start vertex and the terminating curves, typically perpendicular to start curve as shown in the figure below.
# these two lines must be user defined
end_curves = set([110, 142])
start_vertex = 62
(start_curve,) = set(cubit.parse_cubit_list("curve", f"in vertex {start_vertex})")) - end_curves
curve_list = [start_curve]
while (start_curve not in end_curves):
next_vertices = set( cubit.parse_cubit_list("vertex", f"in curve {start_curve}") )
next_vertices.remove(start_vertex)
(start_vertex,) = next_vertices
next_curves = set(cubit.parse_cubit_list("curve", f"in vertex {start_vertex} with num_parents=1"))
next_curves.remove(start_curve)
(start_curve,) = next_curves
if start_curve not in end_curves:
curve_list.append(start_curve)
total_length = 0.0
for curve in curve_list:
total_length += cubit.get_curve_length(curve)
print(total_length)
In this trivial example, of a half circle with radius 2, I get a length of 2*pi which is the correct value.
The other thing to note is that I did a merge before running this code. The code can’t have duplicate vertices in one location. Each vertex must be attached to exactly 2 exterior curves.
I missed your STEP file earlier and I didn’t realize the ribbon was volumetric instead of just surfaces. My original solution worked only on surfaces. Selecting the volumetric curves are little more difficult. We might be able to modify this script if you can guarantee that no measured curve is shorter than the width of the ribbon.
The easier thing to do is to create a sheet body from a set of surfaces on one side.
surface 48 43 47 41 30 35 39 40 51 71 79 55 83 49 75 87 91 67 56 95 59 99 103 57 63 107 copy
unite body with is_sheet
draw body with is_sheet # just to make picking start and end data easier.
You can use the select continuous option to make picking the surfaces on a side easier.
Running the same script as before gives a total length of 529.7095672021032.
You can delete the sheet body and start over on the other side as needed.
# these two lines must be user defined
end_curves = set([282, 280])
start_vertex = 175
(start_curve,) = set(cubit.parse_cubit_list("curve", f"in vertex {start_vertex})")) - end_curves
curve_list = [start_curve]
while (start_curve not in end_curves):
next_vertices = set( cubit.parse_cubit_list("vertex", f"in curve {start_curve}") )
next_vertices.remove(start_vertex)
(start_vertex,) = next_vertices
next_curves = set(cubit.parse_cubit_list("curve", f"in vertex {start_vertex} with num_parents=1"))
next_curves.remove(start_curve)
(start_curve,) = next_curves
if start_curve not in end_curves:
curve_list.append(start_curve)
total_length = 0.0
for curve in curve_list:
total_length += cubit.get_curve_length(curve)
print(total_length)
thanks again for the detailed instructions, I can confirm that I get the exact same output for the selecting the elements with the same ID numbers you did.
Just to clarify, the vertex selection should be such that each vertex is defined as the intersection of two “exterior” edges, right? In that way I can calculate the length of the curves I am highlighting below [labelled as c1 and c3] and not the length of “interior” curve [labelled as c2] (also highlighted in the following screenshot):
Yes, I am relying on the Cubit attribute num_parents=1. The num_parents attribute returns the number of surfaces the curve is attached to. Since the center curve (C2) has two parents, the function as designed will not work with the center curves.
What I am missing in the API at this point would be a function to return the tangent at a point on a curve. This exists inside of Cubit but it is not exposed to the user in the API.