Grasshopper

algorithmic modeling for Rhino

Hello,

I am writing a code in C# trying to extrude a surface. I am using grasshopper add-on in VS to create this component. Please see attached the error that I am getting. 

Here is the code:

using System;
using System.Drawing;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Linq;
using Rhino;
using Grasshopper.Kernel;
using Grasshopper.Getters;
using Rhino.Geometry;
using Grasshopper.Plugin;
using Grasshopper.Kernel.Types;
using Grasshopper.Kernel.Data;

protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)


pManager.AddSurfaceParameter("A", "Zone A", "Zone A Working Surface",0);

protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)


pManager.Register_SurfaceParam("Surface", "S", "Zone AA Working Surface", 0);
//pManager.AddNumberParameter("Output", "Result", "Average of differences between DIVA data & Zone A", GH_ParamAccess.item);

protected override void SolveInstance(IGH_DataAccess DA)

Rhino.Geometry.Surface zoneAsurface = null;

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

DA.SetData(0,Rhino.RhinoApp.RunScript("_ExtrudeSrf" + zoneAsurface + 1, true));

Views: 2642

Attachments:

Replies to This Discussion

This is weird:

pManager.AddSurfaceParameter("A", "Zone A", "Zone A Working Surface", 0);

you should probably use the proper enum rather than an integer.

 

Also note that a GH_Surface in fact wraps around Rhino.Geometry.Brep, not Rhino.Geometry.Surface. Surfaces in Rhino do not support trimming, whereas GH_Surface does. So when you cast a GH_Surface to a Rhino.Geometry.Surface you will lose all trimming information. Consider using GH_Surface or Rhino.Geometry.Brep instead.

 

Your problem however is the assignment:

DA.SetData(0,Rhino.RhinoApp.RunScript("_ExtrudeSrf" + zoneAsurface + 1, true));

 

RunScript does not return a surface, it returns whether the script was run successfully or not. Using Rhino commands from within Grasshopper is actually quite tricky and ought to be avoided whenever possible. Try using the Rhino.Geometry.Extrusion class instead, it provides some static methods for creating extrusion type shapes.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi David,

Thanks for your response. It worked!

I also had to update the Rhino Common.dll reference to the latest version. The old one was not giving me an option for Extrusion.

Thanks!

Naciem

Hi, I just wanted to warm up this old topic ones more.

I'trying to extrude a surface in VB but all the methods in the Extrusionclass are just for Curves ? Is it possible to just cast a Surface to a Curve or how have you done it?

Nice greets

Alex

Hi Alex,

Unfortunately, I can not find that file to review what I did with the surface extrusion. At the end, I changed my approach and used the curve extrusion. 

Attached is some sample codes for the curve extrusion in C#.

For the surface extrusion, just make sure you are using the most recent Rhino Common.dll which will give you an option for Extrusion class. That was the main issue that I had as I remember....

Also, you can select the surface edges, extrude and cap it depending on what you are after!

I hope this help!

Best,

Naciem

Attachments:

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