Grasshopper

algorithmic modeling for Rhino

I am trying to understand this error message I am getting:

http://puu.sh/6o6wO/dacc17980f.png

The error message: "1. Invalid cast: Number » Single"

Relevant code snippets:

In RegisterInputParams:

pManager.AddNumberParameter("", "", "", GH_ParamAccess.item, 0.0f);

pManager[7].Optional = true;

SolveInstance var declaration and usage:

float xPosTime = 0.0f;
DA.GetData(7, ref xPosTime);

HeatMap map = new HeatMap(...., xPosTime);

Views: 1622

Replies to This Discussion

pManager.AddNumberParameter("", "", "", GH_ParamAccess.item, 0.0f);

when you append an 'f' to a number, it turns it into a single precision floating point number. The Number parameter uses double precision numbers. Get rid of the f and it should work.

--

David Rutten

david@mcneel.com

Don't use floats at all would be my suggestion. The only time when you actually need them is when you are doing floating point graphics stuff, which is often only single precision.

--

David Rutten

david@mcneel.com

But those floats will only exist within your SolveInstance function, you should not output them or input them.

--

David Rutten

david@mcneel.com

someFloatValue can be either a float or a double. If it's a double, you have to convert the argument to DrawString into a float first.

If you input a double for offsetting, my recommendation is thus:

in RegisterInputParams:

  pManager.AddNumberParameter("Text Offset", "O", "blh", 0.0);

in SolveInstance:

  double textOffset;

  DA.GetData(?, textOffset);

  float offset = Convert.ToSingle(textOffset);

  ...

  DrawString(..., X + offset);

--

David Rutten

david@mcneel.com

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