GHPython MirrorObjects

Hi all,

I am trying to get the hang of ghpython, but I seem stuck with mirroring objects (pretty basic…).

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg

a =

a.append(rs.AddLine([0,-Thickness,0],[W/2,-Thickness,0]))
a.append(rs.AddLine([0,-Fold],[W/2,-Fold]))

a.append(rs.AddLine([-(Fold-3*Thickness),0],[0,0]))

a.append(rs.AddLine([0,0],[0,H/2]))
a.append(rs.AddLine([-(Fold-3Thickness),0],[-(Fold-3Thickness),H/2]))

a.append(rs.MirrorObjects(a,[H/2,0],[H/2,1],True))

I cannot manage to append the transformed objects to the output variable of the ghpython component. ‘Data conversion failed from Goo to Geometry’. Or are methods like Mirrorobjects only for pythonscripts, not GHPython?

Any good resources on GHPython specifically? I am struggling to understand the logic, most I can find is about Python scripting for Rhino…

Thanks!

Hi @Terribel ,

You’re not too far off…

If I understand your intent, this should work below:

Code:

import rhinoscriptsyntax as rs

# Create an empty list to store the lines
line_list = []

# Append lines to the list
line_list.append(rs.AddLine([0, -Thickness, 0], [W / 2, -Thickness, 0]))
line_list.append(rs.AddLine([0, -Fold, 0], [W / 2, -Fold, 0]))
line_list.append(rs.AddLine([-(Fold - 3 * Thickness), 0], [0, 0, 0]))
line_list.append(rs.AddLine([0, 0, 0], [0, H / 2, 0]))
line_list.append(rs.AddLine([-(Fold - 3 * Thickness), 0], [-(Fold - 3 * Thickness), H / 2, 0]))

# Mirror the objects in the line list
Mo = rs.MirrorObjects(line_list, [H / 2, 0, 0], [H / 2, 1, 0], True)

Graph Space:

Model Space:
image

20230815_Line_Mirroring_Python_Response_01a.gh (7.4 KB)

Hi Michael,

thanks for your help!

The thing I am struggling with is to append these mirrored lines to the original list.

E.g in your example, using .append to add line_list to Mo gives errors. I guess the reason is that rs.MirrorObjects returns a different type (Rhino Geometry?) than the original Addline() method. I do not understand GHPython enough to know how to combine these different types into one list as output.

What I am trying to achieve: I want to create geometry that is symmetric along both X and Y axes. By creating a few lines and then mirroring them (and combining the resulting geometries into one list) I can speed up the workflow (like, a lot).

Thanks!

Hmm no errors on my end, do you have a file or geometry set to include that can be tested with?

I’ve put together a grasshopper script to illustrate what I think you are trying to achieve.

Is this what you are after? Where drawing a line/shape gets mirrored in both X&Y and then recombined?
So your control geometry only exists in one place?

Graph Space:

Model Space:

Control Geometry:

Mirroring On:

Modifying Control Geometry:

Testing With Breps:

Also if you are working with SubD (which I don’t think you are in this case?) there is a Rhino command called Reflect that may be of interest:

Let me know if the grasshopper script is what you are after and then we can look at Python from there.

Thanks!

20230816_Mirror_Objects_XY_Recombine_Response_01b.gh (31.6 KB)

Hi Michael,

thanks so much for helping me out!

In a broader context: I want to build an algorithm to create 2D parametric geometry for paper or cardboard, for example a parametric paper envelope.So only 2D curves.
All geometry is created within the script, so no referencing to existing geometry. The variables width, length, fold,…define the final shape, with a distinction between cutting lines (black) and folding lines (red).

image

I have already built a GH def to do this (example above: the preview and baked geometry), but there are quite a few complexities in the geometry (paper thickness, folding angles,…) and I end up with a fairly big definition which is not very robust: for example: explode → select item components lead to trouble because the order of the segments (list) changes when the ratio between width and length change significantly.

Others advised in another post that parametric CAD would be better suited for this kind of geometry, but I wanted to stick with Rhino for the moment. I could rebuild the definition using another approach, but wanted to try to code it, as it seemed faster to me: draw curves based on coordinates calculated with variables, and mirror the curves given the final geometry is symmetric. The script I posted earlier is the beginning of that: define the red lines parametrically, and then mirror these. Same with the black lines in a second routine. BUT, then I encountered the issue with mirroring.

What i basically want to end up with is a simple GHPython component that has two outputs: ‘red’ and ‘black’ with the respective lines as curves. But somehow the append causes trouble:

Mo = rs.MirrorObjects(line_list, [H / 2, 0, 0], [H / 2, 1, 0], True)
Mo.append(line_list)

It is probably something really simple, but I could not find a solution online.

Thanks again!

Goo is “Grasshopper Object Output” if I remember right.

I can’t repeat the issue on my end. I would need more context to work with. If you would like to send it privately let me know but I need to see that portion of your code to know where the data mismatch is.

That being said I’m a little confused on the append intention with Mo. Mo is already a list of all the lines from the mirroring function. By appending Mo with line list you are essentially adding a nested list of “line list” at the end of your already existing line_list aka Mo output.

Is that what you are after? If not, please explain a little more what you want the Mo output to look like.

Thanks!

Hi Michael,

what I basically want to do is to simply add all the created geometry (so the ‘added lines’ as well as the various mirrored lines) in one list to have them in one output on the component.

I misunderstood the difference between appending and adding lists. Your comment about a nested list pointed me to the eureka moment. I can just use the + operator to add lists to the Mo output (standard python)…Otherwise I need to append the individual constituents of the lists not to have a nested list…

M1 = line_list + rs.MirrorObjects(line_list, [W / 2, 0, 0], [W / 2, 1, 0], True)
Mo = M1+ rs.MirrorObjects(M1, [0, H/2, 0], [1, H/2, 0], True)

Thanks a lot for your time and insigths!

1 Like

Glad you got it working!

for future reference a helpful function can be found in the following:

Notice the print statement (more expected vs the O output, can’t do much with that in GH)

You can leverage the treehelper functions to return the nested lists as a data tree.

Only sharing this because the runtime list really confused me when I started out

1 Like