Grasshopper

algorithmic modeling for Rhino

Hi, first post here.

I'm trying to find my way around gh by trying out components. So I may be overlooking something basic. I do cnc programming by creating closed curves in rhino and then using rhinoCAM to create nc files. Point coordinates lists become polylines. I often add or subtract 3d points from each other. I tried to script a gh python component which replaces empty input with zero ie

If not x:
X= 0

If not y:
Y = 0

If not z:
Z = 0

And then the output streams are labelled X,Y and Z.

Y and Z work fine but X raises an error.

Thanks.

Views: 401

Replies to This Discussion

It's probably something simple, not a bug.

What are your inputs and what error do you get?

No inputs, on purpose. In use I want to be able to calculate a new point from a starting point and one or two changed planar values. So if I can ignore (leave unconnected) unchanged values programming is easier.

Thanks.

No inputs? So what does x stand for? or y or z in that respect. What kind of data do you have? Is x a list

x =[]

or

 x = None

can you post the file?

either way you can use the following,

#check for inputs
if x is None:
x=0.0
print("there is no x input --> use 0.0 instead")
if y is None:
y=0.0
print("there is no y input --> use 0.0 instead")
if z is None:
z=0.0
print("there is no z input --> use 0.0 instead")

#outputs
X=x
Y=y
Z=z

Best,

M.

If you write this line in code:

'If not x:'

python will attempt to convert 'x' into a True or False value. In order to do this, x must be set to some value, such as `None`, `False`, '0.0', an empty list '[]' (all of which would be evaluated as 'False'), or 'x' could be a number, a piece of text, a Point3d, whatever.

The important thing here is that you must set a variable to some value (it can be any value, including 'None') before you can use it. If 'x' is not one of the inputs to your script, then you must set 'x' to some value within your script, before you evaluate it with the line 'if not x:'.

try this:

print x # this will show you the value contained in x

print type( x) # this will show you what kind of data is in x

Also, you should always post the error you receive. It makes it much easier for others to help you.

Thanks for help. I tested against 'None' and it works as expected. Much better than the way I was doing it.  

 

 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service