Hi,
I try to get my head around display conduits. For testing I wrote some simple code in a c# node, that displays 3d text. The problem is, that the display never gets redrawn. Every time i trigger the code new text is added, but it never disappears.
Thanks for any answer.
Best M.
MyConduit myConduit = new MyConduit();
Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc;
if(run){
for(int i = 0;i < plns.BranchCount;i++){
GH_Path p = plns.Paths[i];
for(int j = 0;j < plns.Branch(i).Count;j++){
if(plns[p, j] == null)continue;
Rhino.Display.Text3d txt = new Rhino.Display.Text3d("test", plns[p, j], s);
txt.VerticalAlignment = Rhino.DocObjects.TextVerticalAlignment.Middle;
txt.HorizontalAlignment = Rhino.DocObjects.TextHorizontalAlignment.Center;
txt.FontFace = "Arial";
myConduit.Add(txt);
}
}
myConduit.Enabled = true;
doc.Views.Redraw();
}
else{
myConduit.Enabled = false;
myConduit = null;
doc.Views.Redraw();
}
class MyConduit : Rhino.Display.DisplayConduit
{
private List<Rhino.Display.Text3d> lsText;
public MyConduit(){
this.lsText = new List<Rhino.Display.Text3d>();
}
public void Add(Rhino.Display.Text3d txt){
this.lsText.Add(txt);
}
public void Clear(){
this.lsText.Clear();
}
protected override void CalculateBoundingBox(Rhino.Display.CalculateBoundingBoxEventArgs e)
{
base.CalculateBoundingBox(e);
foreach(Rhino.Display.Text3d txt in this.lsText){
e.IncludeBoundingBox(txt.BoundingBox);
}
}
protected override void DrawForeground(Rhino.Display.DrawEventArgs e)
{
foreach(Rhino.Display.Text3d txt in this.lsText){
e.Display.Draw3dText(txt, System.Drawing.Color.Green);
}
}
}