@michaelazer said:
Thanks, TIG. I think I mixed up with the logic of Sketchup.
(1) Does count=faces.length count all faces on the screen OR in the array I made? It's 'faces' in the array you have made - so it counts just the faces that match your pattern.
(2) If a user deletes a face manually, will it be removed from the array? OR only from the screen? When a users erases a face it vanishes from the model's entities collection. If you have made the array of faces before the deletion then the now deleted face is still counted - because the array is a list of faces that matched the pattern at the moment the list was made... You can check for each face's 'validity' before 'counting' thus:
count=0; faces.each{|face|count+=1 if face.valid?}
Now 'count' only includes 'valid' [i.e. NOT-deleted faces.
Again this is dependent on the moment you make the count.
The array 'faces' includes all matching faces at the moment the list is made.
The 'count' is now the number of valid faces within that array [they were check to be 'matching'].
If the user erases another face after the count is made you are again 'out of step'.
Similarly if additional matching faces are added after the matching 'faces' array is compiled the list is incomplete.
It's easy enough to have some code to compile a list of matching faces and count valid ones at various stages of your tool's use, just remember to do it at the appropriate moment to avoid having out of date information in the array or count...]
(3) If the answer to (2) is "only from the screen" does this mean that if I re-draw the array, will the shape that the user deleted get re-drawn?
Thanks, again.The array is only a list of faces that match your pattern. You can't 'redraw the array' as it's a list of references to faces only. If a face is deleted from the model you can no longer access its information as it no longer exists. If you mean 'remake' the array you can just rerun the code (remembering to empty the array first with faces=[]), and the new list will no longer include the face that was erased. If you want to remember faces even if they are gone you can make an array of say 'face_points' and later use those to recreate a missing face... this is porbably more complex than you want... for each face face_points=[]; face.vertices.each{|v|face_points<<v.position}