@Rich-O-Brien I'll start by saying that I'm not a programmer. I created this script with cloud 3 5 AI to disable or activate the sections in the project. The plug-in correctly creates the list of sections but even though I created the activate and deactivate buttons, they don't work. I tried it on sketchup 2024. Is there anyone who can give me that suggestion?
require 'sketchup.rb'
module SectionManager
def self.show_dialog
dialog = UI::WebDialog.new("Gestione Sezioni", false, "SectionManager", 400, 500, 100, 100, true)
dialog.set_size(400, 500)
dialog.add_action_callback("toggleSection") do |_, section_id|
model = Sketchup.active_model
section = find_section_by_id(model, section_id.to_i)
if section
model.start_operation('Toggle Section', true)
section.active = !section.active
model.commit_operation
puts "Sezione #{section_id} #{section.active? ? 'attivata' : 'disattivata'}"
else
puts "Sezione #{section_id} non trovata"
end
update_dialog_content(dialog)
end
dialog.add_action_callback("activateSection") do |_, section_id|
model = Sketchup.active_model
section = find_section_by_id(model, section_id.to_i)
if section
model.start_operation('Activate Section', true)
section.active = true
model.commit_operation
puts "Sezione #{section_id} attivata"
else
puts "Sezione #{section_id} non trovata"
end
update_dialog_content(dialog)
end
dialog.add_action_callback("refreshList") do |_|
puts "Aggiornamento lista richiesto"
update_dialog_content(dialog)
end
update_dialog_content(dialog)
dialog.show
end
def self.find_all_sections(entities)
sections = []
entities.each do |entity|
if entity.is_a?(Sketchup::SectionPlane)
sections << entity
elsif entity.is_a?(Sketchup::Group) || entity.is_a?(Sketchup::ComponentInstance)
sections += find_all_sections(entity.definition.entities)
end
end
sections
end
def self.find_section_by_id(model, section_id)
find_all_sections(model.active_entities).find { |s| s.entityID == section_id }
end
def self.update_dialog_content(dialog)
model = Sketchup.active_model
sections = find_all_sections(model.active_entities)
puts "Numero totale di sezioni trovate (incluse quelle nidificate): #{sections.length}"
html = <<-HTML
<html>
<head>
<style>
body { font-family: Arial, sans-serif; }
.section { margin: 10px 0; }
button { margin-left: 5px; }
</style>
</head>
<body>
<h2>Tutte le Sezioni</h2>
<div id="sectionList">
#{
if sections.empty?
"<p>Nessuna sezione trovata nel modello.</p>"
else
sections.map { |section|
"<div class='section'>
#{section.name || 'Sezione senza nome'} (ID: #{section.entityID})
<button onclick='toggleSection(#{section.entityID})'>
#{section.active? ? 'Disattiva' : 'Attiva'}
</button>
<button onclick='activateSection(#{section.entityID})'>
Attiva
</button>
</div>"
}.join
end
}
</div>
<button onclick='refreshList()'>Aggiorna Lista</button>
<script>
function toggleSection(sectionId) {
window.location = 'skp:toggleSection@' + sectionId;
}
function activateSection(sectionId) {
window.location = 'skp:activateSection@' + sectionId;
}
function refreshList() {
window.location = 'skp:refreshList@';
}
</script>
</body>
</html>
HTML
dialog.set_html(html)
end
end
# Aggiungi una voce di menu per avviare lo script
UI.menu("Plugins").add_item("Gestione Sezioni (Versione Aggiornata)") {
SectionManager.show_dialog
}
puts "Script di gestione sezioni (versione aggiornata) caricato"










