How to go from text to coordn. in Python?
text to points 01.gh (4.3 KB)
If you plug in numbers in your inputs then you could do in your code:
coor = [x,y,z]
and then use that as the first line as in
oh, and coorsplit
isnât needed than actually, since coor
is already a list. So
import itertools as it
coor = [x,y,z]
coor = [coor for i in range(0, len(coor))]
a = list(it.product(*coor))
So if you plug 0 into x, 2 into y and -2 into z youâd get the coordinates in a list you are looking for.
Thank you for your response.
I actually simplified it for if somebody else would response.
The input wonât be numbers.
I am still curious how it is possible to turn the text into coordn.
-The conversation below can be skipped, when everything above is clear enough. -
So, continuing from the previous post, my aim is to create different directions/possible directions. In the bigger picture I create something similar like shortest walk. I do not use the component because I have some other ideas in mind and goal which I aim for now.
The six points are 45degrees directions. When I understand this method I can modify the way of how the walk will go. I can even change (after the understanding of this basic python part) how to manipulate the walk in height, etc. All to build a structure I want to create.
I reached the limit of simplified grasshoppering during anemone or other looping tools of some sorts. That is the reason why I turned to Python.
About the plug of x/y/z for a coordinate, I wanted to make it more efficient with advanced coding, which I am still learning.
If I continue with pluging everything I will have again a very large ineffient and heavy script.
@Edward, try this to go from thing
to a list of Point3d
:
thing = list(it.product(*coorsplit))
a = [rs.coerce3dpoint(t, True) for t in thing]
_
c.
text to points 02_re.gh (3.2 KB)
pts =[]
for i in range(len(thing)):
pt = rs.AddPoint(thing[i])
pts.append(pt)
My first time phyton, so it should be very easy to understand.
Thank yâall!
I saw on the internet something about people adding a vector to a point, which essentially sum both coordinates to a new one.
However, I cannot find it anymore, does some of you know how to type that?
It should be very easy, but I cannot figure it out right now.
It is just like a vector plus a vector.
text to points 03.gh (4.8 KB)
Hi, these are pretty basic syntax questions youâve been asking - have you tried working through a proper Python course?
https://www.learnpython.org/ is a pretty good introduction with interactive exercises. Youâll learn a lot more than coming back to the forums for every syntax error
In this case look up list comprehension syntax, you probably want something like
[opt + ptPre_list_lastInput for opt in crdOptions]
(canât be sure, no idea what any of the variable names mean)
If you want to just add two vectors together, the addition operator (a + b
) works on Point3d and Vector3d types, which you can get from rs.coerce3dpoint
or rs.coerce3dvector
Yes, I tried working through a Python course. I will continue with that, thank you.
Because I am new to Python I do not know the line between what is ânon-forum likeâ and âforum like.â Now it becomes more clear.
I have another question. [opt + ptPre_list_lastInput for opt in crdOptions]
Is clear to me now, and why are used instead of ( ). However, how I implemented it does not work properly. Summing coordinates/vectors is clear to me through and also the logic behind what you written through learnpython.org.
But, now I have the problem with a None Type,
I tried rs.AddPoint and also rs.coerce3Dpoint, I am doing it wrong.
text to points 04.gh (4.9 KB)
Well the error is telling you that crdOptions is a None type ( googling python error messages works great in general )
Trace that back to the source, turns out that rs.coerce3dpoint is silently returning None instead of throwing an error - something I personally donât like about the rs library.
Why? It expects a Guid or an iterable of 3 numbers as input, but youâre feeding it a list of tuples. So you have to apply it to each tuple individually:
vector_tuples = list(it.product(*crdCalcu_A)) # [(0, 0, 0), (0, 0, 2.0), (0, 0, -2.0) ...]
crdOptions = [rs.coerce3dpoint(t) for t in vector_tuples]
(Print statements are your friend if youâre not sure about intermediate values)
@piac I was trying to search for the coerce3dpoint()
function signature on http://developer.rhino3d.com/api/RhinoScriptSyntax/ , but it looks like the documentation for the entire family of coerce*** functions are missing.
Is this intentional? i.e. theyâre only supposed to be used in internal functions and not publicly exposed
Yes, they were originally meant as internal functions. Because they became so popular, however, they are there to stay.
In v6, we added a few functions that start with âCreateâ and will be documented. @scottd is the brain behind them.
Ah okay - so thatâs 4 different ways of instantiating geometry in Python now:
Rhino.Geometry.Point3d
constructorrs.CreatePoint()
rs.coerce3dpoint()
rs.AddPoint()
each with their own different set of overloadsâŚ
It does seem unnecessarily confusing to newcomers, along with the juggling back and forth between Guids and Rhinocommon types
One reason I always teach people to go for import Rhino
right from the start.
Yes. We have many libraries (well, there is also):
Grasshopper.Kernel.Types.GH_Point
,Rhino.Geometry.Point
,Rhino.DocObjects.PointObject
,Rhino.Geometry.Point3f
,Rhino.Geometry.Point4d
,If they use rhinoscriptsyntax, however, thereâs only:
This creates an index-able group of coordinates. Something like list of numbers.
and:
This adds coordinates to the document and creates a touchable âpointâ, referenced by its ID.
The difference between a document-object and a coordinate-only point has always been there. There simply was no RhinoCommon-free way of creating the âcoordinate groupâ, we were just hiddenly coercing lists to the âcoordinate groupâ. This solves the asymmetry.
Yeah, my minor complaint here (sorry for bringing this off-topic) is that beginners to scripting and Python inevitably start out with rhinoscriptsyntax, and then get into a lot of confusion with errors involving âGuidsâ and âaddingâ geometry to invisible documents - and now having to âcreateâ them again (donât they already exist?) in order to access their attributes.
In my opinion, the RS library also encourages a very imperative, linear style of coding and hinders expressivity and algorithmic thinking to some extent, having to always think in terms of manipulating some document-object. With guids one is limited to the set of functions in the standard RS library, and sooner or later has to do something outside of that set and end up learning bits of RhinoCommon anyway - transitioning back and forth within a script can then be quite a pain.
(end of rant, just sharing some of my experiences :p)
Yeah, I agree, but itâs still better to start from something simple and managing the way up, than being confused altogether from the beginningâŚ