-
-
Save JoshCheek/19f875de5d90d316328acc7b03ede7fa to your computer and use it in GitHub Desktop.
Sketchup extension (proof of concept for Eden) NOW HOSTED AT https://github.com/JoshCheek/sketchup-example-plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /Users/josh/Library/Application Support/SketchUp 2016/SketchUp/Plugins/eden.rb | |
require 'sketchup' | |
require 'extensions' | |
unless file_loaded?(__FILE__) | |
file_loaded(__FILE__) | |
ex = SketchupExtension.new('Eden', 'eden/select_same/main') | |
ex.description = 'Eden\'s extension to select the same objects' | |
ex.version = '1.0.0' | |
ex.copyright = 'none' | |
ex.creator = 'Josh Cheek' | |
Sketchup.register_extension(ex, true) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /Users/josh/Library/Application Support/SketchUp 2016/SketchUp/Plugins/eden/select_same/main.rb | |
require 'sketchup' | |
require 'set' | |
module Eden | |
MENU ||= UI.menu("Tools").add_submenu("Eden") | |
TOOLBAR ||= UI::Toolbar.new("Eden") | |
class SelectSame | |
unless @loaded | |
@loaded = true | |
cmd = UI::Command.new("Select Same") { | |
Sketchup.active_model.select_tool(new) | |
} | |
cmd.menu_text = 'Select Same' | |
cmd.small_icon = 'icon-16.png' # these don't work, IDK why | |
cmd.large_icon = 'icon-24.png' # these don't work, IDK why | |
MENU.add_item(cmd) | |
TOOLBAR.add_item(cmd) | |
end | |
# Can define any of the methods listed here: | |
# http://ruby.sketchup.com/Sketchup/Tool.html | |
def activate | |
Sketchup.status_text = 'Select the duplicated item' | |
@source = nil | |
end | |
def deactivate(view) | |
view.invalidate # marks the view as needing a redraw | |
end | |
def onMouseMove(flags, x, y, view) | |
best_picked = view.pick_helper(x, y).best_picked | |
return unless @source != best_picked | |
@source = best_picked | |
model = view.model | |
model.selection.clear | |
return unless @source | |
model.selection.add [@source] | |
select_similar model | |
end | |
def onLButtonUp(flags, x, y, view) | |
model = view.model | |
model.start_operation('Select Same', true) | |
onMouseMove flags, x, y, view | |
model.commit_operation | |
model.tools.pop_tool | |
end | |
def select_similar(model) | |
current_ids = Set.new( | |
model.selection | |
.select { |e| e.respond_to? :definition } | |
.map { |e| e.definition.entityID } | |
) | |
selected_ids = model.entities | |
.select { |e| e.respond_to? :definition } | |
.select { |e| current_ids.include? e.definition.entityID } | |
model.selection.add selected_ids | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment