I tried to build a similar plug-in. mine combines the soft and smooth steps to a toolbar with on and off functions. From leftr to right is Weld, explode, Soften, unSoften, Smooth, unSmooth
require 'sketchup.rb'
# require 'extensions.rb'
module MP_Extensions
module MP_Edge_Weld_Tool
def self.weld_selected_edges
model = Sketchup.active_model
selection = model.selection
edges = selection.grep(Sketchup::Edge)
if edges.empty?
show_notification("Please select edges to weld.")
return
end
model.start_operation('MP Weld Edges', true)
# Use built-in Weld method
model.active_entities.weld(edges)
model.commit_operation
show_notification("Edges welded.")
end
def self.explode_curve
model = Sketchup.active_model
entities = model.active_entities
selection = model.selection
vertices = selection.grep(Sketchup::Face).map(&:vertices).flatten.uniq
if vertices.empty?
show_notification("Please select faces to explode the edges.")
return
end
model.start_operation('MP Explode Curve', true)
# Explode curves if any
vertices.each do |vertex|
vertex.edges[0].explode_curve
end
model.commit_operation
show_notification("Edges exploded.")
end
def self.soften_curve
model = Sketchup.active_model
selection = model.selection
# Iterate through the selected entities
edges = selection.grep(Sketchup::Edge)
if edges.empty?
show_notification("Please select edges to soften.")
return
end
model.start_operation('MP Soften Curve', true)
selection.each do |entity|
# Check if the entity is an edge and soften it
if entity.is_a?(Sketchup::Edge)
entity.soft = true
end
end
model.commit_operation
show_notification("Edges softened.")
end
def self.unsoften_curve
model = Sketchup.active_model
selection = model.selection
edges = selection.grep(Sketchup::Edge)
if edges.empty?
show_notification("Please select edges to unsoften.")
return
end
model.start_operation('MP Unsoften Curve', true)
# Iterate through the selected entities
selection.each do |entity|
# Check if the entity is an edge and soften it
if entity.is_a?(Sketchup::Edge)
entity.soft = false
end
end
model.commit_operation
show_notification("Edges unsoftened.")
end
def self.smooth_curve
model = Sketchup.active_model
selection = model.selection
# Iterate through the selected entities
edges = selection.grep(Sketchup::Edge)
if edges.empty?
show_notification("Please select a face and edges to smooth.")
return
end
model.start_operation('MP Smooth', true)
selection.each do |entity|
# Check if the entity is a face and smooth it
if entity.is_a?(Sketchup::Edge)
entity.smooth = true
end
end
model.commit_operation
show_notification("Smoothing complete.")
end
def self.unsmooth_curve
model = Sketchup.active_model
selection = model.selection
# Iterate through the selected entities
edges = selection.grep(Sketchup::Edge)
if edges.empty?
show_notification("Please select a face and edges to unsmooth.")
return
end
model.start_operation('MP UnSmooth', true)
selection.each do |entity|
# Check if the entity is a face and unsmooth it
if entity.is_a?(Sketchup::Edge)
entity.smooth = false
end
end
model.commit_operation
show_notification("UnSmoothing complete.")
end
def self.show_notification(message)
dialog = UI::HtmlDialog.new(
dialog_title: "MP Edge Modifications",
scrollable: false,
resizable: false,
width: 300,
height: 100,
style: UI::HtmlDialog::STYLE_DIALOG
)
html_content = <<-HTML
<html>
<head>
<style>
body { font-family: Arial, sans-serif; text-align: center; padding: 15px; }
.message { font-size: 16px; }
</style>
</head>
<body>
<div class="message">#{message}</div>
<script>
setTimeout(function() {
window.close();
}, 1500);
</script>
</body>
</html>
HTML
dialog.set_html(html_content)
dialog.center
dialog.show
end
def self.create_toolbar
toolbar = UI::Toolbar.new("MP Edge Tools")
weld_cmd = UI::Command.new("MP Weld Edges") { weld_selected_edges }
weld_cmd.tooltip = "MP Weld Edges"
weld_cmd.status_bar_text = "Weld selected edges into a polyline"
weld_cmd.small_icon = weld_cmd.large_icon = File.join(__dir__, 'img', 'weld.png')
explode_cmd = UI::Command.new("MP Explode Edges") { explode_curve }
explode_cmd.tooltip = "MP Explode Edges"
explode_cmd.status_bar_text = "Explode selected curve into separate edges (Double click face first)"
explode_cmd.small_icon = explode_cmd.large_icon = File.join(__dir__, 'img', 'explode.png')
soft_cmd = UI::Command.new("MP Soften Edges") { soften_curve }
soft_cmd.tooltip = "MP Soften Edges"
soft_cmd.status_bar_text = "Soften only selected edges"
soft_cmd.small_icon = soft_cmd.large_icon = File.join(__dir__, 'img', 'soft.png')
unsoft_cmd = UI::Command.new("MP Unsoften Edges") { unsoften_curve }
unsoft_cmd.tooltip = "MP Unsoften Edges"
unsoft_cmd.status_bar_text = "Unsoften only selected edges"
unsoft_cmd.small_icon = unsoft_cmd.large_icon = File.join(__dir__, 'img', 'unsoft.png')
smooth_cmd = UI::Command.new("MP Smooth") { smooth_curve }
smooth_cmd.tooltip = "MP Smooth"
smooth_cmd.status_bar_text = "Smooth selected face shading"
smooth_cmd.small_icon = smooth_cmd.large_icon = File.join(__dir__, 'img', 'smooth.png')
unsmooth_cmd = UI::Command.new("MP UnSmooth") { unsmooth_curve }
unsmooth_cmd.tooltip = "MP UnSmooth"
unsmooth_cmd.status_bar_text = "UnSmooth selected face shading"
unsmooth_cmd.small_icon = unsmooth_cmd.large_icon = File.join(__dir__, 'img', 'unsmooth.png')
toolbar.add_item(weld_cmd)
toolbar.add_item(explode_cmd)
toolbar.add_item(soft_cmd)
toolbar.add_item(unsoft_cmd)
toolbar.add_item(smooth_cmd)
toolbar.add_item(unsmooth_cmd)
toolbar.show
end
# Create the toolbar when the script loads
MP_Edge_Weld_Tool.create_toolbar
end # module MP_Weld_Tool
end # module MP_Extensions
