gpt4 book ai didi

ruby - 使用 Sketchup Ruby API 在圆柱体上打洞

转载 作者:太空宇宙 更新时间:2023-11-03 16:31:08 28 4
gpt4 key购买 nike

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

如果我用鼠标来做,这是可行的,但我发现用鼠标很难精确地放置和测量。不过,到目前为止,我还不能让它与脚本一起工作。目前我一直坚持在 pipe 上画不完整的圆圈,所以我无法找到脸并删除它。您应该能够在 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!

最佳答案

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

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

但是,如果您使用的不是 SketchUp 8 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:EntitySketchup:Entity 对象数组。

关于ruby - 使用 Sketchup Ruby API 在圆柱体上打洞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15694777/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com