module Reglue
extend self
# Menü öğesinin eklenme konumunu belirleyen değişken
SUPPORT_MENU_POSITION ||= Sketchup::Menu.instance_method(:add_item).arity != 1 ? 8 : nil
def glue_components_to_faces
model = Sketchup.active_model
selection = model.selection
if selection.empty?
UI.messagebox("Hata: Hiçbir seçim yapılmadı!")
return
end
faces = selection.grep(Sketchup::Face)
components = selection.grep(Sketchup::ComponentInstance).select { |comp| comp.glued_to.nil? }
if faces.empty? || components.empty?
UI.messagebox("Hata: Lütfen hem yüzeyleri hem de yapıştırılabilir bileşenleri seçin!")
return
end
model.start_operation("Bileşenleri Yüzeylere Yeniden Yapıştır", true)
components.each do |component|
closest_face = find_closest_aligned_face(component, faces)
component.glued_to = closest_face if closest_face
end
model.commit_operation
end
def find_closest_aligned_face(component, faces)
component_normal = component.transformation.zaxis
faces.min_by { |face| face.normal.angle_between(component_normal) }
end
unless @loaded
UI.add_context_menu_handler do |menu|
selection = Sketchup.active_model.selection
next if selection.empty?
has_faces = selection.any? { |entity| entity.is_a?(Sketchup::Face) }
has_glueable_components = selection.any? { |entity| entity.is_a?(Sketchup::ComponentInstance) && entity.glued_to.nil? }
if has_faces && has_glueable_components
position = SUPPORT_MENU_POSITION
menu.add_item("Reglue", position) { glue_components_to_faces }
end
end
@loaded = true
end
end

Latest posts made by designerbursa
-
RE: [Plugin] ReGlue
-
can you update it like this?
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
-
Is it ok to add tolerance for snap points?
Re: [Plugin] BezierSpline - v2.2a - 22 Apr 21
I made a change like this if you don't minddef pick_point_to_move(x, y, view) tolerance = 1000 # Tolerans değeri, piksel cinsinden @old_pt_to_move = @pt_to_move ph = view.pick_helper @selection = ph.pick_segment @pts, x, y if @selection if @selection < 0 # Segment üzerinde bir nokta bulduysak pickray = view.pickray x, y i = -@selection segment = [@pts[i-1], @pts[i]] result = Geom.closest_points(segment, pickray) # Yakınlık kontrolü if result[0].distance(@pts[i-1]) <= tolerance || result[0].distance(@pts[i]) <= tolerance @pt_to_move = result[0] else @pt_to_move = nil end else # Kontrol noktasını bulduysak @pt_to_move = @pts[@selection] end else @pt_to_move = nil end @old_pt_to_move != @pt_to_move end
-
RE: [Plugin] ReGlue
@designerbursa ```
module GlueComponentsToFaces extend self def glue_components_to_faces model = Sketchup.active_model selection = model.selection if selection.empty? return UI.messagebox("Error: No selection! Please select faces and components.") end faces = selection.grep(Sketchup::Face) components = selection.grep(Sketchup::ComponentInstance) if faces.empty? || components.empty? return UI.messagebox("Error: Select faces and components!") end model.start_operation("Glue Components to Faces", true) begin components.each do |component| closest_face = find_closest_aligned_face(component, faces) component.glued_to = closest_face if closest_face end rescue => e UI.messagebox("An error occurred: #{e.message}") ensure model.commit_operation end end def find_closest_aligned_face(component, faces) component_normal = component.transformation.zaxis closest_face = faces.min_by { |face| face.normal.angle_between(component_normal) } closest_face end end # Adding a menu item for ease of use in SketchUp if not file_loaded?(__FILE__) UI.menu("Plugins").add_item("Glue Components to Faces") { GlueComponentsToFaces.glue_components_to_faces } file_loaded(__FILE__) end
### I haven't tested it on the 2024 version but you can try this, maybe it will work. It works smoothly on my 2021 version
-
RE: [Plugin] ReGlue
@rv1974 If you can paste without extensions, I really congratulate you...
-
RE: [Plugin] ReGlue
@rv1974 I developed the code for pasting on all selected surfaces at once, it would be useful for everyone if it is updated in this way.
-
RE: [Plugin] ReGlue
def self.glue_components_to_faces model = Sketchup.active_model selection = model.selection return UI.messagebox("Error: No selection!") if selection.empty? faces = selection.grep(Sketchup::Face) components = selection.grep(Sketchup::ComponentInstance) return UI.messagebox("Error: Select faces and components!") if faces.empty? || components.empty? model.start_operation("Glue Components to Faces", true) begin components.each do |component| closest_face = find_closest_aligned_face(component, faces) component.glued_to = closest_face if closest_face end ensure model.commit_operation end end def self.find_closest_aligned_face(component, faces) component_normal = component.transformation.zaxis closest_face = faces.min_by { |face| face.normal.angle_between(component_normal) } closest_face end
-
RE: [Plugin] Selection Toys
When I install this plugin "ae_LaunchUp"; I get the console error
C:/Users/User/AppData/Roaming/SketchUp/SketchUp 2021/SketchUp/Plugins/tt_selection_toys/json.rb:39:in
each' C:/Users/User/AppData/Roaming/SketchUp/SketchUp 2021/SketchUp/Plugins/tt_selection_toys/ui_manager.rb:280:in
build_menus'
C:/Users/User/AppData/Roaming/SketchUp/SketchUp 2021/SketchUp/Plugins/tt_selection_toys/ui_manager.rb:262:in `block (2 levels) in build_ui' -
RE: [Plugin] Material Renamer
Plugin name and menu text
PLUGIN_NAME = 'Rename Materials by File Name'.freeze
Plugin class
class RenameMaterials
def self.rename
# Get the active model
model = Sketchup.active_model# Get the file name and remove the extension file_name = File.basename(model.path, ".*") # Get all materials in the model materials = model.materials # Iterate through all materials and assign new names based on the file name materials.each_with_index do |material, index| new_name = "#{file_name}_#{format('%02d', index + 1)}" material.name = new_name end puts "Materials have been successfully renamed based on the file name."
end
endMenu item that activates the plugin
UI.menu('Plugins').add_item(PLUGIN_NAME) { RenameMaterials.rename }
Advertisement