algorithmic modeling for Rhino
I have very litte programming experience, but I have been studying Python for a couple of months. I have done several tutorials using Python Script and read most of the RhinoPython. Now I am trying to jump into GhPython, and a have a few questions and I would appreciate if any of you could help clarify some of them!
I thought it was easier to write the questions along the some code, so I have attached a screenshot with my questions highlighted, as well as the ghx.
Thank you in advance for any help.
I'll try to answer your questions one by one. Some of these questions refer to ghPython itself, some are Python questions and some are Grasshopper questions. So, you are asking here at the right spot :)
I hope this rather long answer was helpful.
Thanks, kind regards,
for Robert McNeel & Associates
Thank you so much for the detailed response. It was incredibly helpful.
I played around with the sc.sticky, seems helpful.
If you don't mind, I have just a few other simple questions.
1. Regarding documentation, let me see if I understand this:
rc > RhinoCommon SDK Help File
rs > Rhino IronPython + Rhinoscript (Programmer's References)
gh > Grasshopper SDK Help File
ghenv > source code of ghpython only
2. Regarding the ghdoc and ghenv variables, where are the originally defined?
3. For making geometry, what would be the preferred/recommended method?
rs/rc/ or the latest ghcomp? Depends on the use?
1. Yes, so, documentation:
Rhino -> RhinoCommon SDK Help File
rhinoscriptsyntax -> _EditPythonScript file Help (or F1 in editor)
Python -> docs.python.org
Grasshopper -> Grasshopper SDK help file
2. As you say, ghdoc/ghenv are just two variables. The first one contains an instance of GrasshopperDocument, the second one of PythonEnvironment. They list a series of RhinoCommon/Grasshopper/Python references, that might occasionally be useful. They are not needed to create geometry, but just to address special topics that might occasionally be useful. In fact, GrasshopperDocument does the same as RhinoDoc with ObjectTable, while ghenv really does specific things like connecting with Intellisense, providing the Python interpreter instance, or the local scope (the object that represents the executing place of the script).
3. All methods that work for you are "the best" ones. To start I really suggest to use GhPython with rhinoscriptsyntax, which is also the most concise way. Later, RhinoCommon might work, too. ghcomp is useful especially to use components that would otherwise not be accessible, like Delauney or Convex Hull.
I hope this helps,
for Robert McNeel & Associates
Is there a way to create a copy of a GH list input on the python component, so I can update it every loop.. So the initial list is from gh but I want to change items in it every loop and send it back to the next loop in its changed condition. Hope its clear! attached a simple example of my question...
HAH definitely yes I remember. I went through all the threads you referenced but still so confused with the gh's list input to python as GLOBAL VARIABLES.. is there really a way to replace the items coming from the gh list eventhough the operations are referring back to the same list. so I made another caps for my intention.
My original code works with a timer, and every step I make the change in the list (an input from gh) and I want to continue the same operation on the changed list. they have the same name ofc. ghosts need to be buusted
All the best from Graz!!
I'm afraid I don't quite understand the issue(s). There seem to be several things going on at once here. It would help if you could break the logic into more explicit steps, and/or, provide a minimal example file that demonstrates (with comments/scribbles etc) what you're trying to achieve. That said, if the problem is that your variable b in the Python component keeps changing on each update. That is because you're not setting a random seed, meaning that the randint() function will return a new random integer at each call. Also, I suspect you still might be in need of a persistent variable (that is, a variable within the scope of the GHPython that isn't re-instantiated each time the component updates, enabling you to iteratively operate on data ala Kangaroo). That probably didn't help much, apologies :)
Perhaps the attached file will better demonstrate what I'm talking about. That is:
1) Grabbing the data from an input list and storing this in a persistent variable.
2) Updating this data when you click a button.
3) Outputting this data to Grasshopper.