In this case I am trying to hide the edges at the perimeter of the wall only.
I can easily hide all the edges given the group, using this piece of code I am currently using:
all_clad_edges = group_clad.entities.grep(Sketchup::Edge)
for edgei in all_clad_edges do
edgei.hidden = true
end
I know the dimensions of the wall panel (width and height) and all of the x, y, z data so I’m thinking there should be a way to select or find just those edges along the perimeter…
I think that if you can write down a clear, precise definition of what you mean by “perimeter” the exercise will lead you to the required logic for your code.
Off the top I think if I can find the four faces that define the top, bottom and two sides of the panel I can then run through all the edges and see which ones are common to any of these four faces.
Actually I’m making this problem too hard, just get the four faces and then use the edges method to gather all the edges that are bounding these four faces.
Okay, easy. Think first about the right-side edges in your images. They all will have the same x and y, but some edges differing z coordinates.
right_side_edges = all_clad_edges.select do |edge|
pt1 = edge.start.position
pt2 = edge.end.position
p1.x == x && pt1.y == y && pt2.x == x && pt2.y == y
end
EDIT: hmmm … perhaps not true ? The horizontal edges have the same x and z, but different y value.
Correct, there are more than four faces however there are only ever four faces that define the perimeter of the cladding: top, bottom, left and right.
I think this is the best way to go. I just need to figure out a good robust way of finding them, which actually shouldn’t be too hard since I know the x,y dimensions of the panel.
all_clad_faces = group_clad.entities.grep(Sketchup::Face)
# Hide perimeter_faces:
all_clad_faces.each do |face|
next unless face.normal.parallel?(X_AXIS) || face.normal.parallel?(Z_AXIS)
face.edges.each { |edge| edge.hidden= true }
end
You might need to have references for the group x_axis and y_axis if not aligned to the model axis.
ADD: Something like ?
all_clad_faces = group_clad.entities.grep(Sketchup::Face)
# Hide perimeter_faces:
gt = group_clad.transformation
x_axis, y_axis = gt.xaxis, gt.yaxis
all_clad_faces.each do |face|
next unless face.normal.parallel?(x_axis) || face.normal.parallel?(y_axis)
face.edges.each { |edge| edge.hidden= true }
end
… depends upon whether face.normal returns a vector per the internal group axis or not.
It also may depend upon what the current edit context (active_path) is.
That’s because vertices are used by geometry but aren’t themselves geometry. You can get them from an entity, but there is no collection you can grep for them.
I don’t think my algorithm is 100% bullet proof yet but it does the job for now. The trick was to grab the back face of the cladding which will always be a single face with its normal vector in the positive Y direction. Once I have that it isn’t too hard to grab strategic vertices on that face along the perimeter and then find the perimeter faces themselves.
I guess I mostly solved this one myself but it certainly helped to bounce ideas back and forth. Sometimes that is all that is needed to take the blinders off and then see a novel solution that was not immediately apparent.
Once again thank-you Dan, your help is duly noted and much appreciated.