初來SU吧,主要是為了學習SU的二次開發(fā),發(fā)些自己找的,學習小例子,以記。
下面的這個例子,是在SU中自動產(chǎn)生一些臺階,可以通過修改一些參數(shù),改變產(chǎn)生的數(shù)量,階高等,,
我也只是初學,如果有比我還菜的,有興趣的可以跟貼,相互學習。
# # 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中已經(jīng)產(chǎn)生的結果。
|