In the SketchUp UI, the Model Info settings allow for fading the rest of the model when editing a group or component.
Only the entities at the current group hierarchy level are the active_entities…
I don’t see any way to simulate this in a custom tool: A user already must be inside a single group and at a particular level of its group hierarchy, before activating a tool. And so I can’t use onLButtonDoubleClick allow the user to to traverse the group hierarchy within a tool and trigger fading behavior…
To enter a selected object’s editing context use the ENTER key. So clear the selection, then put one group or component object into the set, then send an ENTER.
But if the main modeling viewport does not have focus, the ENTER might get lost (processed by one of the app’s child windows,) so we test at the end of the method …
if (Sketchup.platform == :platform_win rescue RUBY_PLATFORM !~ /darwin/)
require 'win32ole' # load from standard library (SketchUp 2014+)
UTIL = WIN32OLE::new(WScript.Shell)
def edit_comp(comp)
return false unless comp.respond_to?(:definition)
return false if comp.definition.image? # bailout
return unless step_back_to(comp)
sel = Sketchup.active_model.selection
sel.clear
sel.add(comp)
# perhaps a pause here? sleep(0.3)
UTIL.SendKeys('{ENTER}')
# Test the active entities and return boolean result for method:
Sketchup.active_model.active_entities == comp.definition.entities
end
else # Mac
UTIL = File.join(File.dirname(__dir__), 'bin', 'cliclick')
def edit_comp(comp)
return false unless comp.respond_to?(:definition)
return false if comp.definition.image? # bailout
return unless step_back_to(comp)
return nil unless File.exist?(UTIL)
sel = Sketchup.active_model.selection
sel.clear
sel.add(comp)
# perhaps a pause here? sleep(0.3)
if comp.definition.group?
%x["#{UTIL}" kd:shift t:G ku:shift]
else # it's a component
%x["#{UTIL}" kd:shift t:C ku:shift]
end
# Test the active entities and return boolean result for method:
Sketchup.active_model.active_entities == comp.definition.entities
end
end
end
…
def step_back_to(comp)
# ensure the active context contains comp
model = Sketchup.active_model
active = active_entities
if active.grep(comp.class).include?(comp)
return true
elsif model.entities == active
return false
else
until model.entities == active ||
active.grep(comp.class).include?(comp)
model.close_active
active = model.active_entities
end
active.grep(comp.class).include?(comp)
end
end