algorithmic modeling for Rhino
Hi,
I would like to draw a simple text tag in the rhino view port from within a grasshopper c# component - similar to what the native Grasshopper text tag does (red preview text in the rhino view port always oriented towards the viewer).
I have tried the following:
Rhino.Display.CustomDisplay myDis = new Rhino.Display.CustomDisplay(true);
drawTextTag(ref myDis);
// myDis.Dispose();
// <Custom additional code>
void drawTextTag(ref Rhino.Display.CustomDisplay myDis)
{
myDis.AddText("Hello", Plane.WorldXY, 2);
}
However, this does not give me what I want - eg once added the text stays in the viewport even if the component that generated it is disabled.
Can anyone provide an examples on how to create text tags like the native component does??
Thanks a lot in advance.
Tags:
thanks a bunch for your reply.
it wasnt very clear in my question but I would like to draw a text tag in the rhino view port just like the Grasshopper Tag component does.
You're better off using the display pipeline provided in the script components. Click on the eye icon in the upper right corner of the code editor to insert the overrides for drawing your own geometry. These methods will only be called if the component itself is previewing, so you don't have to worry about visible/hidden states or whether the component still exists.
--
David Rutten
david@mcneel.com
Like the attached.
--
David Rutten
david@mcneel.com
Thanks for your reply David,
could you give a short example for drawing simple text in a c# compiled component?
And here's code that adjusts for perspective shortening.
Code inside a compiled component is the same basically. Just override the DrawViewportWires method, make sure to call the base class in this case and then draw your own stuff.
--
David Rutten
david@mcneel.com
Awesome - thanks a bunch. This is super helpful.
Best,
T
Hi David, I have a followup question:
When I try a custom preview for Breps in a similar way i get an error in the display pipeline.
"An error occured in the display pipeline @ 16:31:48(659ms)"
Another issue is that when the component is deactivated the preview is still showing. (prev on/off works)
Here is the code I am using:
public override void DrawViewportWires(IGH_PreviewArgs args)
{
if (_text.Count == 0)
return;
Plane plane;
args.Viewport.GetFrustumFarPlane(out plane);
for (int i = 0; i < _text.Count; i++)
{
string text = _text[i];
Point3d point = _point[i];
plane.Origin = point;
Rhino.Display.Text3d drawText = new Rhino.Display.Text3d(text, plane, 0.5);
args.Display.Draw3dText(drawText, Color.Black);
drawText.Dispose();
}
}
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
Rhino.Display.DisplayMaterial mat = new Rhino.Display.DisplayMaterial(Color.Azure, 0.8);
for (int i = 0; i < _adjFaces.Count; i++)
{
args.Display.DrawBrepShaded(_adjFaces[i], mat);
}
}
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by