Skip to content

Instantly share code, notes, and snippets.

@deathbob
Created April 1, 2013 04:07
Show Gist options
  • Save deathbob/5283198 to your computer and use it in GitHub Desktop.
Save deathbob/5283198 to your computer and use it in GitHub Desktop.
Sketchup hell solved
model = Sketchup.active_model
entities = model.entities
entities.clear!
# Draw a cylinder
basegroup = entities.add_group
basegroupentities = basegroup.entities
center_point = Geom::Point3d.new(0,0,0)
normal_vector = Geom::Vector3d.new(0,0,1)
radius = 10
edgearray = basegroupentities.add_circle center_point, normal_vector, radius
first_edge = edgearray[0]
first_edge.find_faces # needed to create face between edges
main_face = first_edge.faces.first
main_face.reverse! if main_face.normal.z < 0
main_face.pushpull 10
base_trans = basegroup.transformation
# Create the star
cutgroup = entities.add_group
cutgroupentities = cutgroup.entities
star_z = 0
pt1 = [0, 1, star_z]
pt2 = [-0.351, 0.509, star_z]
pt3 = [-0.951, 0.309, star_z]
pt4 = [-0.488, -0.209, star_z]
pt5 = [-0.588, -0.809, star_z]
pt6 = [ 0.0, -0.409, star_z]
pt7 = [ 0.588, -0.809, star_z]
pt8 = [0.488, -0.209, star_z]
pt9 = [ 0.951, 0.309, star_z]
pt10 = [0.351, 0.509, star_z]
# Draw the face, extrude the star
base = cutgroupentities.add_face(pt1, pt2, pt3, pt4, pt5, pt6, pt7, pt8, pt9, pt10)
base.reverse! if base.normal.z < 0
base.pushpull 11
cut_trans = cutgroup.transformation
puts cutgroupentities.count
puts basegroupentities.count
cg = cutgroup.entities.to_a
bg = basegroup.entities.to_a
puts cut_trans.inspect
puts base_trans.inspect
puts cutgroupentities.count
puts basegroupentities.count
puts bg.size
puts cg.size
Sketchup.active_model.entities.intersect_with true, cut_trans, basegroup.entities, base_trans , true, bg
cutgroup.explode
basegroup.explode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment