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
}
(…未完待续。。。