初来SU吧,主要是为了学习SU的二次开发,发些自己找的,学习小例子,以记。
下面的这个例子,是在SU中自动产生一些台阶,可以通过修改一些参数,改变产生的数量,阶高等,,
我也只是初学,如果有比我还菜的,有兴趣的可以跟贴,相互学习。
# # First we pull in the standard API hooks. require 'sketchup.rb'
# Show the Ruby Console at startup so we can
# see any programming errors we may make.
Sketchup.send_action "showRubyPanel:"
# Add a menu item to launch our plugin.
UI.menu("PlugIns").add_item("Draw stairs") {
UI.messagebox("I'm about to draw stairs!")
# Call our new method.
draw_stairs
}
def draw_stairs
# Create some variables.
stairs = 10
rise = 10
run = 12
width = 100
thickness = 3
# Get handles to our model and the Entities collection it contains.
model = Sketchup.active_model
entities = model.entities
# Loop across the same code several times
for step in 1..stairs
# Calculate our stair corners.
x1 = 0
x2 = width
y1 = run * step
y2 = run * (step + 1)
z = rise * step
# Create a series of "points", each a 3-item array containing x, y, and z.
pt1 = [x1, y1, z]
pt2 = [x2, y1, z]
pt3 = [x2, y2, z]
pt4 = [x1, y2, z]
# Call methods on the Entities collection to draw stuff.
new_face = entities.add_face pt1, pt2, pt3, pt4
new_face.pushpull thickness
end
end
把上面的代码复制存在一个文本文件里面,重命名为stairs.rb,放在C:\Program Files\Google\Google SketchUp 8\Plugins里面,再重新打开SU,在菜单项[插件]中可以找到Draw stairs,点击就能看到在SU中已经产生的结果。
|