Hi all,
I want to creat a 3D text tag in Visual Studio ,but it seems to some happen some problems, i don’t know why my code doesn’t work, Who would like to help me?
public _3DText1()
: base("LY-3D文本", "LY-3DText",
"创建3D文本",
"LiYing", "Dimension")
{
}
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddPlaneParameter("Plane","放置面","input a plane",GH_ParamAccess.item);
pManager.AddTextParameter("Text", "文本", "input text", GH_ParamAccess.item);
pManager.AddNumberParameter("Height", "字高", "Set text height", GH_ParamAccess.item);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddTextParameter("Text", "文本", "Output text", GH_ParamAccess.item);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
GH_Plane P = new GH_Plane();
string T = "Hello!";
double H = 0;
if (!DA.GetData(0, ref P)) return;
if (!DA.GetData(1, ref T)) return;
if (!DA.GetData(2, ref H)) return;
Plane PP1 = new Plane(P.Value.Origin,P.Value.Normal);
Text3d t3d = new Text3d(T, PP1, H);
TextGoo AA = new TextGoo(t3d);
DA.SetData(0,AA);
}
public class TextGoo : GH_GeometricGoo<Text3d>, IGH_PreviewData, IGH_BakeAwareData
{
#region constructors
public TextGoo(Text3d text)
{
m_value = text;
}
private static Text3d DuplicateText3d(Text3d original)
{
if (original == null) return null;
var text = new Rhino.Display.Text3d(original.Text, original.TextPlane, original.Height)
{
Bold = original.Bold,
Italic = original.Italic,
FontFace = original.FontFace
};
return text;
}
public override IGH_GeometricGoo DuplicateGeometry()
{
return new TextGoo(DuplicateText3d(m_value));
}
#endregion
#region properties
public override string TypeName
{
get { return "3D Text"; }
}
public override string TypeDescription
{
get { return "3D Text"; }
}
public override string ToString()
{
if (m_value == null)
return "<null>";
return m_value.Text;
}
public override BoundingBox Boundingbox
{
get
{
return m_value.BoundingBox;
}
}
public override BoundingBox GetBoundingBox(Transform xform)
{
if (m_value == null)
return BoundingBox.Empty;
BoundingBox box = m_value.BoundingBox;
Point3d[] corners = xform.TransformList(box.GetCorners());
return new BoundingBox(corners);
}
#endregion
#region methods
public override IGH_GeometricGoo Transform(Transform xform)
{
var text = DuplicateText3d(m_value);
if (text == null)
return new TextGoo(null);
Plane plane = text.TextPlane;
Point3d point = plane.PointAt(1, 1);
plane.Transform(xform);
point.Transform(xform);
double dd = point.DistanceTo(plane.Origin);
text.TextPlane = plane;
text.Height *= dd / Math.Sqrt(2);
return new TextGoo(text);
}
public override IGH_GeometricGoo Morph(SpaceMorph xmorph)
{
return DuplicateGeometry();
}
#endregion
#region preview
BoundingBox IGH_PreviewData.ClippingBox
{
get { return Boundingbox; }
}
public void DrawViewportWires(GH_PreviewWireArgs args)
{
if (m_value == null)
return;
args.Pipeline.Draw3dText(m_value, args.Color);
}
public void DrawViewportMeshes(GH_PreviewMeshArgs args)
{
// Do not draw in meshing layer.
}
#endregion
#region baking
public bool BakeGeometry(RhinoDoc doc, ObjectAttributes att, out Guid id)
{
id = Guid.Empty;
if (m_value == null)
return false;
if (att == null)
att = doc.CreateDefaultAttributes();
id = doc.Objects.AddText(m_value, att);
return true;
}
#endregion
}
Hi,
I would start by changing the type of the output.
.AddTextParameter adds a string output, so your text is actually converted to a string…
Maybe use .AddGenericParameter instead ?
1 Like
I would try , thanks!