Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using System;
using System.Collections;
using System.Collections.Generic;
using Rhino;
using Rhino.Geometry;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
using Rhino.Display;
using Rhino.DocObjects;
using System.Drawing;
/// <summary>
/// This class will be instantiated on demand by the Script component.
/// </summary>
public class Script_Instance : GH_ScriptInstance
#region Utility functions
/// <summary>Print a String to the [Out] Parameter of the Script component.</summary>
/// <param name="text">String to print.</param>
private void Print(string text) { /* Implementation hidden. */ }
/// <summary>Print a formatted String to the [Out] Parameter of the Script component.</summary>
/// <param name="format">String format.</param>
/// <param name="args">Formatting parameters.</param>
private void Print(string format, params object[] args) { /* Implementation hidden. */ }
/// <summary>Print useful information about an object instance to the [Out] Parameter of the Script component. </summary>
/// <param name="obj">Object instance to parse.</param>
private void Reflect(object obj) { /* Implementation hidden. */ }
/// <summary>Print the signatures of all the overloads of a specific method to the [Out] Parameter of the Script component. </summary>
/// <param name="obj">Object instance to parse.</param>
private void Reflect(object obj, string method_name) { /* Implementation hidden. */ }
#region Members
/// <summary>Gets the current Rhino document.</summary>
private readonly RhinoDoc RhinoDocument;
/// <summary>Gets the Grasshopper document that owns this script.</summary>
private readonly GH_Document GrasshopperDocument;
/// <summary>Gets the Grasshopper script component that owns this script.</summary>
private readonly IGH_Component Component;
/// <summary>
/// Gets the current iteration count. The first call to RunScript() is associated with Iteration==0.
/// Any subsequent call within the same solution will increment the Iteration count.
/// </summary>
private readonly int Iteration;
/// <summary>
/// This procedure contains the user code. Input parameters are provided as regular arguments,
/// Output parameters as ref arguments. You don't have to assign output parameters,
/// they will have a default value.
/// </summary>
private void RunScript(bool bake, ref object A)
Plane txt3dPln = new Plane(new Point3d(0, 300, 0), Vector3d.ZAxis);
Plane txtEntityPln = new Plane(new Point3d(600, 300, 0), Vector3d.ZAxis);
List<Plane> plnList = new List<Plane>();
txt3d = new Text3d("TextTest\nText3d", txt3dPln, 80);
txt3d.HorizontalAlignment = TextHorizontalAlignment.Center;
txt3d.VerticalAlignment = TextVerticalAlignment.Bottom;
DimensionStyle dimStyle = this.FindDimStyleByName("dim_GH-Bake");
txtEntity = TextEntity.Create(
"TextTest\nTextEntity", txtEntityPln, dimStyle, false, 0, 0);
txtEntity.Justification = Rhino.Geometry.TextJustification.BottomCenter;
A = plnList;
// <Custom additional code>
//Text3dはRhino.Display Namespace、TextEntityはRhino.Geometry Namespaceと違いがあります。
Rhino.Display.Text3d txt3d;
Rhino.Geometry.TextEntity txtEntity;
//Return a BoundingBox that contains all the geometry you are about to draw.
public override BoundingBox ClippingBox
return BoundingBox.Empty;
//Draw all wires and points in this method.
public override void DrawViewportWires(IGH_PreviewArgs args)
args.Display.Draw3dText(txt3d, Color.Red);
args.Display.DrawText(txtEntity, Color.Blue);
public DimensionStyle FindDimStyleByName(string dimStyleName)
DimensionStyle dimStyle = doc.DimStyles.FindName(dimStyleName);
if(dimStyle == null)
DimensionStyle newDimStyle = new DimensionStyle();
newDimStyle.LengthResolution = 1;
newDimStyle.AngleResolution = 2;
newDimStyle.TextHeight = 80;
newDimStyle.TextGap = 20;
newDimStyle.ExtensionLineExtension = 0;
newDimStyle.ExtensionLineOffset = 10;
newDimStyle.CentermarkSize = 30;
newDimStyle.ArrowType1 = DimensionStyle.ArrowType.Dot;
newDimStyle.ArrowType2 = DimensionStyle.ArrowType.Dot;
newDimStyle.ArrowLength = 40;
newDimStyle.LeaderArrowType = DimensionStyle.ArrowType.Dot;
newDimStyle.LeaderArrowLength = 40;
//newDimStyle.TextVerticalAlignment = TextVerticalAlignment.Bottom;
//newDimStyle.TextHorizontalAlignment = TextHorizontalAlignment.Center;
newDimStyle.Name = dimStyleName;
newDimStyle.Index = doc.DimStyles.Add(newDimStyle, false);
return newDimStyle;
return dimStyle;
// </Custom additional code>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment