algorithmic modeling for Rhino
I am totally new to Python (and programming in general) and I am trying to understand the basics of it.
I want to import a curve from gh, divide it and display the points. It looks like I have managed to import the curve into the py component but I cannot see any points (see pic)....
any suggestion?
thanks in advance.
Tags:
Replies are closed for this discussion.
You are mixing and matching two different things, the normal default script context that is within Grasshopper and the changeable script context between Grasshopper and Rhino itself. Here is how to do your script in only Grasshopper or both Grasshopper and Rhino by toggling the script context from this script that uses a "points" Python wire output:
import rhinoscriptsyntax
points = rhinoscriptsyntax.DivideCurve (curve1, 10)
...to this script, that leaves the Grasshopper part working but adds a direct to Rhino script context toggle and back to restore it to normal at the end, and this puts points directly into the Rhino document, bypassing Grasshopper at will:
import rhinoscriptsyntax
import scriptcontext
import Rhino
scriptcontext.doc = Rhino.RhinoDoc.ActiveDoc
points = rhinoscriptsyntax.DivideCurve (curve1, 10)
for point in points:
rhinoscriptsyntax.AddPoint (point)
scriptcontext.doc = ghdoc
This assumes you know about the type hint that is needed by right clicking the Python wire input, and the Item/List/Tree access settings for the Python wire inputs which is fine as it is:
thank you very much Nik for your reply.
at the moment, I want to stay only within the gh geometries. Following your example, I want now create lists of points and than run the line command between those points. as u see from the pic, my lists contain only one element but also, it looks like that those single elements are not 3d points....
You have no Python "points" variable assigned to anything so your Python output is void.
If you bake just my new Python script here, you do get your lines and points, or whatever is in there that has assigned geometry, and you get a preview too, but I turned that off and opted for real outputs:
My number_of_points should be called number_of_divisions since I have to add +1 to handle the 11 points created by a subdivision of 10.
great. thanks again nik for your quick response.
I was aiming to have 2 separate lists of points that I could control to combine into different line combinations like cull or cull index in gh. I have a simple gh definition that I am aiming to slowly resolve with python (here attached) covering the basics of the language.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by