Snap Grasshopper Preview

What would be the way or methodology to script a grasshopper component that outputs a geometry and user could snap to it?

I know that there is selectable preview plugin for grasshopper.

But I just want to output few polylines, that will allways stay as it is, and their coordinates are manually written inside component.

Do I need somehow to fake it ?
Like Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline();
and then lock it?

What would be a process using code?
If the component is refreshed is it being bake twice?
Or is it is added to new layer that is cleaned every time objects are baked and locked?

I know Anders Holden Deleuran this type of thingy for bendy stuff, I am wondering what is the process behind.
From second 4 to 7:

why don’t you just use a bake plugin? just set it to bake continuously.

Or use the Geometry Cache to bake (and replace) on demand. It won’t lock the baked geometry but you can snap to it.

Dear David,

Thank you for a reply.

How Geometry Cache works?
Is it possible to have a sample how to use Geometry Cache within C#?

No, it’s a UI object that is not readily callable from C# code.

The cache works by baking geometry to the current 3dm file along with some user data that identifies it as both a cache-baked object and also it’s position within the original data tree. The former data allows the cache to delete the old geometry before baking new one, and the latter data allows the cache to recreate a datatree from the objects in case you want to insert a manual editing step in between.

Here’s an example of the cache, note that you must assign a name to a cache to make it work: cache.gh (4.4 KB)

Just drag the slider, then click on the cache bake button to update the circles in the Rhino file.

3 Likes

Geometry Cache would be a LOT more useful if there were a way to specify a layer to bake to.

1 Like

Is there any way to bake objects using geometry cache without pressing bake button? (Moving slider and automatically baking)

1 Like

No it requires manual interaction. There’s a lot goes on in Rhino when you add/delete/replace objects, not least the creation of loads of undo records, so I’ve been shying away from automatic baking.

What would be a drawback if I would just bake a curve like this upon each iteration I would delete object with the same name:

if(toggle){

  Guid id = Guid.Empty;
  foreach(Rhino.DocObjects.RhinoObject ob in Rhino.RhinoDoc.ActiveDoc.Objects){
    if(ob.Name == "myCrv"){
      id = ob.Id;
    }
  }

  if(id != Guid.Empty){
    doc.Objects.Delete(id, false);
  }
  Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes();
  att.Name = "myCrv";

  doc.Objects.AddCurve(curves[0], att);

}

Nothing, if you don’t mind getting 500 extra undo record when you drag a slider.

3 Likes