Grasshopper

algorithmic modeling for Rhino

How to simply define, say, RGB colors, or just Red/Blue/Cyan specific named colors for objects I'm "baking" directly from Grasshopper Python?

I look and look and have no idea because the only examples I find use Color.CadetBlue shortcuts that actually don't work since Color itself is unfound, let alone CadetBlue.

http://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_DocObject...

I don't see any RGB color definition in the Rhinocommon reference, which is just bizarre. Nobody owns that. Nobody patented it. But you left it out? RGB is impossible?

So before I create an object I can't just assign an RGB color?

SO THIS FAILS:

import Rhino

dimPlane = Rhino.Geometry.Plane(Rhino.Geometry.Point3d.Origin, end-start, Rhino.Geometry.Vector3d.CrossProduct(end-start, Rhino.Geometry.Vector3d.ZAxis))

dim = Rhino.Geometry.LinearDimension.Create(Rhino.Geometry.AnnotationType.Aligned, Rhino.RhinoDoc.ActiveDoc.DimStyles[1], dimPlane, end-start, start, end, dimPt, 0)

attributes = Rhino.DocObjects.ObjectAttributes()


attributes.ObjectColor = Color.Blue

Rhino.RhinoDoc.ActiveDoc.Objects.AddLinearDimension(dim, attributes)

No, CadetBlue doesn't work either. Nothing ever works from examples. Is that a .NET/Windows standard? I have no idea since not only is it not in the manual, there is no manual.

I don't know what buttons to push. How do I just make a dimension with the color blue in both display and print color? I already figured out how to bake it to a layer that can control it's color and Print Weight, but I'd rather override these directly so my script doesn't rely on an allied Rhino template file.

There's just no good working examples in the reference, in general. 

Revit/Dynamo beckons. They stole T-Splines. Maybe they also stole rational color definition?

My theory is that most programmers wanted to be game designers. So they made Rhino and other CAD software into a game. Yes, there is a way, along the Oregon Trail.

Views: 1958

Replies to This Discussion

import Rhino

from System.Drawing import Color

attr = Rhino.DocObjects.ObjectAttributes()
attr.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject
attr.ObjectColor = Color.FromArgb(255, 0, 0)

Just saw your comment after the fact. Thanks for the FromArgb command though. I failed to even see RGB in there, in the reference. I read it as "ARGHHHH!" and had to go to sleep.

Here is how it's done.

The Rhinocommon examples are so full of partial library imports instead of full Rhinocommon commands, that you cannot tell where each command comes from. It turns out the Color command comes from a .NET system library that is completely undocumented in the Rhinocommon SDK reference.

Nor can you just import System.Drawing or System iteself, but you must very oddly use a wildcard asterisk to import everything from it instead, instead of just import it like a normal programming event, you can't just do the normal thing, it has to suck, it has to be like the computer games every programmer wishes he was developing, it can't just be imported, since that would be impossibly simple, so the command isn't even import. It's "from" and then "import."

These Windows (Mac too?) .NET system color names like CadedBlue are referenced here, but not for free in the Rhinocommon SDK where they belong too, for free I mean it costs no money to put that crucial information where the Rhino programmer might find it:

http://yorktown.cbe.wwu.edu/sandvig/shared/netcolors.aspx

You also must toggle a color source setting away from layer color to an individual object override. Fair enough. You have that option in Rhino too, in the Properties palette.

Working code (Rhino 6 WIP):

import Rhino
from System.Drawing import *

dimPlane = Rhino.Geometry.Plane(Rhino.Geometry.Point3d.Origin, end-start, Rhino.Geometry.Vector3d.CrossProduct(end-start, Rhino.Geometry.Vector3d.ZAxis))

dim = Rhino.Geometry.LinearDimension.Create(Rhino.Geometry.AnnotationType.Aligned, Rhino.RhinoDoc.ActiveDoc.DimStyles[1], dimPlane, end-start, start, end, dimPt, 0)

attributes = Rhino.DocObjects.ObjectAttributes() # Blank attributes container.

attributes.ObjectColor = Color.CadetBlue # .NET color name.

attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject # Override layer color.

Rhino.RhinoDoc.ActiveDoc.Objects.AddLinearDimension(dim, attributes)

Now I don't have to rely on a Rhino template file so much with defined layers, or else create specific layers for dimension colors. I just spit out dimensions. More attributes will be figured out too. I like to avoid plugins and Rhinoscript and template files that create a mess for clients who simply want something to work out of the box.

Script with points embedded:

Attachments:

Deeper the rabbit hole goes, as the allied plot color is completely differently specified than object (display) color. It's the most cryptic command description I've run into as it seemingly invokes long underscored variables falling out of the sky that I'm supposed to know what buttons to push to assign values to, or somehow turn "ON," minus any code examples, let alone in my beloved Python language:

PlotColor: If plot_color_from_object == PlotColorSource, then PlotColor is the object's plotting color.

PlotColorSource: The color used to plot an object on paper is specified in one of three ways. If PlotColorSource is ON::plot_color_from_layer, then the object's layer ON_Layer::PlotColor() is used. If PlotColorSource is ON::plot_color_from_object, then value of PlotColor() is used.

Actually, just the reference is terrible, the command is in fact the same format, so here is how you add plot color as well as just display color to a dimension, using Rhino 6 WIP by the way, not Rhino 5, since dimensions changed in Rhinocommon:

I also added PlotWeight (Rhino Print Width), which happens to be specified in millimeters, period.

Attachments:

I left out PlotWeightSource, the override away from the layer setting:

attributes.PlotWeightSource = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service