I am trying to add to a group using a definition and I am not sure what I am doing wrong. Maybe I need to create two separate groups and merge them. maybe the group should be a global variable? The first photo shows the first via with the second via commented out and the second shows when I try to run the same definition twice. It says that the main_face has been deleted. Shouldn’t it be recreated as it runs through the method a second time though?
SKETCHUP_CONSOLE.clear
def via(group,pts,thickness,lateral_extension=0,inversion=false) #,:mode=>nil)
min_x = pts.map{|p| p[0]}.min
max_x = pts.map{|p| p[0]}.max
min_y = pts.map{|p| p[1]}.min
max_y = pts.map{|p| p[1]}.max
main_face = group.entities.add_face pts
if main_face.normal.z = -1
main_face.reverse!
end
for v in main_face.vertices do
min_v = v.position
break if min_v.x == min_x && min_v.y == min_y
end
main_face.pushpull thickness
cut_vector1 = [-lateral_extension,0,thickness]
cut_vector2 = [0,0,thickness]
cut = group.entities.add_line(min_v,min_v+cut_vector1)
cut2= group.entities.add_line(min_v+cut_vector2,min_v+cut_vector1)
cut_edges = group.entities.grep(Sketchup::Edge)
cut_edges.each(&:find_faces)
cut.faces[0].followme main_face.edges
if inversion == true
center = group.bounds.center
vector = Geom::Vector3d.new(1,0,0)
angle = 180.degrees
transformation = Geom::Transformation.rotation(center, vector, angle)
group.transformation= transformation
end
return group
end
ents = Sketchup.active_model.entities
etch = ents.add_group
z = 0
pts = [0,0,z], [5,0,z], [5,8,z], [0,8,z]
etch1 = via(etch,pts,10,6)
etch2 = via(etch,pts,10,6,true)