Grasshopper

algorithmic modeling for Rhino

How to pass geometry from the SolveInstance() to the DrawViewportWires()?

Hi,

I am trying to draw curves in the viewport, based on curve objects created in the SolveInstance(). I would like to use the DrawViewportWires since the method seems straight forward and allows me to use specific colors and linewidths.

Has anyone here done something similar? 
Ps: I'm creating components through visual studio.

Regards, 
Lennert

Views: 538

Replies to This Discussion

Lennert,

You can do liske follows:

private Curve datacurve;

SolveInstance()

{

    this.datacurve=......

}

DrawViewportWires()

{

    Draw(datacurve);

}

If you want to draw your own stuff in addition to the default previews, what you have to do is, conceptually (all unimportant keywords omitted):

private Collection<Geometry> _myPreviewGeometry;

private BoundingBox _myPreviewBoundingBox;

void BeforeSolution()

{

  _myPreviewGeometry.Clear();

  _myPreviewBoundingBox = BoundingBox.Empty;

}

void SolveInstance(IGH_DataAccess da)

{

  Geometry myGeometry = ...;

  _myPreviewGeometry.Add(myGeometry);

  _myPreviewBoundingBox.Union(myGeometry.BoundingBox);

}

BoundingBox ClippingBox
{
  get { return BoundingBox.Union(base.ClippingBox, _myPreviewBoundingBox); }
}

void DrawViewportWires(IGH_PreviewArgs args)

{

  base.DrawViewportWires(args);

  if (_myPreviewGeometry == null) return;

  foreach (Geometry geometry in _myPreviewGeometry)

    args.Pipeline.DrawGeometry(geometry);

}

I'll take a look at this, David. Many thanks for your quick reply. 

Of course... Thanks for the quick answer, Panda! :-)

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2025   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service