Measuring Curve Lengths in Imported STEP Model

Dear community,

I am interested in isolating the bounding curves of a ribbon attached as an .stp file and measuring their length.

I am attaching below a screenshot to put into perspective what the curves I am referring to look like

image

The ribbon looks like this:ribbon.stp (1.1 MB)

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.

Any suggestions?

Thanks,
Nikos.

Can you attach the .cub5 or .stp file for your model?

Hi Nikos,

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.

Thanks,
Karl

1 Like

Hi Nikos,

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.

Karl

1 Like

Hi @karl,

thank you for your response and for providing a script! Could you provide a working example geometry file so that I can replicate?

After running the python script from the journal editor for my custom end_curves and start_vertex raises a number of errors (attaching screenshot)

In my case (for the ribbon.stp file I have already provided above) the following apply:

ID end_curve_1 = 23
ID end_curve_2 = 110

ID start_vertex = 79

Thanks,
Nikos.

Hi Nikos,

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)

Karl

1 Like

Dear @karl,

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):

Does that make sense?

Cheers,
Nikos.

Hi @Nikos,

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.

Karl

1 Like