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__)
输入参数:
生成球体: