algorithmic modeling for Rhino
Hi,
I am trying to create custom parameter and data. I found some pieces of thing on the forum that help me to create my parameter but now I have an error message that I can't solve:
"Error 1 The type 'TEST.SomeStuffs' cannot be used as type parameter 'T' in the generic type or method 'Grasshopper.Kernel.GH_Param<T>'. There is no implicit reference conversion from 'TEST.SomeStuffs' to 'Grasshopper.Kernel.Types.IGH_Goo'. C:\...\SomeStuffs.cs"
I am wondering if I am on the right way...
Also is it better to inherit my custom parameter from GH_Param or GH_PersistentData ?
Attached are my classes.
Any help will be very appreciated .
thanks
Tags:
The GH_Param class requires that "T" implement the IGH_Goo. Since TEST.SomeStuffs is only inheriting from System.Object (implicitly, as all objects do), there's no implementation of IGH_Goo, and therefore can't be used as "T".
I'd suggest inheriting from GH_Goo, since that will take care of implementing the IGH_Goo interface for you. If you feel the need to provide some specific behavior that IGH_Goo specifies, then you can override a method/property as needed. If you've got another class that you're looking to actually inherit from, then you can handle implementing the IGH_Goo interface yourself.
Hi Damien,
I decided to inherit from GH_GOO<object>
public class SomeStuffs : Grasshopper.Kernel.Types.GH_Goo<object> {}
I need to spend a bit more time to well understand all that process but it seems to work.
thanks.
Hi raf,
data needs to have certain functionality before it can be used inside a Grasshopper file. IGH_Goo (and the GH_Goo abstract class) define this functionality. For example, data needs to be copyable and it needs to know how to convert itself from/to other types of data.
Let's say that you have a simple data type that combines a point and an integer:
public struct PointIndexData
{
public Point3d Point;
public int Index;
}
It doesn't really matter whether it's a class or a struct. Once you have your data type you can 'wrap' it up in goo in order to make it Grasshopper compliant:
public class PointIndexGHData : GH_Goo<PointIndexData>
{
//...
}
At this point you'll need to implement the 5 abstract methods that are not implemented by GH_Goo<T>. They might look something like this:
public class PointIndexGHData : GH_Goo<PointIndexData>
{
public override IGH_Goo Duplicate()
{
PointIndexGHData dup = new PointIndexGHData();
dup.Value = Value;
return dup;
}public override bool IsValid
{
get { return Value.Index >= 0; }
}public override string ToString()
{
return string.Format("{0} [{1}]", Value.Point, Value.Index);
}public override string TypeDescription
{
get { return "Points and Integers, living in perfect harmony"; }
}public override string TypeName
{
get { return "IndexPoint"; }
}
}
You'll probably also want to override the CastFrom and CastTo methods so that your data can easily be used by any component which takes in simple points or integers, and -in this case- you want your data to also implement the Grasshopper.Kernel.IGH_PreviewData interface as this data can -and should- be displayed in the Rhino viewports.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hi David,
In the SolveINstance which type should be returned
PointIndexData or PointIndexGHData.
I have similar thing to deal with and thanks to your hints in blog I've reached to the point I have to assign data to my custom result parameter to give it to setdata.
with mybase class it turns red in grasshopper and with the GHParam i can not assign data.
SolveInstance doesn't return any type, but for DA.SetData() you can probably use both, provided you've set up your Cast functions correctly.
Typically it's fastest if you provide the actual IGH_Goo implemented type, but I rarely do that. I typically just assign Point3d or int or Brep instead of GH_Point, GH_Integer and GH_Brep.
--
David Rutten
david@mcneel.com
Seattle, WA
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by