# encoding: UTF-8
module Author # <---<<< change to something unique
module InsertLocalComponent
extend self
WIN =(Sketchup.platform == :platform_win rescue RUBY_PLATFORM !~ /darwin/i)
OPEN_CAPTION ||= 'Choose Component ...'
TOOLBAR_NAME ||= 'Component Menu'
CMD_NAME ||= {}
CMD_NAME[:pc1]= 'Place Component'
@@loaded ||= false
@@cmd ||= {}
@@cdpath ||= "D:/"
@@skp ||= "asd.skp"
def place_component_1()
#
if WIN
# If an error occurs finding the directory path,
# Windows will open in the directory last used.
# If the 3rd filter argument is used, Windows
# will open in the directory last used for the filter,
# and ignore the second directory path argument.
filepath = UI.openpanel(OPEN_CAPTION,File.join(@@cdpath,'*.skp'))
else
filepath = UI.openpanel(OPEN_CAPTION,@@cdpath,@@skp)
end
return unless filepath
#
mod = Sketchup::active_model
# Creates a "Load Component" undo operation:
cdef = mod.definitions.load(filepath)
cdef ? @@cdpath=File.dirname(filepath) : return
#
# Model#place_component() creates it's own undo operation
# that CANNOT be wrapped in a Sketchup::Model#start_operation.
mod.place_component(cdef)
#
end
if !@@loaded # RUN ONCE CODE:
@@toolbar ||= UI::Toolbar.new(TOOLBAR_NAME)
name = CMD_NAME[:pc1]
cmd = @@cmd[:pc1] ||= UI::Command.new(name) {
place_component_1()
}
cmd.small_icon = ""
cmd.large_icon = ""
cmd.tooltip = name
cmd.menu_text = name
cmd.status_bar_text = name
@@toolbar.add_item(@@cmd[:pc1]) unless @@toolbar.include?(@@cmd[:pc1])
@@toolbar.show if @@toolbar.get_last_state != TB_HIDDEN
@@loaded = true
end
end
end