SKETCHUP帶有RUBY介面,可以輕鬆開發自己需要的外掛程式。先做一個畫球的實驗一下,效果還可以。不過有一個小問題,就是連續畫同一個球(半徑和球心相同)時,不僅新的球看不到,連原來的也刪除了,還要再研究研究,呵呵。
代碼如下:
require 'sketchup.rb'
@cx = 0
@cy = 0
@cz = 0
def drawShpere(center, radius)
# Access the Entities object
ents = Sketchup.active_model.entities
# Create the initial circle
circle = ents.add_circle center, [0, 0, 1], radius
circle_face = ents.add_face circle
# Create the circular path
path = ents.add_circle center, [0, 1, 0], radius + 1
# Create the sphere
circle_face.followme path
# Remove the path
ents.erase_entities path
end
def auto_sphere
prompts=["CX","CY","CZ","R"]
types=["","","",""]
title="Shpere Parameter"
@cx=0 if not @cx
@cy=0 if not @cy
@cz=0 if not @cz
@radius=5 if not @radius
values=[@cx,@cy,@cz,@radius]
popups=["","","",""]
results=inputbox( prompts, values, popups, title )
return nil if not results
@cx=results[0]
@cy=results[1]
@cz=results[2]
@radius=results[3]
center = [@cx,@cy,@cz]
drawShpere(center, @radius)
end
if( not file_loaded?(__FILE__) )
UI.menu("Plugins").add_item("AutoSphere"){auto_sphere}
end
file_loaded(__FILE__)
輸入參數:
產生球體: