usingSystem.Drawing;usingRhino;usingRhino.DocObjects;usingRhino.Geometry;usingRhino.Input;usingRhino.Commands;namespace examples_cs
{publicclassModifyObjectColorCommand:Command{publicoverridestringEnglishName{get{return"csModifyObjectColor";}}protectedoverrideResultRunCommand(RhinoDoc doc,RunMode mode){ObjRef obj_ref;var rc =RhinoGet.GetOneObject("Select object",false,ObjectType.AnyObject,out obj_ref);if(rc !=Result.Success)return rc;var rhino_object = obj_ref.Object();var color = rhino_object.Attributes.ObjectColor;bool b =Rhino.UI.Dialogs.ShowColorDialog(ref color);if(!b)returnResult.Cancel;
rhino_object.Attributes.ObjectColor= color;
rhino_object.Attributes.ColorSource=ObjectColorSource.ColorFromObject;
rhino_object.CommitChanges();// an object's color attributes can also be specified// when the object is added to Rhinovar sphere =newSphere(Point3d.Origin,5.0);var attributes =newObjectAttributes();
attributes.ObjectColor=Color.CadetBlue;
attributes.ColorSource=ObjectColorSource.ColorFromObject;
doc.Objects.AddSphere(sphere, attributes);
doc.Views.Redraw();returnResult.Success;}}}
fromSystem.Drawingimport*fromRhinoimport*fromRhino.DocObjectsimport*fromRhino.Geometryimport*fromRhino.Inputimport*fromRhino.Commandsimport*fromRhino.UI.DialogsimportShowColorDialogfrom scriptcontext import doc
defRunCommand():
rc, obj_ref =RhinoGet.GetOneObject("Select object",False,ObjectType.AnyObject)if rc <>Result.Success:return rc
rhino_object = obj_ref.Object()
color = rhino_object.Attributes.ObjectColor
b, color =ShowColorDialog(color)ifnot b:returnResult.Cancel
rhino_object.Attributes.ObjectColor= color
rhino_object.Attributes.ColorSource=ObjectColorSource.ColorFromObject
rhino_object.CommitChanges()# an object's color attributes can also be specified# when the object is added to Rhino
sphere =Sphere(Point3d.Origin,5.0)
attributes =ObjectAttributes()
attributes.ObjectColor=Color.CadetBlue
attributes.ColorSource=ObjectColorSource.ColorFromObject
doc.Objects.AddSphere(sphere, attributes)
doc.Views.Redraw()returnResult.Successif __name__ =="__main__":RunCommand()
ImportsSystem.DrawingImportsRhinoImportsRhino.DocObjectsImportsRhino.GeometryImportsRhino.InputImportsRhino.CommandsNamespace examples_vb
PublicClassModifyObjectColorCommandInheritsCommandPublicOverridesReadOnlyPropertyEnglishName()AsStringGetReturn"vbModifyObjectColor"EndGetEndPropertyProtectedOverridesFunctionRunCommand(doc AsRhinoDoc, mode AsRunMode)AsResultDim obj_ref AsObjRef=NothingDim rc =RhinoGet.GetOneObject("Select object",False,ObjectType.AnyObject, obj_ref)If rc <>Result.SuccessThenReturn rc
EndIfDim rhino_object = obj_ref.[Object]()Dim color__1 = rhino_object.Attributes.ObjectColorDim b AsBoolean=Rhino.UI.Dialogs.ShowColorDialog(color__1)IfNot b ThenReturnResult.CancelEndIf
rhino_object.Attributes.ObjectColor= color__1
rhino_object.Attributes.ColorSource=ObjectColorSource.ColorFromObject
rhino_object.CommitChanges()' an object's color attributes can also be specified' when the object is added to RhinoDim sphere =NewSphere(Point3d.Origin,5.0)Dim attributes =NewObjectAttributes()
attributes.ObjectColor=Color.CadetBlue
attributes.ColorSource=ObjectColorSource.ColorFromObject
doc.Objects.AddSphere(sphere, attributes)
doc.Views.Redraw()ReturnResult.SuccessEndFunctionEndClassEndNamespace