Grasshopper

algorithmic modeling for Rhino

Hi All,

I am trying to get points on surface by asking the user to input a surface, U and V values in a C# component. I think I am close but I am getting this error saying cast:int 32. If anyone has any clue why I am getting this one I would appreciate the most to share it with me. Thanks!

 

Here is my code:  

 

  

protected override void SolveInstance(IGH_DataAccess DA)

        {

           

/// 1 - Define local variables to catch the incoming data from Grasshopper

           

int myUvalue = 0;

           

int myVvalue = 0;

           

Point3d myOutPt = new Point3d();

           

Vector3d[] myOutVects = new Vector3d[0];

           

           

/// Populate local variables (and defense)

            Rhino.Geometry.

Surface myIntSrf = null;

           

if (!DA.GetData<Rhino.Geometry.Surface>(0, ref myIntSrf) || !myIntSrf.IsValid) { return; }

           

if (!DA.GetData(1, ref myUvalue)) { return; }

           

if (!DA.GetData(2, ref myVvalue)) { return; }

           

           

/// Reparameterize Surface

           

Interval Uinterval = new Interval();

           

Interval Vinterval = new Interval();

            Uinterval = myIntSrf.Domain(0);

            Vinterval = myIntSrf.Domain(1);

           

double param0 = 0.0;

           

double param1 = 0.0;

    

                   

for (int i = 0; i < myUvalue; i++)

                    {

                       param0 = Uinterval[0] + (((Uinterval[1] - Uinterval[0]) / (myUvalue - 1)) * i);

                       

for (int j = 0; j < myVvalue; j++)

                        {

                            param1 = Vinterval[0] + (((Vinterval[1] - Vinterval[0]) / (myVvalue - 1)) * j);

                            myIntSrf.Evaluate(param0, param1, myUvalue, out myOutPt,out myOutVects);

                           

                       

                        }

                      }

           

/// Populate outputs

           

///DA.SetData(0, myIntSrf);

                    DA.SetData(0, myOutPt);

           

         }

Views: 2605

Replies to This Discussion

Can you post the entire component source so I can compile it here the same way? 

Alternatively, what does the error look like? If you put a breakpoint in your SolveInstance method, at what line does the exception occur?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Sorry for the really late response I was away from my files for the whole day. David here is the whole component source. Thank you!

 

using

System;

using

System.Collections.Generic;

 

using

Grasshopper.Kernel;

using

Rhino;

using

Rhino.Commands;

using

Grasshopper.Getters;

using

Rhino.Geometry;

using

Grasshopper.Plugin;

using

Grasshopper.Kernel.Types;

using

Grasshopper.Kernel.Data;

 

namespace

Louver

{

   

public class Louver : GH_Component

    {

       

/// <summary>

       

/// Each implementation of GH_Component must provide a public

       

/// constructor without any arguments.

       

/// Category represents the Tab in which the component will appear,

       

/// Subcategory the panel. If you use non-existing tab or panel names,

       

/// new tabs/panels will automatically be created.

       

/// </summary>

       

public Louver()

            :

base("LouverGeometry", "LG",

               

"Creates Louvers from imported surface",

               

"LOUVERS", "Subcategory")

        {

        }

       

/// <summary>

       

/// Registers all the input parameters for this component.

       

/// </summary>

       

protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)

        {

            pManager.AddSurfaceParameter(

"Glazing Surface", "GS", "The surface to create Louvers on", GH_ParamAccess.item);

            pManager.AddNumberParameter(

"U value", "U", "U number of panels", GH_ParamAccess.item);

            pManager.AddNumberParameter(

"V value", "V", "V number of panels", GH_ParamAccess.item);

          

/// pManager.AddNumberParameter("Rotation of Louvers", "RL", "The desired rotation of the Louvers", GH_ParamAccess.item);

        }

       

/// <summary>

       

/// Registers all the output parameters for this component.

       

/// </summary>

       

protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)

        {

           

///pManager.Register_SurfaceParam("Louvers", "LG", "Louver Geometry", 0);

            pManager.Register_PointParam(

"Pt", "Points", "Eval Pts", GH_ParamAccess.list);

        }

       

/// <summary>

       

/// This is the method that actually does the work.

       

/// </summary>

       

/// <param name="DA">The DA object can be used to retrieve data from input parameters and

       

/// to store data in output parameters.</param>

       

protected override void SolveInstance(IGH_DataAccess DA)

        {

           

/// 1 - Define local variables to catch the incoming data from Grasshopper

           

int myUvalue = 0;

           

int myVvalue = 0;

           

Point3d myOutPt = new Point3d();

           

Vector3d[] myOutVects = new Vector3d[0];

           

           

/// Populate local variables (and defense)

            Rhino.Geometry.

Surface myIntSrf = null;

           

if (!DA.GetData<Rhino.Geometry.Surface>(0, ref myIntSrf) || !myIntSrf.IsValid) { return; }

           

if (!DA.GetData(1, ref myUvalue)) { return; }

           

if (!DA.GetData(2, ref myVvalue)) { return; }

           

           

/// Reparameterize Surface

           

Interval Uinterval = new Interval();

           

Interval Vinterval = new Interval();

            Uinterval = myIntSrf.Domain(0);

            Vinterval = myIntSrf.Domain(1);

           

double param0 = 0.0;

           

double param1 = 0.0;

    

                   

for (int i = 0; i < myUvalue; i++)

                    {

                       param0 = Uinterval[0] + (((Uinterval[1] - Uinterval[0]) / (myUvalue - 1)) * i);

                       

for (int j = 0; j < myVvalue; j++)

                        {

                            param1 = Vinterval[0] + (((Vinterval[1] - Vinterval[0]) / (myVvalue - 1)) * j);

                            myIntSrf.Evaluate(param0, param1, myUvalue,

out myOutPt,out myOutVects);

                           

                       

                        }

                   

              

                   

                   

                     }

           

/// Populate outputs

           

///DA.SetData(0, myIntSrf);

                    DA.SetData(0, myOutPt);

           

         }

           

          

        

              

       

       

/// <summary>

       

/// Provides an Icon for every component that will be visible in the User Interface.

       

/// Icons need to be 24x24 pixels.

       

/// </summary>

       

protected override System.Drawing.Bitmap Icon

        {

           

get

            {

               

I fixed the cast: int error message by changing the pManager.AddNumberParameter to pManager.AddIntegerParameter. But I still need to fine tune it as I am not getting the evaluation points out.

There were several weird things in that file. I attached a cs file that seems to do what you're after.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

Thank you David an apologies for the weirdness. I am new to C#...Thanks again!

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