How to get edge/line color?
-
Hi all,
Using Ruby, is it possible to retrieve the color of an Edge object?
I am working on a plugin and I have no idea how to access this information from the code.
Any help is appreciated
-
-
View the API for Edge, but there isn't anything about colors there.
-
Realize an Edge is a Drawingelement, and so inherits the methods of Drawing element.
-
Find that Drawingelements have a material property, which returns a Material.
-
See that a Material has a color property.
In Short, with a single edge selected..
some_edge = Sketchup.active_model.selection[0] edge_color = some_edge.material.color
But, if the edge has no material, this will give an error because some_edge.material will return
nil
. So you should check the Edge has a material before asking for the color. -
-
Hi Jim,
Thanks for pointing me that way but it appears that the material for my lines is null/nil.
I see if I go to Windows->Styles, then click on Edit in the newly opened window, I can change line colours from there.
Is this information exposed through a different API maybe?
-
@bigstink said:
Is this information exposed through a different API maybe?
Yes, Style settings are accessed in the Hash-like RenderingOptions. You can view all the RendingOptions using this line in the Ruby window.
Sketchup.active_model.rendering_options.each {|k, v| puts "#{k} = #{v}"}
There does not appear to be a key for an "EdgeColor"
-
Ah, it is the
ForegroundColor
key. -
Perfect, those rendering options will come in handy!
This works great, thanks Jim
Advertisement