Click or drag to resize

ObjectAttributesColorSource Property

The color used to display an object is specified in one of three ways. If ColorSource is ON::color_from_layer, then the object's layer ON_Layer::Color() is used. If ColorSource is ON::color_from_object, then value of m_color is used. If ColorSource is ON::color_from_material, then the diffuse color of the object's render material is used. See ON_3dmObjectAttributes::MaterialSource() to determine where to get the definition of the object's render material.

Namespace:  Rhino.DocObjects
Assembly:  RhinoCommon (in RhinoCommon.dll)
Since: 5.0
Syntax
public ObjectColorSource ColorSource { get; set; }

Property Value

Type: ObjectColorSource
Examples
using System.Drawing;
using Rhino;
using Rhino.DocObjects;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Commands;

namespace examples_cs
{
  public class ModifyObjectColorCommand : Command
  {
    public override string EnglishName { get { return "csModifyObjectColor"; } }

    protected override Result RunCommand(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) return Result.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
      var sphere = new Sphere(Point3d.Origin, 5.0);
      var attributes = new ObjectAttributes();
      attributes.ObjectColor = Color.CadetBlue;
      attributes.ColorSource = ObjectColorSource.ColorFromObject;
      doc.Objects.AddSphere(sphere, attributes);

      doc.Views.Redraw();
      return Result.Success;
    }
  }
}
Python
from System.Drawing import *
from Rhino import *
from Rhino.DocObjects import *
from Rhino.Geometry import *
from Rhino.Input import *
from Rhino.Commands import *
from Rhino.UI.Dialogs import ShowColorDialog
from scriptcontext import doc

def RunCommand():
  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)
  if not b: return Result.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()
  return Result.Success

if __name__ == "__main__":
  RunCommand()
See Also