Continuing the discussion from How to set entities to a specific elevation (z):
Here is an example script that does this.
(It is just too simple to warrant the rigmarole of publishing an extension for it.)
-
The top level namespace module name is just a generic “Author”.
Change it to something unique for production use. -
If you wish to disable the UI redraw during the command,
change the@@disable_ui
variable totrue
.
move_to_ground_plane.rb (903 Bytes)
This is what the file looks like for those not wanting to download the file:
# encoding: UTF-8
module Author; end
module Author::MoveToGroundPlane
extend self
MENU_TEXT ||= "Move to Ground Plane"
@@loaded ||= false
@@disable_ui ||= false
def move_to_ground_plane(ents)
model = Sketchup.active_model
model.start_operation(MENU_TEXT,@@disable_ui)
ents.each do |ent|
ent.transform!([0,0,-ent.transformation.origin.z])
end
model.commit_operation
end
if !@@loaded
UI.add_context_menu_handler do |popup|
sel = Sketchup.active_model.selection
unless sel.empty?
ents = sel.grep(Sketchup::Group) + sel.grep(Sketchup::ComponentInstance)
unless ents.empty?
popup.add_item(MENU_TEXT) { move_to_ground_plane(ents) }
end
end
end # context menu handler registrar
@@loaded = true
end # run once at first load
end # extension module