Grasshopper

algorithmic modeling for Rhino

Registering input parameters and passing the to SolveInstance

Hello!

I'm working my way though creating a component and I'm stuck on passing the registered input parameters to the solve instance function. The problem is while assigning an input surface. I undertsnd that the type Surface is protected so do I need to use Rhino.DocObjects.SurfaceObject? if so how do I use it?

the  code below and the VS project attached:

 

Many thanks in advance!

Evert

 

///

Registers all the input parameters for this component.

       /// </summary>

       protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)

        {

            pManager.AddBrepParameter(

"Surface", "S", "Surface to generate the grid onto",0);

            pManager.AddIntegerParameter(

"Hexagrid.Ux", "Ux", "Number of grid cells in U direction", 0);

            pManager.AddIntegerParameter(

"Hexagrid.Uy", "Uy", "Number of grid cells in V direction", 0);

        }

       /// <summary>

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

       /// </summary>

       protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)

        {

            pManager.Register_CurveParam(

"HexagridOnSrf.C", "C", "Grid Cell Outlines");

            pManager.Register_PointParam(

"HexagridOnSrf.P", "P", "Points at grid centres");

        }

       /// <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)

        {

           

//We begin by performing a series of checks

            

Surface S = new Surface();          

if (!DA.GetData(0, ref S))               

return;

           Int32 Ex = 1;           

if (!DA.GetData(1, ref Ex))

               return;

           Int32 Ey = 1;

           if (!DA.GetData(1, ref Ey))

               return;

 

 

Views: 1774

Attachments:

Replies to This Discussion

as I heard... user can not create type surface. try to use brep.

(you can use created surface but not create surface yourself)

also, there are some GH Plugins, that create HexGrid on Surface.

check it together :)

http://www.food4rhino.com/project/somnium-gh

http://www.food4rhino.com/project/lunchbox

Hi Kwon!

Thanks for replying, it appears that Brep as a type is also protected, I just want to pass the referenced surface to the SolveInstance.

I know about the hexagrid components in those add-onns, it's just that I've got the code in a CSharp scripting component and want to learn to create a GHA. 8)

Cheers

Evert

did you tried...

Surface S = new Surface(); 
 

to

Brep S = new Brep();

and doesn't it work?

Register a surface collection parameter with this:

pManager.Register_SurfaceParam("Surface", "S", "Surface to generate the grid onto",0);

 

In the solve method, try something like this:

GH_Surface ghsurface = null;
if (!DA.GetData<GH_Surface>(0, ref ghsurface) || !ghsurface.IsValid)
   return;
Surface s = ghsurface.Value;

Hope it helps.

Jon

 

Hi Jon,

Thanks for that, I've got  GH_IO, GH_Util, Grasshopper and Rhinocommon dlls referenced and have declared these directives:

using System;

using System.Collections.Generic;

using Grasshopper.Getters;

using Grasshopper.Plugin;

using Grasshopper.Kernel;

using Rhino.Geometry;

 But there is an error that the type GH_Surface could not be found, Am I missing something else?

Thanks again


Evert

 

 

Add

using Grasshopper.Kernel.Types;

Hi Jon,  Thanks for the hint. In the end I needed to cast it and used:

GH_Surface ghsurface = null;

if (!DA.GetData/font>GH_Surface>(0, ref ghsurface) || !ghsurface.IsValid)           

return;         

Surface S = null;

 ghsurface.CastTo(out S);

 

Cheers

Evert

Hi Evert,

I am having the same problem you had with inputting a surface.

Did you use this as your input line? pManager.Register_SurfaceParam("Surface", "S", "Surface to generate the grid onto",0);

I have all the references and the directives as you posted here except GH_Util.

The problem that I am having now is the "Register_SurfaceParam" can not be found. Do you think this is because of missing GH_Util reference? If yes, how can I reference this?

I tried "using Grasshopper.Kernel.Utility;" and still not finding "Register_SurfaceParam"!!!

Also, I would greatly appreciate it if you can share your code.

 

Thanks,

 

Naciem

 

 

Hi Naciem,

you'll need Grasshopper.Kernel.DataTypes,  I haven't got my pc here to check what I wrote, sorry!

I'll post the code a bit later!

Cheers

Evert

Hi Evert,

I realized what I was doing wrong and it's working now.

Thanks for your response though!

Naciem

Jon,

 

I'm getting an error when I try to import my own class objects (e.g.I_Model_NodeSupport). Do you know how to handle these?

 

Cheers.

 

   

Protected Overrides Sub RegisterInputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_InputParamManager)

        pManager.AddTextParameter(

"Name", "N", "String", GH_ParamAccess.item)

pManager.AddPointParameter(

"Point", "P", "Point3d", GH_ParamAccess.item)

        pManager.AddGenericParameter(

"Local Axis", "LA", "Null/Surface/Plane", GH_ParamAccess.item)

        pManager.AddGenericParameter(

"Support", "S", "I_Model_Support", GH_ParamAccess.item)

        pManager.AddGenericParameter(

"PointLoad", "PL", "List (of I_Model_PointLoad)", GH_ParamAccess.list)

        pManager.AddGenericParameter(

"Group", "G", "List (of (I_Model_Group)", GH_ParamAccess.list)

   

End Sub

   

Protected Overrides Sub RegisterOutputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_OutputParamManager)

        pManager.AddGenericParameter(

"Node", "N", "I_Model_Node",GH_ParamAccess.item)

   

End Sub

   

Protected Overrides Sub SolveInstance(ByVal DA As Grasshopper.Kernel.IGH_DataAccess)

       

Dim inName As String = Nothing

       

Dim inP As Point3d = Nothing

       

Dim inLA As Plane = Nothing

       

Dim inS As I_Model.I_Model_NodeSupport = Nothing

       

Dim inPL As New List(Of I_Model.I_Model_PointLoad)

       

Dim inG As New List(Of I_Model.I_Model_Group)

       

Dim outNode As I_Model.I_Model_Node

       

If Not DA.GetData(0, inName) Then Return

       

If Not DA.GetData(1, inP) Then Return

       

If Not DA.GetData(2, inLA) Then Return

       

If Not DA.GetData(3, inS) Then Return

       

If Not DA.GetData(4, inPL) Then Return

       

If Not DA.GetData(5, inG) Then Return

       

Dim IM_P As I_Model_Node

        IM_P =

New I_Model_Node(inP, Nothing, inName)

       

If Not DA.GetData(2, inLA) Then IM_P.SetLocalAxis(inLA)

       

If Not DA.GetData(3, inS) Then IM_P.SetSupport(inS)

       

If Not DA.GetData(4, inPL) Then

           

Dim PL As I_Model_PointLoad

           

For Each PL In inPL

                IM_P.AddPointLoad(PL)

           

Next

       

End If

       

If Not DA.GetData(5, inG) Then

           

Dim G As I_Model_Group

           

For Each G In inG

                IM_P.AddToGroup(G)

           

Next

       

End If

        outNode = IM_P

        DA.SetData(0, outNode)

   

End Sub

Hi, Nope!

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