Unexpected group behavior with grep

sketchup
bugsplat
groups

#1

Hello all,
I’m fairly new to ruby and SketchUp’s API though I have spent some time written a short bit of code to help generate and clean up diagonal lines on a surface. I welcome any feedback, code critiques and help. The code seems to work fine up until I need to ‘grep’ the edges within the overall group and delete them. In SketchIp model space I can see the lines are indeed selected but the group hierarchy is not as I would expect. Additionally, when trying to ‘clear’ or ‘erase’ the unnecessary edges, a bugsplat occurs. Does anyone here have any ideas?

Grep Problems.rb (2.6 KB)


#2

See if this is what you are trying to do.

Grep Problems v2.rb (2.4 KB)


#3

I don’t think ‘grep’ is the problem. Instead I think the problem is that you are trying to put lines from diagonal_line_group3 into group_to_delete which is a sub_group of group3. You can’t have the same edges in two groups at the same time.

Deleting all edges that are associated with 1 face deletes the boundary edges of the face which deletes the face.


#4

Thank-You so much, that worked perfectly! If I may ask a few questions; In general is the ‘select’ enumerable a better approach to selecting faces and edges within a group? Also does ‘times’ automatically convert to an integer? I had assumed ‘to_i’ was needed.


#5

Thank-you for your reply. I think I understand what you are saying, but does the sequence of code not act as a sort of cut-paste between groups when using grep and each and adding to arrays? I had also assumed that ‘each’ in the code was only selecting the edges that we’re not bounding a face.


#6

grep merely returns a list of references to the items not the physical item. The ‘cut and paste’ operation would require actually adding a copy of the entity to the target group then deleting it from the source group.

Your code specified a face count <= 1 which included all bounding edges because they are associated with 1 face.