Pushpull BUG?

group.entities.map {|e| e.pushpull(100) if e.is_a?Sketchup::Face }

group is including only one face
but this crashes everytime
must be a bug

I drew a rectangular face, grouped it, selected the group, and then ran

group = Sketchup.active_model.selection[0]
group.entities.map {|e| e.pushpull(100) if e.is_a?Sketchup::Face }

It worked as expected, without crashing. That makes me suspect there is something odd about your group variable that may be triggering a bug. Can’t tell without knowing the details of how you obtained it.

I’d suggest going about this a different way:

group.entities.grep(Sketchup::Face).each {|f| f.pushpull(100)}

I suspect there may be some issue with pushpull modifying the entities collection while map is iterating over it. That is, pushpull adds both a new bottom face and side faces, each of which may then pick up as eligible for the map.

2 Likes

must be it , it crashes after running and runing.
but why not u?

and i learned a new thing thanks u!

Just an FYI, … Enumerable#grep itself allows a block arguement, so the .each call is unneeded.

Ex:

group.entities.grep(Sketchup::Face) { |f| f.pushpull(100) }
1 Like

without “each”, it crashed again
guessing “each” ends enumerating and create a new array
tired of crashing, i use this instead :tired_face: , since i only need to manipulate a single face group

group.entities.grep(Sketchup::Face)[0].pushpull(100)

Good afternoon All,

It works fine for me but it increase the thickness of all the groups in the drawing. I would like to do it for just a selection of groups. Could anybody drop me a few line ? Thanks in advance

amount = 5.0 # Set to desired push pull amount
model = Sketchup.active_model
model.selection.grep(Sketchup::Group) do |grp|
  # For each group find the first face and push pull it:
  face = grp.entities.find {|ent| ent.is_a?(Sketchup::Face) }
  face.pushpull(amount) if face
end
1 Like

He had an other problem where a groups that shares the same definition. I answered him on other topic.
(However your code is more polished… :wink: )

Yea, okay I just read that one.