1.In Sketchup 2024 and below ,I find it is to slow to use API “SUModelIsDrawingElementVisible” to analyse all entitys’s visiblity,and SUModelIsDrawingElementVisible"a and “SUDrawingElementGetHidden”API is error sometimes , …is there any way to make it quickly to anlalyse visiblity?
2.Sketchup 2026 SDK improve these API above ?
I am not proficient in ruby, but i put this together using AI and a lot of testing. The script looks at the current selection and updates the toolbar icon state to show soften edges ( all, some, none)
require 'sketchup.rb'
module MP_Extensions
module MP_Edge_State_Tool
def self.update_icon
model = Sketchup.active_model
selection = model.selection
edges = selection.grep(Sketchup::Edge)
return if edges.empty?
# Check the current state of the edges
all_soft = edges.all? { |edge| edge.soft? }
none_soft = edges.none? { |edge| edge.soft? }
if all_soft
icon = 'all.png'
elsif none_soft
icon = 'none.png'
else
icon = 'some.png'
end
icon_path = File.join(__dir__, icon)
@cmd.small_icon = @cmd.large_icon = icon_path
end
def self.recreate_toolbar
@toolbar = UI::Toolbar.new("MP Edge State")
@toolbar.add_item(@cmd)
@toolbar.show
end
def self.toggle_soft_edges
model = Sketchup.active_model
selection = model.selection
edges = selection.grep(Sketchup::Edge)
return if edges.empty?
# Check the current state of the edges
all_soft = edges.all? { |edge| edge.soft? }
none_soft = edges.none? { |edge| edge.soft? }
model.start_operation('MP Edge State', true)
if all_soft
# Set all edges to none soft
edges.each { |edge| edge.soft = false }
elsif none_soft
# Set all edges to all soft
edges.each { |edge| edge.soft = true }
end
model.commit_operation
# Update toolbar icon
self.update_icon
self.recreate_toolbar
end
unless @loaded
@loaded = true
@cmd = UI::Command.new("MP Edge State") { toggle_soft_edges }
@cmd.tooltip = "MP Edge State Tool"
@cmd.status_bar_text = "Toggle the state of selected edges"
#update_icon
# Set default icon to "all.png" on load
@cmd.small_icon = @cmd.large_icon = File.join(__dir__, 'all.png')
recreate_toolbar
end
# Add an observer to update the toolbar icon when the selection changes
class SelectionObserver < Sketchup::SelectionObserver
def onSelectionBulkChange(selection)
MP_Edge_State_Tool.update_icon
MP_Edge_State_Tool.recreate_toolbar
end
end
Sketchup.active_model.selection.add_observer(SelectionObserver.new)
end # module MP_Edge_State_Tool
end # module MP_Extensions
Please delimit code correctly for the forum:
EDIT: Thanx for fixing.
This is the C SDK subcategory and the topic opener is asking about it’s use, Not the Ruby API.
As the Ruby API is interpreted it would likely be slower than anything written directly in C, especially using Ruby’s C interface. (I.e., Ruby itself is coded in C.)
My apologies Dan. Where I clicked in the header mentioned SketchUp SDK did not realize that meant “C”. I had been working on a similar issue trying to show a tool icon change based on the display state of edges. I thought my discovery may help with a portion of their issue. best reagrds