usingRhino;usingRhino.Commands;usingRhino.Geometry;usingRhino.Input.Custom;namespace examples_cs
{classDrawArrowHeadsConduit:Rhino.Display.DisplayConduit{privatereadonlyLine m_line;privatereadonlyint m_screen_size;privatereadonlydouble m_world_size;publicDrawArrowHeadsConduit(Line line,int screenSize,double worldSize){
m_line = line;
m_screen_size = screenSize;
m_world_size = worldSize;}protectedoverridevoidDrawForeground(Rhino.Display.DrawEventArgs e){
e.Display.DrawArrow(m_line,System.Drawing.Color.Black, m_screen_size, m_world_size);}}publicclassDrawArrowheadsCommand:Command{publicoverridestringEnglishName{get{return"csDrawArrowHeads";}}DrawArrowHeadsConduit m_draw_conduit;protectedoverrideResultRunCommand(RhinoDoc doc,RunMode mode){if(m_draw_conduit !=null){RhinoApp.WriteLine("Turn off existing arrowhead conduit");
m_draw_conduit.Enabled=false;
m_draw_conduit =null;}else{// get arrow head sizevar go =newGetOption();
go.SetCommandPrompt("ArrowHead length in screen size (pixels) or world size (percentage of arrow length)?");
go.AddOption("screen");
go.AddOption("world");
go.Get();if(go.CommandResult()!=Result.Success)return go.CommandResult();int screen_size =0;double world_size =0.0;if(go.Option().EnglishName=="screen"){var gi =newGetInteger();
gi.SetLowerLimit(0,true);
gi.SetCommandPrompt("Length of arrow head in pixels");
gi.Get();if(gi.CommandResult()!=Result.Success)return gi.CommandResult();
screen_size = gi.Number();}else{var gi =newGetInteger();
gi.SetLowerLimit(0,true);
gi.SetUpperLimit(100,false);
gi.SetCommandPrompt("Length of arrow head in percentage of total arrow length");
gi.Get();if(gi.CommandResult()!=Result.Success)return gi.CommandResult();
world_size = gi.Number()/100.0;}// get arrow start and end pointsvar gp =newGetPoint();
gp.SetCommandPrompt("Start of line");
gp.Get();if(gp.CommandResult()!=Result.Success)return gp.CommandResult();var start_point = gp.Point();
gp.SetCommandPrompt("End of line");
gp.SetBasePoint(start_point,false);
gp.DrawLineFromPoint(start_point,true);
gp.Get();if(gp.CommandResult()!=Result.Success)return gp.CommandResult();var end_point = gp.Point();var v = end_point - start_point;if(v.IsTiny(Rhino.RhinoMath.ZeroTolerance))returnResult.Nothing;var line =newLine(start_point, end_point);
m_draw_conduit =newDrawArrowHeadsConduit(line, screen_size, world_size);// toggle conduit on/off
m_draw_conduit.Enabled=true;RhinoApp.WriteLine("Draw arrowheads conduit enabled.");}
doc.Views.Redraw();returnResult.Success;}}}
importRhinoimportSystem.Drawingimport scriptcontext
import rhinoscriptsyntax as rs
classDrawArrowHeadsConduit(Rhino.Display.DisplayConduit):def__init__(self, line, screenSize, worldSize):self.line = line
self.screenSize = screenSize
self.worldSize = worldSize
defDrawForeground(self, e):
e.Display.DrawArrow(self.line,System.Drawing.Color.Black,self.screenSize,self.worldSize)defRunCommand():# get arrow head size
go =Rhino.Input.Custom.GetOption()
go.SetCommandPrompt("ArrowHead length in screen size (pixles) or world size (percentage of arrow lenght)?")
go.AddOption("screen")
go.AddOption("world")
go.Get()if(go.CommandResult()!=Rhino.Commands.Result.Success):return go.CommandResult()
screenSize =0
worldSize =0.0if(go.Option().EnglishName=="screen"):
gi =Rhino.Input.Custom.GetInteger()
gi.SetLowerLimit(0,True)
gi.SetCommandPrompt("Length of arrow head in pixels")
gi.Get()if(gi.CommandResult()!=Rhino.Commands.Result.Success):return gi.CommandResult()
screenSize = gi.Number()else:
gi =Rhino.Input.Custom.GetInteger()
gi.SetLowerLimit(0,True)
gi.SetUpperLimit(100,False)
gi.SetCommandPrompt("Lenght of arrow head in percentage of total arrow lenght")
gi.Get()if(gi.CommandResult()!=Rhino.Commands.Result.Success):return gi.CommandResult()
worldSize = gi.Number()/100.0# get arrow start and end points
gp =Rhino.Input.Custom.GetPoint()
gp.SetCommandPrompt("Start of line")
gp.Get()if(gp.CommandResult()!=Rhino.Commands.Result.Success):return gp.CommandResult()
ptStart = gp.Point()
gp.SetCommandPrompt("End of line")
gp.SetBasePoint(ptStart,False)
gp.DrawLineFromPoint(ptStart,True)
gp.Get()if(gp.CommandResult()!=Rhino.Commands.Result.Success):return gp.CommandResult()
ptEnd = gp.Point()
v = ptEnd - ptStart
if(v.IsTiny(Rhino.RhinoMath.ZeroTolerance)):returnRhino.Commands.Result.Nothing
line =Rhino.Geometry.Line(ptStart, ptEnd)
conduit =DrawArrowHeadsConduit(line, screenSize, worldSize)
conduit.Enabled=True
scriptcontext.doc.Views.Redraw()
rs.GetString("Pausing for user input")
conduit.Enabled=False
scriptcontext.doc.Views.Redraw()returnRhino.Commands.Result.Successif __name__=="__main__":RunCommand()
ImportsRhinoImportsRhino.CommandsImportsRhino.GeometryImportsSystem.Collections.GenericImportsRhino.Input.CustomNamespace examples_vb
ClassDrawArrowHeadsConduitInheritsRhino.Display.DisplayConduitPrivate _line AsLinePrivate _screenSize AsIntegerPrivate _worldSize AsDoublePublicSubNew(line AsLine, screenSize AsInteger, worldSize AsDouble)
_line = line
_screenSize = screenSize
_worldSize = worldSize
EndSubProtectedOverridesSubDrawForeground(e AsRhino.Display.DrawEventArgs)
e.Display.DrawArrow(_line,System.Drawing.Color.Black, _screenSize, _worldSize)EndSubEndClassPublicClassDrawArrowheadsCommandInheritsCommandPublicOverridesReadOnlyPropertyEnglishName()AsStringGetReturn"vbDrawArrowHeads"EndGetEndPropertyProtectedOverridesFunctionRunCommand(doc AsRhinoDoc, mode AsRunMode)AsResult' get arrow head sizeDim go =NewRhino.Input.Custom.GetOption()
go.SetCommandPrompt("ArrowHead length in screen size (pixles) or world size (percentage of arrow lenght)?")
go.AddOption("screen")
go.AddOption("world")
go.[Get]()If go.CommandResult()<>Result.SuccessThenReturn go.CommandResult()EndIfDim screenSize AsInteger=0Dim worldSize AsDouble=0.0If go.[Option]().EnglishName="screen"ThenDim gi =NewRhino.Input.Custom.GetInteger()
gi.SetLowerLimit(0,True)
gi.SetCommandPrompt("Length of arrow head in pixels")
gi.[Get]()If gi.CommandResult()<>Result.SuccessThenReturn gi.CommandResult()EndIf
screenSize = gi.Number()ElseDim gi =NewRhino.Input.Custom.GetInteger()
gi.SetLowerLimit(0,True)
gi.SetUpperLimit(100,False)
gi.SetCommandPrompt("Lenght of arrow head in percentage of total arrow lenght")
gi.[Get]()If gi.CommandResult()<>Result.SuccessThenReturn gi.CommandResult()EndIf
worldSize = gi.Number()/100.0EndIf' get arrow start and end pointsDim gp =NewRhino.Input.Custom.GetPoint()
gp.SetCommandPrompt("Start of line")
gp.[Get]()If gp.CommandResult()<>Result.SuccessThenReturn gp.CommandResult()EndIfDim startPoint = gp.Point()
gp.SetCommandPrompt("End of line")
gp.SetBasePoint(startPoint,False)
gp.DrawLineFromPoint(startPoint,True)
gp.[Get]()If gp.CommandResult()<>Result.SuccessThenReturn gp.CommandResult()EndIfDim endPoint = gp.Point()Dim v = endPoint - startPoint
If v.IsTiny(Rhino.RhinoMath.ZeroTolerance)ThenReturnResult.[Nothing]EndIfDim line =NewLine(startPoint, endPoint)Dim conduit =NewDrawArrowHeadsConduit(line, screenSize, worldSize)' toggle conduit on/off
conduit.Enabled=Not conduit.EnabledRhinoApp.WriteLine("draw arrowheads conduit enabled = {0}", conduit.Enabled)
doc.Views.Redraw()ReturnResult.SuccessEndFunctionEndClassEndNamespace