Re: [Plugin] Recall last tool v1.2
can you update it like this?
code_text
module Matt
class MattObserver < Sketchup::ToolsObserver
@@last_tool_id = nil
@@toggle = true # Variable to control toggling
def onActiveToolChanged(tools, tool_name, tool_id)
# Save the tool ID if itās not one of the excluded IDs
@@last_tool_id = tool_id unless [21022, 10508].include?(tool_id) || tool_id >= 50000
puts "Active tool: #{tool_name} --> ID: #{tool_id}" unless [21022, 10508].include?(tool_id) || tool_id >= 50000
end
def self.recall_last
# Get the ID of the currently active tool
active_tool = Sketchup.active_model.tools.active_tool_id
# If the active tool is the selection tool and there's no other active tool, switch to the last tool
if [0, 21022].include?(active_tool)
if @@last_tool_id
Sketchup.send_action(@@last_tool_id)
else
puts "No previous tool. Selecting default tool."
Sketchup.send_action("selectSelectionTool:")
end
else
# If another tool is active, switch to the selection tool
Sketchup.send_action("selectSelectionTool:")
end
end
end
# Add the observer to SketchUp's tools
Sketchup.active_model.tools.add_observer(MattObserver.new)
# Add "ReCall" menu item
unless file_loaded?(__FILE__)
menu = UI.menu("Plugins") # Adds item under the "Plugins" menu
menu.add_item("ReCall") {
MattObserver.recall_last # Calls the recall_last method when clicked
}
file_loaded(__FILE__)
end
end