Grasshopper

algorithmic modeling for Rhino

Hello everybody,

 

I am trying to debug a Visual Studio 2010 project to Rhino 5 just to give it a try but nothing happens and I do not find the answer.

 

I have made a class in Visual Studio 2010, referrenced RhinoCommon.dll (with copy local False :-)) and then set in the debug options, Start Action, Start external program and referenced the Rhino.exe file in Rhinoceros 5.0 WIP (64-bit) folder.

 

I tried the following code from McNeel´s developers wiki (add a cylinder) and I get no errors neither building the solution nor debugging in VS2010 but, after Rhino starts, nothing happens in Rhino and there is no geometry:


using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rhino;
using Rhino.Geometry;

namespace MyFirstRhinoDrawing
{
    class Class1
    {
        Rhino.Commands.Result cil = AddCylinder(RhinoDoc.ActiveDoc);

    public static Rhino.Commands.Result AddCylinder(Rhino.RhinoDoc doc)
    {
      Rhino.Geometry.Point3d center_point = new Rhino.Geometry.Point3d(0, 0, 0);
      Rhino.Geometry.Point3d height_point = new Rhino.Geometry.Point3d(0, 0, 10);
      Rhino.Geometry.Vector3d zaxis = height_point - center_point;
      Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(center_point, zaxis);
      double radius = 5;
      Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(plane, radius);
      Rhino.Geometry.Cylinder cylinder = new Rhino.Geometry.Cylinder(circle, zaxis.Length);
      Rhino.Geometry.Brep brep = cylinder.ToBrep(true, true);
      if (brep != null)
      {
        doc.Objects.AddBrep(brep);
        doc.Views.Redraw();
      }
      return Rhino.Commands.Result.Success;
    }


}
}

 




 

Any help would be much appreciated. Thanks in advance.

 

Cheers!

 

 

P.S. May not be a question for the GH forum but I did not know where to post it! :-)

Views: 3025

Replies to This Discussion

AFAIK you can't debug a gha against Rhino5.  The reason being is that GH is developed against .Net 3.5, so when a 4.0 assembly is loaded, GH can't hit the debug symbols.  VS2010 can debug ghas, you just have to run them against Rhino 4.

Who's calling this code? Do you have a command defined anywhere?

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi Damien and David,

 

Damien, I think you can debug against Rhino5. At least, that´s what Giulio did in a workshop I attended some time ago. Anyway, that was with an early version of Rhino5 and I am not sure if it´s possible right now.

 

I thoght I was missing a constructor in the example I posted and changed the code to:

 

using System.Text;
using Rhino;
using Rhino.Geometry;

namespace MiFirstRhinoDrawing
{

    class Class1
    {
     Rhino.Commands.Result cil = new Rhino.Commands.Result();

    public Class1()
    {
        cil = AddCylinder(RhinoDoc.ActiveDoc);
    }


   
    public static Rhino.Commands.Result AddCylinder(Rhino.RhinoDoc doc)
    {
    }
  }
}

(and then the function AddCylinder)

 

I added another class in the same namespace to call the first one as well:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rhino;

namespace MiFirstRhinoDrawing
{
    class Class2
    {
        static void Main()
        {
            Class1 example = new Class1();
        }
       
    }
}

 

That is what I understood from David´s reply but again Rhino doesn´t draw anything. I don´t know whether I am going in the right direction!

 

Thanks for your help, I am fairly new to programming environments such as VS.

 

Cheers!

You need to create a Command class. Then when you type the command name in the command line, Rhino will call your code and then you should be able to hit breakpoints.

 

But I still can't see from this code who is responsible for actually calling the code you wrote. Maybe it's best if you post your entire visual studio project (as a Zip file), so I can see all of it on my machine.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

You can debug both grasshopper components and Rhino plug-ins in Rhino 5.  Debugging these will require Visual Studio 2010 since earlier version of VS do not know anything about .NET 4.

 

Miguel,

It looks like you are attempting to take a sample on the wiki like

http://wiki.mcneel.com/developer/rhinocommonsamples/addtorus

and convert it into a runnable plug-in command.  The easiest way to create a plug-in and commands it to use the Visual Studio project and command templates (it can be done manually, but why bother;)).  I'm actually in the process of updating these templates and should have something for you within the next couple of days.

 

I'll post a message here when I have something that you can use.

 

Thanks,

-Steve

Thanks, Steve, it would be really helpful!

Sure, David

 

There it goes.

 

Many thanks!

:-)

Attachments:

Actually, I managed creating and calling my own class in GH´s script component but I couldn´t in VS!

 

I am posting a sample code in case sombebody could find it useful:

 



private void RunScript(Point3d x, object y, ref object A, ref object B)
  {
    MyBox hello = new MyBox();
    A = hello.Construir(x);
    B = hello.volumen;
    Print((hello.Construir(x).Volume).ToString());
  }

  //<Custom additional code>
  public class MyBox
  {
    Box box = new Box();

    //// Members
    // properties
    public double volumen
    {
      get{return box.Volume;}
      set{box = new Box();}
    }

    // method
    public Rhino.Geometry.Box Construir(Point3d pto)
    {
      box = new Box(new Plane(pto, Vector3d.XAxis, Vector3d.YAxis), new Interval(-5, 5), new Interval(-5, 5), new Interval(0, 15));
      return box;
    }

    // constructor
    public MyBox()
    {
    }
  }

That works because Grasshopper calls RunScript at the appropriate time. It's easier to write small algorithms as Grasshopper Scripts because you don't have to deal with the whole command and plugin overhead. You don't have to worry about writing data prompts and pickers and so on, it's all taken care of by Grasshopper.

 

If you're going to write Rhino commands, you'll need to do these things yourself. It's not terribly involved, it's just a little bit of extra typing but you need to know how.

 

It should all be much easier with the plugin wizards Steve said he's going to write.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Ok, David, looking forward to see Steve´s setup!

My apologies, I read too quick.  My response was about GHAs specifically.  A regular Rhino plugin debugs just fine with Rhino 5 and VS 2010.

 

I currently can't open up the rar you posted, but I would recommend looking at the csproj file. In the csproj file make sure that the RhinoCommon dll that's being pointed to is the one in the Rhino 5 directory.  I don't know if the one that GH ships to work with Rhino 4 is compiled any differently then the one that ships with Rhino 5, but that could be the culprit.

Hi Damien,

You can definitely debug ghas under Rhino 5 / VS2010.  It also doesn't matter which RhinoCommon you target for the compile.

Thanks,

-Steve

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