MahmoudAbdelRahman / GH_CPython

CPython plugin for Rhino-Grasshopper
BSD 2-Clause "Simplified" License
175 stars 38 forks source link

Default values for inputs #36

Open natalia-wz opened 4 years ago

natalia-wz commented 4 years ago

What a great plugin! I was wondering though if there is a way of setting the default values for the inputs? Many thanks, N/

MahmoudAbdelRahman commented 4 years ago

Hi @buka71, You can set them inside the python code, once you initiate the component, you might need to delete the default input _input and add other inputs e.g. x, y, width, ....

natalia-wz commented 4 years ago

Hi yes, but if I set their initial values of the inputs with the body, the input from the components that attach to them gets overwritten. If I have _x as a variable within the list of my inputs and I set _x = 5, the value that gets connected to the _x gets overwritten (If I don't, the input behaves as expected, i.e. inherits whatever I connect to it). I was wondering if there is a way of setting an initial value for _x which gets used in case nothing gets connected to that node, but gets overwritten by whatever then connects to _x.

mrtnbrst commented 3 years ago

Empty inputs are set to None, so for an optional parameter x with a default value of 5 you could write something like:

if x is None:
    x = 5