Hi everyone,
I am trying to change color and material of the object for my plugin when some properties has changed from UI. Changing materials works fine at Rendered mode, but when I change ObjectColor from ObjectAttributes, it does not change the color even if by using CommitChanges() method.
In order to achieve this, do I have to recreate RhinoObject every time? Or is there any other way to do this?
Thanks in advance,
-Oğuzhan
I guess you also need to change the ColorSource to ColorFromObject.
rhObj.Attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject;
rhObj.Attributes.ObjectColor = Color.Blue;
rhObj.CommitChanges();
@Mahdiyar,
Thanks for your reply but I already did it, it is same.
I found a solution now, but it can be work around. Not so sure this is the appropriate way or not.
// Duplicate attributes
ObjectAttributes duplicatedAttributes = rhObj.Attributes.Duplicate();
// Change color
duplicatedAttributes.ObjectColor = Color.Blue;
// Set duplicated attributes to existing RhinoObject
rhObj.Attributes = duplicatedAttributes;
This works.
from Rhino.DocObjects import ObjectColorSource
from System.Drawing import Color
import rhinoscriptsyntax as rs
import scriptcontext as sc
id = rs.GetObject("select an object")
rhObj = sc.doc.Objects.FindId(id)
rhObj.Attributes.ColorSource = ObjectColorSource.ColorFromObject
rhObj.Attributes.ObjectColor = Color.Blue
rhObj.CommitChanges()
rs.Redraw()
private void RunScript(Guid id, System.Drawing.Color color)
{
var rhObj = RhinoDocument.Objects.FindId(id);
rhObj.Attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject;
rhObj.Attributes.ObjectColor = color;
rhObj.CommitChanges();
}
PythonObjectColor.py (359 Bytes)
CSharpObjectColor.gh (3.7 KB)
1 Like
@Mahdiyar That’s perfect!
Actually I found the main problem, I was using reference of Attributes in different layer in my plugin. But even if I change color of it, it was not reflected to the real RhinoObject. That’s why it is working with only by setting expilicity.
It’s weird, it should act like a reference object. But problem solved anyway! 
Thanks again!