本文主要是介绍佩戴红宝石的草图大师(Ruby for Sketchup)--STLslicer(1),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
STLslicer
初衷
- 首先。。。
絮叨
课题的原因,需要一个演示图片,做不好就开始犯牛劲。。。费劲学习这个。
首先的剖面方法:
见上
以下是修订版:
def sep(p='xy',length=0, no = 0)entities = Sketchup.active_model.entitiesif 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])endsp.name=psp.symbol= no.to_ssp.activate
endsepsep "yz", -15, 15sep "xz",9, 9
结果如下图:
剖切循环(loopSlicers):
按照一定的厚度,沿着坐标轴,做系列剖切:
如下图,立方体的直径为10mm,每2mm一个剖切面,沿着Z轴:
(0..10).each{ |i|if i%2==0sep i.to_l.mm, "yz", iend
}
boundingbox的引入
对于复杂的立体图,需要引入绑盒
这个有点难,我费了不少劲儿。。。
直接上代码:
def l2i(leng)num = leng.to_mm.to_l.to_i
endmodel = Sketchup.active_model
entities = model.entities
entities.each { |entity|if entity.class == Sketchup::ComponentInstancename = entity.definition.namedefn = entity.definitionbbox = defn.bounds@w = bbox.width.to_l.to_s@h = bbox.height.to_l.to_s@d = bbox.depth.to_l.to_sputs name + " " + @w + " " + @h + " " + @dpts = []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.widthyd = l2i bbox.depthzh = 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
}
(…未完待续。。。
这篇关于佩戴红宝石的草图大师(Ruby for Sketchup)--STLslicer(1)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!