Ruby代码"自动草图"二十面体

时间:2016-01-13 03:18:31

标签: ruby sketchup

我的名字是Jim,我很难在Sketchup页面上显示我的第一个ruby Sketchup代码。 我有Windows 8 Sketchup 2016专业版

下面文件中的代码基本上是从书中复制出来的。自动Sketchup" 我是Ruby的新手,我无法发现遗漏的东西。 必须有其他东西才能让它运行。 假设在草图中添加二十面体。

如果我能克服这个驼峰,我会很高兴。 如果有人能指出我正确的方向,我将永远感激你的帮助。

mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
view = mod.active_view

Ss = 1.11935599 # Short side
Gr = 1.65742 # Long side

pt0 = Geom:: Point3d.new 0,Ss,Gr
pt1 = Geom:: Point3d.new 0,-Ss,GS
pt2 = Geom:: Point3d.new Gr,0,Ss
pt3 = Geom:: Point3d.new -Gr,0,Ss
pt4 = Geom:: Point3d.new Ss,-Gr,0
pt5 = Geom:: Point3d.new -Ss,-Gr,0
pt6 = Geom:: Point3d.new 0,Ss,-Gr
pt7 = Geom:: Point3d.new 0,-Ss,-Gr
pt8 = Geom:: Point3d.new Gr,0.-Ss
pt9 = Geom:: Point3d.new -Gr,0,-Ss
pt10 = Geom:: Point3d.new Ss,Gr,0
pt11 = Geom:: Point3d.new -Ss,Gr,0

pm = Geom:: PolygonMesh.new 12, 20

 #Top half
pm.add_polygon pt0, pt1, pt2
pm.add_polygon pt0, pt1, pt3
pm.add_polygon pt1, pt4, pt5
pm.add_polygon pt1, pt4, pt2
pm.add_polygon pt1, pt3, pt5

 #Middle
pm.add_polygon pt4, pt5, pt7
pm.add_polygon pt2, pt8, pt4
pm.add_polygon pt10, pt11, pt0
pm.add_polygon pt3, pt9, pt5
pm.add_polygon pt2, pt8, pt10
pm.add_polygon pt2, pt0, pt10
pm.add_polygon pt9, pt5, pt7
pm.add_polygon pt7, pt8, pt4
pm.add_polygon pt11, pt9, pt3
pm.add_polygon pt11, pt3, pt0

 #Bottom half
pm.add_polygon pt6, pt7, pt8
pm.add_polygon pt6, pt7, pt9
pm.add_polygon pt6, pt10, pt11
pm.add_polygon pt6, pt10, pt8
pm.add_polygon pt6, pt9, pt11

 #Draw face in the mesh
ent = Sketchup.active_mod.entities
ent.add_faces_from_mesh pm

1 个答案:

答案 0 :(得分:1)

在修复一些拼写错误后,您的代码确实有效。我改变了这两行,如下所示:

pt1 = Geom:: Point3d.new 0,-Ss,Gr
pt8 = Geom:: Point3d.new Gr,0,-Ss

并完全删除了这一行

ent = Sketchup.active_mod.entities

尝试这种方式。有些面最终会反转,但几何体确实会被创建。