Grasshopper

algorithmic modeling for Rhino

Hi, I’m trying to preview data from a custom class I’ve written. However, as soon as I include it in my code, Grasshopper just freezes up (it goes pale white, similar to the behavior when calling an infinite loop). Here’s what I’m doing:

The custom class I derive from GH_Goo<object> and I make it inherit from IGH_PreviewObject. I override IsPreviewCapable, ClippingBox, Hidden, DrawViewportWires and I create some PreviewArgs from some lines created by the class, as shown in the code below.

In my component I then call DrawViewportWires and pass the PreviewArgs I created in the class. Is that the right thing to do?

    public class CustomClass : GH_Goo<object>, IGH_PreviewObject

    {

 

//GH_Goo stuff

//Custom Class stuff

 

        bool IGH_PreviewObject.IsPreviewCapable

        {

            get { return true; }

        }

        private BoundingBox boundingBox;

        private BoundingBox BoundingBox

        {

            get

            {

                List<Point3d> ptsPreview = new List<Point3d>();

                //add points to list

foreach (Point3d pt in pts) { ptsPreview.Add(pt); }

                boundingBox = new BoundingBox(ptsPreview);

                return boundingBox;

            }

        }

        BoundingBox IGH_PreviewObject.ClippingBox

        {

            get { return BoundingBox; }

        }

        bool IGH_PreviewObject.Hidden

        {

            get

            {

                return false;

            }

            set

            {

                //…

            }

        }

        void IGH_PreviewObject.DrawViewportWires(IGH_PreviewArgs ArgsWires)

        {

            //base.DrawViewportWires(ArgsWires); -what’s base with GH_Goo<object>?

            ArgsWires.Display.DrawLines(PreviewLines, Color.Red);

        }

        void IGH_PreviewObject.DrawViewportMeshes(IGH_PreviewArgs ArgsMeshes)

        {

            //base.DrawViewportWires(ArgsMeshes); -what’s base with GH_Goo<object>?

        }

        public IGH_PreviewArgs ArgsWires

        {

            get

            {

                ArgsWires.Display.DrawLines(PreviewLines, ArgsWires.WireColour);

                return ArgsWires;

            }

        }

        private List<Line> previewLines;

        public List<Line> PreviewLines

        {

            get

            {

                previewLines = new List<Line>();

                foreach (Line l in lines) { previewLines.Add(l); }

                return previewLines;

            }

        }

}

In the component which uses the class, I then call

CustomClass cl = new CustomClass();         

DrawViewportWires(cl.Args);

 

I’ve also tried 

cl.DrawViewportWires(cl.ArgsWires);

but I get the same error.

Also, I’ve tried putting all of the IGH_PreviewObject stuff into the component and collecting the “previewLines” in SolveInstance, which didn’t cause Grasshopper to freeze, but didn’t display anything either. Any help/pointers in the right direction would be greatly appreciated! Thanks, Daniel

 

Views: 1396

Replies to This Discussion

Hi Daniel,

IGH_PreviewObject is for things like Components and Parameters, IGH_PreviewData is for IGH_Goo derived types. If you put a class that implements IGH_Goo and IGH_PreviewData inside a Generic parameter, it will display. If you make your own parameter that specifically handles your own goo, then that parameter will need to implement IGH_PreviewObject.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

oh I see, cool. It seems to work! Nice, simple, magic. Thanks, David!

public class CustomClass: GH_Goo<object>, IGH_PreviewData
{

BoundingBox IGH_PreviewData.ClippingBox
{
get { return BoundingBox; }
}

void IGH_PreviewData.DrawViewportWires(Rhino.Display.RhinoViewport vp, Rhino.Display.DisplayPipeline pl, System.Drawing.Color col, int i)
{
pl.DrawLines(PreviewLines, col);
}

void IGH_PreviewData.DrawViewportMeshes(Rhino.Display.RhinoViewport vp, Rhino.Display.DisplayPipeline pl, Rhino.Display.DisplayMaterial mat)
{

//no shaded preview for this type of object
}

}

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service