Hi All,
Is there any way/API call to set my own colour for the entities when it is selected instead of the blue colour or red if it is locked. I know I can create my own style, but that will change it for everything in the model. I only need to change for the groups/components I specify in my code.
Thanks.
Can’t be done. The selection color is a style property and thus global to the model, not an entity property.
What is your use case where you’d want a different selection color on certain entities?
I just want to separate(view differently) some entities from others based on a condition. But I got your point. Thanks for the reply.
If the condition has them assigned to use different tags (previously layers,) then code could temporarily switch the render to color by tag (layer.)
If your code is implementing a tool, then the tool’s draw method(s) can draw bounding boxes in whatever color you like. (I think @thomthom posted a code example of this somewhere.)
Another option would be to temporarily modify the materials that the objects are painted with.
Thanks Dan. Could you please throw some more light on switching the render to color by tag.
Yes my code is implementing a tool, so if I set a color to the entity’s bounding box, will this color be shown permanently on the model or only come up when I click on that entity?
Thanks.
def color_by_tag_or_layer(switch = true)
model = Sketchup.active_model
opts = model.rendering_options
if switch
opts['DisplayColorByLayer']= true
else
opts['DisplayColorByLayer']= false
end
end
REF:
ADD: This is actually a style setting. So to make it permanent you’d update the current style in use.
Many users might prefer a scene page with it’s own style that has color by tag active.
Yes, BUT only if your tool does not change it back.
You can do this within your tool class to have a special bounding box color in effect only whilst your tool is active …
SPECIAL_HIGHLIGHT ||= Sketchup::Color.new('Magenta')
def activate()
@model_highlight_color = get_style_highlight_color()
activate_special_boundingbox_color()
# ... other tool activation code ...
end
def get_style_highlight_color
Sketchup.active_model.rendering_options['HighlightColor']
end
def activate_special_boundingbox_color(switch = true)
model = Sketchup.active_model
opts = model.rendering_options
if switch
opts['HighlightColor']= SPECIAL_HIGHLIGHT
else
opts['HighlightColor']= @model_highlight_color
end
end
def deactivate(view)
activate_special_boundingbox_color(false)
# ... other tool deactivation code ...
end
It would be up to you whether to leave your special bounding box color in effect during a suspend.
Now since your implementing a tool … You can draw in 3D space in whatever color suits your fancy without effecting any of the model’s or current scene’s rendering style settings.
def draw(view)
obj = view.model.selection.first
bb = obj.bounds
v = []
6.times do |i|
v << bb.corner(i)
end
view.drawing_color= SPECIAL_HIGHLIGHT
view.draw(GL_LINE_LOOP, v[0], v[1], v[5], v[4])
view.draw(GL_LINE_LOOP, v[2], v[3], v[7], v[6])
view.draw(GL_LINES, v[0], v[2], v[4], v[6], v[5], v[7], v[1], v[3])
end
This is sort of what Thomas’ example did.
Thanks a lot Dan.