Grasshopper

algorithmic modeling for Rhino

Hi all,

I have a component, from a plug-in, that outputs a list of ScriptVariable values.
I am trying to cast these values to double's, which they are, but with no luck.
Is there a way to cast Variable's using plain GH components ?

Cheers
Emilio

Views: 709

Replies to This Discussion

Emilio,

I'm a bit confused. You're outputting a list of GH_Variant instances and they won't convert themselves to Doubles/Points/Integers/Strings when you plug them into a Number/Point/Integer/String parameter respectively?

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Sorry, David ...
I just reopened Rhino, loaded GH and the definition works. :|
Forgot to try that before.

Since I've already disturbed you, I'm going to ask
a different question:
The component that outputs the list is defined by a
plug-in and its class is derived from GH_Param.
( I learnt that looking at CurvePoint, as you
told me to do )
I think deriving from GH_Param is fine: the component
'frame' is already there and most of the work has to do
with the GH_Attributes.
But I think GH_Param can only have one input parameter
and one output parameter.
Which class should I derive my class from to be
able to use more in/out parameters, still
being able to set up a custom GH_Attributes ?

Thanks !
Cheers
Emilio
Hi Emilio,

you're right, anything that derives from IGH_Param only supports a single input and a single output. In fact IGH_Attributes only allows for a single input and a single output. Components solve this somewhat differently, the Component Attribute class doesn't have any inputs/outputs at all, but it manages a set of parameter attributes. So when you drag the component, it in turn drags the input and output parameters along as well.

This requires quite a bit of layout and event-handling. Is there any way you can use a GH_Component instead of a GH_Param? If not, can you tell me exactly what it is you need, I can probably refactor the Component attributes to be more generic. I just haven't done this recently since there was no need for it.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hi David,

actually, I have no need (for now) of that multi-param component.
The GH_Param does what I need.
I might need the complex one in the future, I don't knot yet ...
I just thought to investigate a bit to learn how to build that
kind of thing ... and to learn something more about GH.

To try to clarify: I am talking about a component that I can double-click
to make it show a Form, in practice some kind of graphical interface
for a GH definition. The Form lets the user set some values and then
confirm, so that the component outputs its value(s)
(My GH_Param thing already does that)
But that component should also be able to use more input and/or output parameters.
GH_Parameter is fine for parameter handling, but I think its output
cannot be handled by the Form, am I right ?
If that is possible ... good, problem solved. :)

Anyway, don't worry, I don't need it now.
Should I need that in the future, I'll let you know. ;)

Thanks !
Emilio
Ah ok, that's pretty easy. If you just want to override the DoubleClick event on a box-standard component you need to:

1. Create a new class which derives from Kernel.Attributes.GH_ComponentAttributes
2. Override RespondToMouseDoubleClick() and do your form logic in there.
3. Override the CreateAttributes() method on your GH_Component derived class and return your new special attributes instead.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Ah !
Good to know. :)
I'll try to rewrite the plug-in that way.

Thanks a lot !
Cheers
Emilio
Hi David,

I've tried to derive a class from GH_ComponentAttributes,
but I get this error message:

gui.cs(83,16): error CS1501: No overload for method 'GH_ComponentAttributes' takes '0' arguments
c:\Programmi\Rhinoceros 4.0\Plug-ins\Grasshopper\Grasshopper.dll: (Location of symbol related to previous error)

I'm not able to understand what that means ... sorry.
(I cannot find the GH_ComponentAttributes class in the help file)

What am I doing wrong (or not doing at all) ?

Thanks
Emilio
Emilio,

the GH_ComponentAttributes class has a single constructor which takes a single instance that derives from GH_Component. Are you calling this costructor from your constructor?

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Ah, OK, thanks for the info.
The constructor works fine now.

But I haven't found the way to control the
component output from the Form.
(Clicking a button should make the component output its result)
When using GH_Param, overriding CollectVolatileData_Custom()
worked fine.
Is there a correspondent method in GH_Component ?
(BTW, I see no m_data field in GH_Component, so I
also would not know how to build the result... )

Or should I call some method to exec SolveInstance() ?
It seems that ExpireSolution() does not do that... Should it ?

Thanks
Emilio
Hi Emilio,

apologies for the slow responses, I'm doing a lot of personal stuff this week.

GH_Component does not have an m_data field. Every parameter that belongs to a Component has an m_data field, but I don't think you want to access those directly.

It sounds like you need to add additional fields to your Component which get accessed from within your SolveInstance method. You can assign them via the form or via some other way.

When you call ExpireSolution(true), it should destroy all volatile data of the component output parameters + all downstream objects, then recompute all those objects.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thanks for your response,
but don't worry. No hurry about that,
I too have other things to do.

.. Also, _I_ should apologize, because the component
works fine, I simply forgot to set the input parameters,
which were not used in my simple test.

Thank you David !
Cheers
Emilio

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service