Works in Grasshopper, but not in Python, why?

Works in Grasshopper, but not in Python, why?

Hello Everyone,

I am new to the forum, so please forgive my ignorance. I am trying to put together a script to create a wall assembly similar to those in Revit. Here are my steps:

  1. Select a curve in Rhino and input it into Grasshopper.
  2. Select the wall height, offset direction, and wall finishes.

I am hoping to do all the number crunching in a Python script, but the results are not what I’m anticipating. Frustrated, I decided to convert the Python script to work in Grasshopper…and everything works.

Can someone help me understand why it works in Grasshopper but not in Python? Files attached.

Wall_3D.3dm (73.3 KB)

Wall_2D3D_251231.gh (18.0 KB)

where is the python script that is not working ?
what s the error message ?

what s your experience level to rhino / grasshopper ? are you aware of the differences
between Object ID’s, ObjRef, Rhino Objects, Geometrie, ObjectAttributes ?

kind regards - tom

In a nutshell, Grasshopper, Python (traditional CPython), the three different Python components available within Grasshopper, and RhinoPython, are all completely different environments for code to run in.

The environment code runs in is equally important to the code itself, in terms of whether it works correctly or not. Especially when (but not only when) the code calls out to external libraries installed in that environment.

@James_Parrott - the Python code just uses rhinoscriptsyntax. So environmental differences are not an issue.

@AT1 - I see no reason your code doesn’t work in Rhino without Grasshopper. Your challenge will be to gather the input to be sent to your function, footprint_2D, and then processing the output. Grasshopper makes this somewhat easier. But there are lots of ways, from Python, to prompt the user to “select objects” and input values on the command line or from some dialog box. Just more typing. :wink:

– Dale

Hello Tom,

The python script runs, but it produces incorrect results, see below. I recently purchased Rhino 8 and new to all of this. I can see the power of Grasshopper/Python script and hopeto automate the many tedious tasks I do for work.

Best,

Arthur

  1. Shape of original curve for the 3D wall to follow

  1. 3D wall output using Grasshopper, correct result

  1. 3D wall output using Python script, incorrect result - 3D wall not following the original curve

@dale - The Python script runs, but produces incorrect results. Please look at my response to @Tom_P. ‘footprint_2D’ function is my bad, left over from my swing_door script. Should not be an issue, as I did not use it in this script. Could my problem be related to the Grasshopper coordinates being limited to CPlane (world) only?

I’m not in front of my PC so cannot check your code.

BUT

If you are getting the result you need in GH why not leave it in GH?

You can run GH code as commands using the Grasshopper Player or even compile into YAK installable plugins using the Script Editor.

I’ve made some videos about the process, search the forum for compile grasshopper.

Cheers

DK

@kiteboardshaper - Smaller packages are doable, but as the complexity increases, I can’t keep track of all the connector wires. - Arthur

Hi @AT1

I can understand that feeling, but large projects are possible with some discipline on the GH structure:

Cheers

DK

Ok, two things:

  1. Your Grasshopper definition does the job but the your copy paste approach is not the proper way of doing things. I’d suggest you learn about data trees as quickly as possible as it will help you reduce the number of nodes. I rebuilt your offset definition with 11 nodes instead of 40 nodes. I wouldn’t use Edge Surface as Loft in this case works much better.

    Wall_2D3D_251231_11-vs-40.gh (35.9 KB)

  2. I’m lacking programming skills but I do get pretty far with looking at example files and Copilot helps quite a bit too. Your code does the same thing as the Grasshopper definition. It handles one curve after another with copy pasted code and you need 78 lines of code. It can be done with much less.

    offset_curve_loft_python.gh (12.5 KB)

I haven’t checked the files, but if you’re trying to offset a polyline with per segment distance using Python (and RhinoCommon), something like this might help:

@martinsiegrist - Pretty impressive, thank you! I started the Rhino/Grasshopper journey about a week ago and have a long road ahead of me. I tried your script and received the following output below, please help. Also, are there equivalent commands for ‘for’ loops and ‘if/else’ statements in Grasshopper?

Try with two or more lines, curves or polylines.

@martinsiegrist Selecting multiple lines/curves will definitely speed up my workflow, thank you. But, I would still like to have the option to select a single line/curve.

Wall_2D3D_251231_one or many.gh (22.7 KB)

@martinsiegrist - This is perfect, thank you. I am going to study your work carefully tonight!
Another problem (files attached): I am having Grasshopper make 3D swing doors for me. I can make it work in CPlane(WorldXY), but I I would like to align the door with an angle wall from the start. How should I approach this?

X-P_LEVEL 1_3D.3dm (1.5 MB)

door_swing_2D3D_251230.gh (20.5 KB)

You’re close. For just one size door frame you would build one door on the XY plane and then use the Orient component to orient the door from XY to the respective target planes.

@AndersDeleuran - Thank you for sharing, I did not know about the ‘Gene Pool’ component. Is there a component in Grasshopper that combines ‘Gene Pool’ and ‘Value List’? I want to combine the materials in my wall assembly as one (examples … extwall_stucco_1/2”ply_2x4studs_1/2”gyp, intwall_1/2”gyp_2x4studs_1/"2”gyp, etc.). And up to (8) different wall materials.

Hi @AT1
Why are you not posting your python script since that is problem?
RM

@3dsynergy- The Python script is part of the GH file posted.