Python: Corner to Center

python
unhandled

(Edward) #1

I want to try to shorten a grasshopper route with python. But, how?
I cannot get the 3D-coordinates of the corner-point somehow, what am I doing wrong?

python corner to center 01.gh (7.3 KB)


(Martinspence84) #2

Hey @Edward,
I think you misspelled the method you are trying to call. It should be PointCoordinates, and I also think you should revise your input.
See here for further info:

http://developer.rhino3d.com/api/RhinoScriptSyntax/#geometry-PointCoordinates


(Edward) #3

Thank you for your response.
Do you also know how to add values (sum)?

Sum or math.fsum does not work.

python corner to center 02.gh (8.7 KB)


(Martinspence84) #4

Check out the error you are getting. The fsum() only takes one argument, and you are feeding it two :-).

You could put them in a list to get around this:

>>> x = 10
>>> y = 43.5929
>>> 
>>> sum([x,y])
53.5929
>>> 
>>> 
>>> import math
>>> math.fsum([x,y])
53.5929

Sorry for the snippet. I don’t have access to R3D/GH atm.


(Matt Gaydon) #5

Another way to make it smaller without using Python, just makes it as an expression.

CORNER_TO_CENTRE_EXPRESSION.gh (5.7 KB)


(Edward) #6

Somehow, I cannot stich the values together as a coordinate.
Do you know what I am doing wrong?

python corner to center 03.gh (8.6 KB)


#7

Hi,
You should try :

center = rs.AddPoint(Xcenter, Ycenter, Zcorner)


#8

You can also create a text string that the point component will “understand”.

center = "{"+str(Xcenter)+","+str(Ycenter)+","+str(Zcorner)+"}"

But this doesn’t create a point, only a comprehensive string.


(Edward) #9

Thank you! :smile: :