Grasshopper

algorithmic modeling for Rhino

This is possible with a boolean condition?

In registerInputParams I have an if-else condition, when false (by default) will be a numeric input, and for true will be a string type.

I want to change to a string type from internal menu event (as bbox comp. with "union box"). When this event changes and activates a determinate internal param, the bool becomes true and the component expires a new solution (from the eventArgs, me.expiresolution (true)). But it does not work, the input type is always numeric.

This can be done? there some trick? I'm doing something wrong?

Many thanks!!

...Sub RegisterInputParams...

If (bool) then

pManager.addTextParam...

Else

pmanager.addNumberParam...

end if

End Sub

Public bool as boolean = false

...Sub AppendAdditionalMenuItems...

... Menu_AppendItem (...,AddressOf WTF,... )...

(several)

end sub

...Sub WTF (ByVal sender As Object, ByVal e As EventArgs)...

bool = true

Me.ExpireSolution(True)

end sub

Views: 860

Replies to This Discussion

Hi Dani, couldn't you just set the parameter to "Text" and use IsNumeric(String) to determin if the input can be converted to a numerical value or not? Or did I misunderstand?

Eii Pieter, thanks for you reply.

Hmm yeah, I think that I could do that. But want to know if there is a way to change the type input in the script, the solution is more elegant...

Thanks anyway, is a solution in case of. ;)

You'll run into endless problems if you actually start switching out the parameter with a different parameter of a different type. I recommend on of these solutions:

  1. Use a Generic parameter and just retrieve IGH_Goo from inside SolveInstance, then cast to whatever type seems appropriate/is possible.
  2. Create a new parameter type which can handle both text and numeric values.

Pieter's approach is also possible, but you have to worry about the numbers getting rounded when they are converted to text, so it may not be a good idea.

Thank you very much for your reply David,
1. This means that I have to check the data type, and in case of be inadequate, providing a balloon error message? On the other hand, I could change the icon (of the type, hexagonal shape,black background...) of the input??
2. It is very difficult to do this (ok, many lines of code)? I need it for various components. This could change the input icon too?

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service