usingSystem.Collections.Generic;usingSystem.Drawing;usingSystem.Linq;usingRhino;usingRhino.Commands;usingRhino.Display;usingRhino.Geometry;usingRhino.Input;usingRhino.DocObjects;namespace examples_cs
{publicclassDisplayOrderCommand:Command{publicoverridestringEnglishName{get{return"csDisplayOrder";}}privateList<RhinoObject> m_line_objects =newList<RhinoObject>();protectedoverrideResultRunCommand(RhinoDoc doc,RunMode mode){// make lines thick so draw order can be easily seenvar dm =DisplayModeDescription.GetDisplayModes().Single(x => x.EnglishName=="Wireframe");var original_thikcness = dm.DisplayAttributes.CurveThickness;
dm.DisplayAttributes.CurveThickness=10;DisplayModeDescription.UpdateDisplayMode(dm);AddLine(Point3d.Origin,newPoint3d(10,10,0),Color.Red, doc);AddLine(newPoint3d(10,0,0),newPoint3d(0,10,0),Color.Blue, doc);AddLine(newPoint3d(8,0,0),newPoint3d(8,10,0),Color.Green, doc);AddLine(newPoint3d(0,3,0),newPoint3d(10,3,0),Color.Yellow, doc);
doc.Views.Redraw();Pause("draw order: 1st line drawn in front, last line drawn in the back. Any key to continue ...");//all objects have a DisplayOrder of 0 by default so changing it to 1 moves it to the front. Here we move the 2nd line (blue) to the front
m_line_objects[1].Attributes.DisplayOrder=1;
m_line_objects[1].CommitChanges();
doc.Views.Redraw();Pause("Second (blue) line now in front. Any key to continue ...");for(int i =0; i < m_line_objects.Count; i++){
m_line_objects[i].Attributes.DisplayOrder= i;
m_line_objects[i].CommitChanges();}
doc.Views.Redraw();Pause("Reverse order of original lines, i.e., Yellow 1st and Red last. Any key to continue ...");// restore original line thickness
dm.DisplayAttributes.CurveThickness= original_thikcness;DisplayModeDescription.UpdateDisplayMode(dm);
doc.Views.Redraw();returnResult.Success;}privatevoidPause(string msg){ObjRef obj_ref;var rc =RhinoGet.GetOneObject(msg,true,ObjectType.AnyObject,out obj_ref);}privatevoidAddLine(Point3d from,Point3d to,Color color,RhinoDoc doc){var guid = doc.Objects.AddLine(from, to);var obj = doc.Objects.Find(guid);
m_line_objects.Add(obj);
obj.Attributes.ObjectColor= color;
obj.Attributes.ColorSource=ObjectColorSource.ColorFromObject;
obj.CommitChanges();}}}
fromSystem.Collections.Genericimport*fromSystem.Drawingimport*fromRhinoimport*fromRhino.Commandsimport*fromRhino.Displayimport*fromRhino.Geometryimport*fromRhino.Inputimport*fromRhino.DocObjectsimport*from scriptcontext import doc
m_line_objects =[]defRunCommand():# make lines thick so draw order can be easily seen
wfdm =[dm for dm inDisplayModeDescription.GetDisplayModes()if dm.EnglishName=="Wireframe"][0]
original_thikcness = wfdm.DisplayAttributes.CurveThickness
wfdm.DisplayAttributes.CurveThickness=10DisplayModeDescription.UpdateDisplayMode(wfdm)AddLine(Point3d.Origin,Point3d(10,10,0),Color.Red, doc)AddLine(Point3d(10,0,0),Point3d(0,10,0),Color.Blue, doc)AddLine(Point3d(8,0,0),Point3d(8,10,0),Color.Green, doc)AddLine(Point3d(0,3,0),Point3d(10,3,0),Color.Yellow, doc)
doc.Views.Redraw()Pause("draw order: 1st line drawn in front, last line drawn in the back. Any key to continue ...")#all objects have a DisplayOrder of 0 by default so changing it to 1 moves it to the front. Here we move the 2nd line (blue) to the front
m_line_objects[1].Attributes.DisplayOrder=1
m_line_objects[1].CommitChanges()
doc.Views.Redraw()Pause("Second (blue) line now in front. Any key to continue ...")for i inrange(0, m_line_objects.Count-1):
m_line_objects[i].Attributes.DisplayOrder= i
m_line_objects[i].CommitChanges()
doc.Views.Redraw()Pause("Reverse order of original lines, i.e., Yellow 1st and Red last. Any key to continue ...")# restore original line thickness
wfdm.DisplayAttributes.CurveThickness= original_thikcness
DisplayModeDescription.UpdateDisplayMode(wfdm)
doc.Views.Redraw()returnResult.SuccessdefPause(msg):
rc, obj_ref =RhinoGet.GetOneObject(msg,True,ObjectType.AnyObject)defAddLine(from_pt, to_pt, color, doc):
guid = doc.Objects.AddLine(from_pt, to_pt)
obj = doc.Objects.Find(guid)
m_line_objects.Add(obj)
obj.Attributes.ObjectColor= color
obj.Attributes.ColorSource=ObjectColorSource.ColorFromObject
obj.CommitChanges()if __name__ =="__main__":RunCommand()
ImportsSystem.Collections.GenericImportsSystem.DrawingImportsSystem.LinqImportsRhinoImportsRhino.CommandsImportsRhino.DisplayImportsRhino.GeometryImportsRhino.InputImportsRhino.DocObjectsNamespace examples_vb
PublicClassDisplayOrderCommandInheritsCommandPublicOverridesReadOnlyPropertyEnglishName()AsStringGetReturn"vbDisplayOrder"EndGetEndPropertyPrivate m_line_objects AsNewList(OfRhinoObject)()ProtectedOverridesFunctionRunCommand(doc AsRhinoDoc, mode AsRunMode)AsResult' make lines thick so draw order can be easily seenDim dm =DisplayModeDescription.GetDisplayModes().[Single](Function(x) x.EnglishName="Wireframe")Dim original_thikcness = dm.DisplayAttributes.CurveThickness
dm.DisplayAttributes.CurveThickness=10DisplayModeDescription.UpdateDisplayMode(dm)AddLine(Point3d.Origin,NewPoint3d(10,10,0),Color.Red, doc)AddLine(NewPoint3d(10,0,0),NewPoint3d(0,10,0),Color.Blue, doc)AddLine(NewPoint3d(8,0,0),NewPoint3d(8,10,0),Color.Green, doc)AddLine(NewPoint3d(0,3,0),NewPoint3d(10,3,0),Color.Yellow, doc)
doc.Views.Redraw()Pause("draw order: 1st line drawn in front, last line drawn in the back. Any key to continue ...")'all objects have a DisplayOrder of 0 by default so changing it to 1 moves it to the front. Here we move the 2nd line (blue) to the frontm_line_objects(1).Attributes.DisplayOrder=1m_line_objects(1).CommitChanges()
doc.Views.Redraw()Pause("Second (blue) line now in front. Any key to continue ...")For i AsInteger=0To m_line_objects.Count-1m_line_objects(i).Attributes.DisplayOrder= i
m_line_objects(i).CommitChanges()Next
doc.Views.Redraw()Pause("Reverse order of original lines, i.e., Yellow 1st and Red last. Any key to continue ...")' restore original line thickness
dm.DisplayAttributes.CurveThickness= original_thikcness
DisplayModeDescription.UpdateDisplayMode(dm)
doc.Views.Redraw()ReturnResult.SuccessEndFunctionPrivateSubPause(msg AsString)Dim obj_ref AsObjRef=NothingDim rc =RhinoGet.GetOneObject(msg,True,ObjectType.AnyObject, obj_ref)EndSubPrivateSubAddLine(from AsPoint3d,[to]AsPoint3d, color AsColor, doc AsRhinoDoc)Dim guid = doc.Objects.AddLine(from,[to])Dim obj = doc.Objects.Find(guid)
m_line_objects.Add(obj)
obj.Attributes.ObjectColor= color
obj.Attributes.ColorSource=ObjectColorSource.ColorFromObject
obj.CommitChanges()EndSubEndClassEndNamespace