How to convert brep.Trims 2d Curve to a 3d curve + rhinocommon

I am extracting Trims from a brep surface. Each brepTrim stores a 2d curve within it. Is there a way to map those 2d curves onto a brep surface/face that its trimming so that i can get a 3d curve from it?
I tried using Loops to extract the trimming 3d curves but that is not a reliable method since sometimes that gives me a seam curve as well.
What is a proper way to query a brep for a trimming 3d curve on surface of a brep face.

The reason i am asking about 3d curve specifically is that i am using it to create trims in a different software (revit/dynamo) and so far I have only one method available for trimming a surface.

Thanks!

-konrad

Hi Konrad,
The BrepTrim is in the 2D parameter space, so in order that you get the 3D geometry, you need to find the “Edge” that the trim belongs to. Use BrepTrim:Edge Once you have the edge and verify that it is not null (because it can be for singular trims), then you can get the curve using BrepEdge::ToNurbsCurve()

Hi Rajaa,

Thanks for replying. Yes, your method gets me a step closer however not entirely there yet. When i am calling trims i get a list of 5 trims but really i need two closed trim curves.

so is there a way to group those trims into lists of lists based on whether they form a closed polycurve. Can i try and cast them to polycurve? as you can imagine i need a closed polycurve to be able to trim a surface with it (nature of the Dynamo beast :slight_smile: )

Try “Curve.JoinCurves”

can’t do. I dont think that i have mentioned that i am working using the openNurbs/rhino3dmIO.dll interop for reading Rhino files. I am not actually inside of Rhino so i cant execute a command like this.
I guess it will all come down to being able to group them together and i will do the joining on the Revit/Dynamo side. Is there a property that Trims carry that will allow me to group them together based on whether they could be joined?

I see. Joining sorts the curves for you. Here is a suggestion. Get all the trims in a loop, then get to the edges of each trim in the loop. Before adding the edge curve to your list, make sure that it is not a seam, otherwise skip it. You know the edge is a seam if it has multiple trims that belong to the same loop or face. Does that help?

i already tested all trims for TrimType and excluded all the seam curves. Now i am left with only boundary curves. they are all naked edges so that cannot be used to sort them together. i will keep looking at it. thank you,

If you have examined the trim list in a loop, then they should be “in order” and you do not need to sort anymore. You can simply append them to a Polycurve to create one curve.

yes, but the output of that polycurve.append() is ONE (1) polycurve containing multiple closed curves. so the two closed curves that you see in the image that i appended are put together under one polycurve. i need to separate them.

for brep in rhObjects:
trims = brep.Trims
newPolyCurve = rc.Geometry.PolyCurve()
for i in trims:
dsFaces.append(rhNurbsSurfaceToSurface(i.Face.ToNurbsSurface()))
if i.TrimType == rc.Geometry.BrepTrimType.Boundary:
trimEdge.append(i.Edge.EdgeIndex)
for index in trimEdge:
edges.append(brep.Edges.Item[index].ToNurbsCurve())
for i in edges:
newPolyCurve.Append(i)
if newPolyCurve.IsClosed == 1:
temp_list.append(newPolyCurve)
newPolyCurve = rc.Geometry.PolyCurve()

for brep in rhObjects:
trims = brep.Trims
newPolyCurve = rc.Geometry.PolyCurve()
for i in trims:				
	dsFaces.append(rhNurbsSurfaceToSurface(i.Face.ToNurbsSurface()))
	if i.TrimType == rc.Geometry.BrepTrimType.Boundary:
		trimEdge.append(i.Edge.EdgeIndex)
		for index in trimEdge:
			edges.append(brep.Edges.Item[index].ToNurbsCurve())
		for i in edges:
			newPolyCurve.Append(i)
			if newPolyCurve.IsClosed == 1:
				temp_list.append(newPolyCurve)
				newPolyCurve = rc.Geometry.PolyCurve()

for some reason this wont work because newpolyCurve.IsClosed returns false for as long as the two curves are not appended to it. :frowning:

You need to loop through each breploop separately and create a polycurve for each of your loops. Getting all the trims of the beep will indeed create one big poly curve and the order of trims are not sorted.

there is only one loop in this brep. this is why i gave up the idea of using loops. they also contain seam curves which was my secondary reason to give it up. since brep.Loops are ordered i will try and loop through them to see where that leads.