佩戴红宝石的草图大师(Ruby for Sketchup)--STLslicer(1)

STLslicer

初衷

  • 首先。。。

絮叨

课题的原因,需要一个演示图片,做不好就开始犯牛劲。。。费劲学习这个。

首先的剖面方法:

见上
以下是修订版:

def sep(p='xy',length=0, no = 0)
  entities = Sketchup.active_model.entities
  if p == 'xy'
    sp = entities.add_section_plane([0, 0, length], [1.0, 0, 0])
  elsif p == 'yz'
    sp = entities.add_section_plane([length,0,0],  [0, 0, 1.0])
  else p == 'xz'
    sp = entities.add_section_plane([0, length, 0], [0, 1.0, 0])
    end
  sp.name=p
  sp.symbol= no.to_s
  sp.activate
end

sep

sep "yz", -15, 15

sep "xz",9, 9

结果如下图:

如图

剖切循环(loopSlicers):

按照一定的厚度,沿着坐标轴,做系列剖切:

如下图,立方体的直径为10mm,每2mm一个剖切面,沿着Z轴:

(0..10).each{ |i|
  if i%2==0
    sep i.to_l.mm, "yz", i
  end
}

在这里插入图片描述

boundingbox的引入

对于复杂的立体图,需要引入绑盒

这个有点难,我费了不少劲儿。。。

直接上代码:

def l2i(leng)
  num = leng.to_mm.to_l.to_i
end

model = Sketchup.active_model
entities = model.entities
entities.each { |entity|
  if entity.class == Sketchup::ComponentInstance
    name = entity.definition.name
    defn = entity.definition
    bbox = defn.bounds
    @w = bbox.width.to_l.to_s
    @h = bbox.height.to_l.to_s
    @d = bbox.depth.to_l.to_s
    puts name + " " + @w + " " + @h + " " + @d
    pts = []
    pts[0] = bbox.corner(0)
    pts[1] = bbox.corner(1)
    pts[2] = bbox.corner(2)
    pts[3] = bbox.corner(3)
    pts[4] = bbox.corner(4)
    pts[5] = bbox.corner(5)
    pts[6] = bbox.corner(6)
    pts[7] = bbox.corner(7)
    #puts pts[0][0]
  
    xx = l2i pts[0][0]
    yy = l2i pts[0][1]
    zz = l2i pts[0][2]
    
    xw = l2i bbox.width
    yd = l2i bbox.depth
    zh = l2i bbox.height
    
    
    # puts xx.class, xx.to_l.mm, xx+xw
    
    # sep xx, xx, "yz"
    
    (zz..zh-zz).each{ |i|
        sep i.to_l.mm, "xy", i-zz
    }

  end
}

在这里插入图片描述

(…未完待续。。。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jumbo Jing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值