Hello
I tried to create a plugin that divides in the Z direction when inputting an interval using an inputbox.
There is a problem that the code that worked in the Ruby Console cannot be made into a plug-in.
Of course, my coding skills seem to be the problem
require 'sketchup.rb'
def create_line
mod = Sketchup.active_model
ent = mod.entities
sel = mod.selection
SKETCHUP_CONSOLE.clear
Sketchup.send_action "selectSelectionTool:"
prompts = ["1","2"]
values = [$hg1, $hg2]
result = UI.inputbox(prompts, vlaues, "커튼월")
$hg1 = result[0].to_f; $hg2 = result[1].to_f;
puts(result[0], reuslt[1])
faces = sel.grep(Sketchup::Face).reject{|f|f.normal.z != 0}
for f in faces
btm = f.edges.min_by{|x|x.start.position.z+x.end.position.z}
sp = btm.start.position.offset(Z_AXIS, $hg1.to_f.mm)
sp = btm.end.position.offset(Z_AXIS, $hg1.to_f.mm)
sp2 = btm.start.position.offset(Z_AXIS, $hg1.to_f.mm + $hg2.to_f.mm)
ep2 = btm.end.position.offset(Z_AXIS, $hg1.to_f.mm + $hg2.to_f.mm)
new = ent.add_line(sp,ep)
new = ent.add_line(sp2,ep2)
end
end
# Add a menu item to activate the plugin
UI.menu("Plugins").add_item("Create line") {
prompts = ["1", "2"]
defaults = [10, 10]
input = UI.inputbox(prompts, defaults, "Dimensions")
}
I wonder if it is a code that cannot function with def. Below is the code I proceeded with the ruby console (no def)
mod = Sketchup.active_model
ent = mod.entities
sel = mod.selection
SKETCHUP_CONSOLE.clear
Sketchup.send_action "selectSelectionTool:"
prompts = ["1","2"]
values = [$hg1, $hg2]
result = UI.inputbox(prompts, values, "커튼월")
$hg1 = result[0].to_f; $hg2 = result[1].to_f;
puts(result[0], result[1])
faces = sel.grep(Sketchup::Face).reject{|f|f.normal.z != 0}
for f in faces
btm = f.edges.min_by{|x|x.start.position.z+x.end.position.z}
sp = btm.start.position.offset(Z_AXIS, $hg1.to_f.mm)
ep = btm.end.position.offset(Z_AXIS, $hg1.to_f.mm)
sp2 = btm.start.position.offset(Z_AXIS, $hg1.to_f.mm + $hg2.to_f.mm)
ep2 = btm.end.position.offset(Z_AXIS, $hg1.to_f.mm + $hg2.to_f.mm)
new = ent.add_line(sp,ep)
new = ent.add_line(sp2,ep2)
end
Thanks for any helpful tips or corrections. Always happy to help. Thanks everyone.