Hi, lately I been trying to create a custom Leader using the C# component in grasshopper. I I been trying to bake the geometry but Im not sure how to override the BakeGeometry Method. I was wondering if someone could guide me on how to do it…I have attached the example file I been using…Thanks!!! Leader_example.gh (5.2 KB)
1 Like
You can simply use ObjectTable.AddLeader method:
private void RunScript(List<Point3d> points, string text, double height, bool bake)
{
leader = Leader.CreateWithRichText(text, Plane.WorldXY, RhinoDocument.DimStyles[0], points.ToArray());
leader.TextHeight = height;
if (bake)
RhinoDocument.Objects.AddLeader(leader);
}
// <Custom additional code>
private Leader leader;
public override BoundingBox ClippingBox
{
get
{
return leader.GetBoundingBox(true);
}
}
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
args.Display.DrawAnnotation(leader, Color.White);
}
Leader01.gh (6.8 KB)
Or you can create your own custom bakeable Goo:
private void RunScript(List<Point3d> points, string text, double height, ref object A)
{
leader = Leader.CreateWithRichText(text, Plane.WorldXY, RhinoDocument.DimStyles[0], points.ToArray());
leader.TextHeight = height;
A = new LeaderGoo(leader);
}
// <Custom additional code>
private Leader leader;
public override BoundingBox ClippingBox
{
get
{
return leader.GetBoundingBox(true);
}
}
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
args.Display.DrawAnnotation(this.leader, Color.White);
}
public class LeaderGoo : GH_Goo<Leader>, IGH_BakeAwareData
{
public LeaderGoo(Leader leader) : base(leader) { }
public override IGH_Goo Duplicate()
{
return new LeaderGoo(Value);
}
public override bool IsValid
{
get { return Value.IsValid; }
}
public override string ToString()
{
return "Bakeable leader";
}
public override string TypeDescription
{
get { return "Leader for baking purposes."; }
}
public override string TypeName
{
get { return "LeaderGoo"; }
}
bool IGH_BakeAwareData.BakeGeometry(RhinoDoc doc, ObjectAttributes att, out Guid objGuid)
{
objGuid = Guid.Empty;
var leader = Value;
if (!leader.IsValid) return false;
if (att == null)
att = doc.CreateDefaultAttributes();
doc.Objects.AddLeader(leader, att);
return true;
}
}
Leader02.gh (4.8 KB)
3 Likes