Python Script for Unrolling Brep

Hello.

I’m super new to GH Python scripting.

Can anyone explain what I am omitting to get this brep to unroll? Any help is greatly appreciated.

First Python Script.gh (6.3 KB)

hi, this might be helpful to better understand the Unroller class: https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_Unroller.htm


First Python Script_re.gh (8.2 KB)

1 Like

Thank you. Very helpful. I"m not sure I entirely understand what transpired. :slight_smile:
The PerformUnroll command is a method that is applied to a data tree containing the Brep information? Is that right? I see that it is not uncommon to simply have a closed paranthesis after a method but I’m not quite as clear on why there is a square bracket with a “0” inside it after that. Is this because this “PerformUnroll” method could perform on multiple breps and we are asking it to only perform the method on the first item. Any help with this is appreciated. Unfortunately if don’t get a little better understanding of this myself, I’m afraid I won’t build on the wisdom here.

Hello,

That is because the PerformUnroll method returns an array (i.e. list) of Breps. See the ‘returns’ section in the developer documentation.

Adding index [0] takes the first object from the list. Python indexes and slices will be very helpful for your second and subsequent scripts :slight_smile:

1 Like

yes, it’s right

by initialising a new instance of the Unroller class with rh.Geometry.Unroller(Brep) you setup operations in such a way you will be able to perform unrolling operations (Methods) on Brep

at that point you can chose what specific Unroller Method you want to use on Brep, depending on your needs

you can also shorten the code by just calling the PerformUnroll method in-line after the class initialization:

the PerformUnroll method returns a data structure with several lists of data

while you are inside the Python script, these lists are like baskets that can contain data (apples)
but if you output to GH these lists directly, all you will get is baskets containing apples, not just the apples

as confirmation: if in GH you isolate the first item of the list, you will get an item which is like a basket containing Breps, not just the Breps:

just for the sake of explanation :slight_smile: you will never use this for real
if you made that Rhino.Geometry.Brep[ ] basket of data go through another script component, then Python would handle the basket again, and let you see the apples:

that’s why, as Graham well explained, it comes much easier to just tell Python to already output the items inside basket/list [0] which contains the Breps

1 Like

Thank you. Your various screenshots make it much clearer what is going on.
Another question that you may or may not be able to answer (but I will pose nonetheless :)):

I see that I can enter [1] instead of [0] to generate a curve associated with the chosen BRep but when I do this, nothing is reported. As I look at the Unroller Method information more, it appears this might be because I have not also implemented a “AddFollowingGeometry” command to establish that data set. Just trying to establish where this command would get inserted. Without abusing the privilege, any help is appreciated.

Python Unfolding Script V3.gh (8.7 KB)

retrieving list [0] or [1] does not generate any items: items are shown only if the list contains them

that’s why if you retrieve list [1] (=curves) without first adding the curve (AddFollowingGeometry method) it will show an empty list

here is a basic example of how to add a curve to the unroll


Python Unfolding Script_re.gh (13.0 KB)

applied to a point, it would look like the following:


Python Unfolding Script V3_re2.gh (11.0 KB)

1 Like

Got it…and if I understand this correctly, grasshopper/Rhino must do some kind of check on the curves and and points to make sure they are coplanar with the Brep.

I thought Rhino did an explosion of the flattened Brep and conducted some kind of complicated comparison routine to suss out what lengths in the flattend object corresponded to an edge on the original Brep. I suspect it probably makes sense that a better way to track edges might be to generate a narrative geometry that “follows” from the original object to the flattened one. Thanks for your help.

the curve must be lying on a (sur)face of the brep:

each portion of curve which does not lie on a surface of the brep gets cut out:

this also unrolls the central point of each brep face for reference

Python Unfolding Script V3_re4.gh (12.2 KB)

[edit] as each brep.Face center point is calculated as area centroid of the face itself, the centers of each face will be placed correctly only on planar faces