SKETCHUP RUBY开发试验一 画球的插件

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__)

 

输入参数:

 

生成球体:

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值