2

我正在编写一个脚本来在 SketchUp(免费版,Mac)中制作一个简单的长笛。我想制作一个管子,然后是穿过管子的圆柱体,画出管子和圆柱体之间的相交线,然后擦除圆柱体,留下圆圈从管子上切下来。

如果我用鼠标来做这件事,这很有效,但我发现用鼠标很难精确地放置和测量。不过,到目前为止,我还不能让它与脚本一起工作。目前我被困在管子上画不完整的圆圈,所以我找不到脸并擦掉它。您应该能够在 ruby​​ 控制台中运行以下脚本并明白我的意思。我究竟做错了什么?

entities = Sketchup.active_model.entities

# make tube
tube = entities.add_group
tube_inner = tube.entities.add_circle Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 5, 360
tube_outer = tube.entities.add_circle Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 6, 360
cross_section_face = tube.entities.add_face tube_outer
inner_face = tube.entities.add_face tube_inner
tube.entities.erase_entities inner_face
cross_section_face.pushpull -10, false

# make a cylinder that punches through the wall
hole_punch = entities.add_group
hole_outer = hole_punch.entities.add_circle Geom::Point3d.new(0,0, 5), Geom::Vector3d.new(0,1,0), 3, 360
face = hole_punch.entities.add_face hole_outer
face.pushpull 10, false

# draw the intersection lines and erase the hole punch
entities.intersect_with true, hole_punch.transformation, tube, tube.transformation, true, hole_punch
hole_punch.erase!
4

1 回答 1

1

确定相交后要擦除的正确面可能非常棘手。

但由于您使用的是圆柱体形状(即实体),我建议您使用 SketchUp 8 Pro 中引入的实体布尔运算。例如,您可以使用Group.subtracthttp://www.sketchup.com/intl/en/developer/docs/ourdoc/group#subtract

但是,如果您没有使用 SketchUp 8 Pro 或更新版本,那么您将无法使用这些方法。


替代解决方案 - 避免 Pro 版本的 Solid Tools 方法:

entities = Sketchup.active_model.entities

# (!) You created a circle with so many edges that at the scale
#     you drew it they where pushing the boundary of how small
#     units SketchUp can handle. (1/1000th inch).
#     If you has Edge Outline style enabled you could see that
#     not all edges where fully merged.
#     I reduced the curve segments from 360 to 180.
#     (Do you really need such a high mesh density anyway?)

# make tube
tube = entities.add_group
tube_inner = tube.entities.add_circle Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 5, 180
tube_outer = tube.entities.add_circle Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 6, 180
cross_section_face = tube.entities.add_face tube_outer
inner_face = tube.entities.add_face tube_inner
tube.entities.erase_entities inner_face
cross_section_face.pushpull -10, false

# make a cylinder that punches through the wall
hole_punch = entities.add_group
hole_outer = hole_punch.entities.add_circle Geom::Point3d.new(0,0, 5), Geom::Vector3d.new(0,1,0), 3, 180
face = hole_punch.entities.add_face hole_outer
face.pushpull 10, false

# draw the intersection lines and erase the hole punch
entities.intersect_with true, hole_punch.transformation, tube, tube.transformation, true, hole_punch
hole_punch.erase!

# Find all the edges that belong to the Circle elements drawn
# earlier (including the ones push-pulled).
# (Could also collect these earlier before intersecting by
#  collecting all non-smooth edges.)
circles = tube.entities.grep(Sketchup::Edge).select { |e| e.curve }.uniq
# Then we pick out all the faces that isn't connected to these edges and erase them.
new_faces = tube.entities.grep(Sketchup::Face).select { |f| (f.edges & circles).empty? }
entities.erase_entities( new_faces )

如果您真的想要 360 度圈,您可以放大组的内容 - 同时缩小组实例。这样,组定义的规模就更大了。(参见这篇关于 SketchUp 中的实例和定义的文章:http ://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/ )

此外,如果您希望面填充内外蒙皮之间的孔,您还需要与该部分相交。


请注意Entities.intersect_with描述 - 当前文档并不能很好地解释所有论点。有两种entities说法。

第一个应该是Sketchup::Entities相交对象应该出现的对象。(我有点惊讶它通过给它喂一个Sketchup::Group物体来起作用。)

第二个应该Sketchup::Entities- 那将失败。它必须是对象Sketchup:Entity或对象数组Sketchup:Entity

于 2013-03-31T22:57:05.723 回答