Grasshopper

algorithmic modeling for Rhino

Hi all,

 

I recently upgraded from an older version of GH to 0.8.0004 in R4. After updating my C# code (adding the GH_ParamAccess types and replacing the 'out' by 'ref' in the retrieving input data command) I encountered some issues.

 

Although this piece of code worked before with the 'out' keyword

 

//input variables                   
OnSurface inputSurface;            

//set input data           
if (!DA.GetData<OnSurface>(0, ref inputSurface)) { return; }

 

after updating the code, the general error 'Use of unassinged local variable 'inputSurface'' is generated.

 

By assigning the inputSurface as follows

 

//input variables                   
OnSurface inputSurface = new OnNurbsSurface();

 

the code does run, but in GH the component gives the error 'Invalid cast: GH Surface >> OnSurface. The same happens if I initialise the inputSurface as

 

OnNurbsSurface inputSurface = new OnNurbsSurface();

 

I've also added the RhinoCommon reference because of the error: The type 'Rhino.Geometry.Vector3d' is defined in an assembly that is not referenced. You must add a reference to assembly 'RhinoCommon, Version=5.0.15005.0'.

 

Might it be that the RhinoCommon and the SDK are interfering?

 

I was hoping someone could let me know how to resolve this.

 

Regards,

 

Roel.

 

Views: 2201

Replies to This Discussion

Hi Roel,

 

it cannot be OnSurface, classes that start with "IOn", "On", "MRhino" and "IRhino" are part of the old SDK. GH 0.8 uses RhinoCommon which has different class and interface names. You need to ditch your assembly reference to Rhino_DotNET and only use RhinoCommon classes. So instead of RMA.OpenNurbs.OnSurface, you need to switch to Rhino.Geometry.Surface or Rhino.Geometry.Brep.

 

When a parameter is passed using the out keyword, the function that you're calling promises to fill out the data in every case (or throw an exception). Therefore you can pass a newly declared but not instantiated value into a function using an out parameter. The same is not true for ref parameters. You need to specifically assign a value to the inputSurface variable for the compiler to accept this code. This value can be null however. So:

 

Surface inputSurface = null;

 

Should do the trick. 

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks David,

 

however that did not solve problem; still getting the error 'Invalid cast: GH Surface >> OnSurface.

 

Is that because I can't use the SDK class and interface names, such as OnSurface in GH 0.8? Does that mean that 1) I have to rewrite the code following the RhinoCommon naming, remove the SDK references and add the RhinoCommon reference or 2) go back to GH 0.6 or 0.7?

 

Regards, Roel.

Yes. 

 

"it cannot be OnSurface, classes that start with "IOn", "On", "MRhino" and "IRhino" are part of the old SDK. GH 0.8 uses RhinoCommon which has different class and interface names. You need to ditch your assembly reference to Rhino_DotNET and only use RhinoCommon classes. So instead of RMA.OpenNurbs.OnSurface, you need to switch to Rhino.Geometry.Surface or Rhino.Geometry.Brep."

 

You could go back to 0.6 as well, but that doesn't sound like a good long-term strategy.

 

Rip out your reference to Rhino_DotNET.dll, rename all the classes that have disappeared (such as OnSurface), and then fix the function calls that have changed.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks again David. I will go through the documentation at http://wiki.mcneel.com/developer/rhinocommon and try to update the code.

 

Regards, Roel.

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