How to go from text to coordn. in Python?

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.

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.

How to go from a list of coordinates to points (python)?

text to points 02.gh (2.9 KB)

@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.

1 Like

Text to points.gh (11.3 KB)

Iâm sure thereâs a better way to do this.

2 Likes

text to points 02_re.gh (3.2 KB)

``````pts =[]
for i in range(len(thing)):
pts.append(pt)
``````

My first time phyton, so it should be very easy to understand.

1 Like

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)

1 Like

@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` constructor
• `rs.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.

2 Likes

Yes. We have many libraries (well, there is also):

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âŚ

Everything works now, but what seems odd to me is still the problem with the + for data. I cannot + a 3Dpoint with a Guide, so I made the guide a 3Dpoint.
Is that always needed?
Is it the general rule that same looking data (a value of 3 numbers) must be recognized as the same type to + them?