1

Hi my name is Jim and I am having a very hard time just displaying my first ruby Sketchup code on the sketchup page. I have Windows 8 Sketchup 2016 pro

The code in the file below is basically copied out of the book " Automatic Sketchup " I am so new to Ruby that I can't detect what is being left out. There must be something else needed to make it run. It is suppose to add an icosahedron to the sketch.

If I could just get over this hump, I would be so happy. If someone could point me in the right direction I would be forever indebted for your help.

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
130jim
  • 11
  • 3

1 Answers1

1

Your code actually works after fixing a few typos. I changed these 2 lines as shown:

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

and removed this line altogether

ent = Sketchup.active_mod.entities

Give it a try that way. Some of the faces end up reversed but the geometry does get created.

Bugra Barin
  • 246
  • 1
  • 4