Sketchup Bugsplat on modify the entities group

Create Box >>> Modify Box >>> Close Sketchup = Bugsplat

module Ahmad2020
  module Pondasi

    extend self

    KUNCI ||= Module.nesting[0].name.gsub('::','_')

    def create_box
      #Create the group and set attributes
      ents = Sketchup.active_model.entities
      car_group = ents.add_group

      main_face = car_group.entities.add_face(
        [0,0,0], [6,0,0], [6,8,0], [0,8,0]
      )
      main_face.reverse!
      main_face.pushpull(5)

      car_group.set_attribute(KUNCI, "bebas", "bebas")
    end

    def modify_box
      # Get attributes and Change entities
      groups = Sketchup.active_model.entities.grep(Sketchup::Group)
      groups.select! {|e| e.attribute_dictionary(KUNCI) }

      groups.each {|e|
        old  = e.entities.to_a
        temp = e.entities.add_group(old)
        main_face = e.entities.add_face(
          [0,0,0], [6,0,0], [6,8,0], [0,8,0]
        )
        main_face.reverse!
        main_face.pushpull(10)
        temp.erase!
      }
    end

    if !defined?(@loaded)
      menu = UI.menu("Plugins").add_submenu(KUNCI.gsub('_',' '))
      menu.add_item('Create Box') { create_box() }
      menu.add_item('Modify Box') { modify_box() }
      @loaded = true
    end

  end
end

I did not get a BugSplat! with SketchUp 2020.2.172, nor 2021.1.299 (on Windows.)

problem

Your code appears to have created an invalid geometry. Try to check Model Info>>Statistics>>Fix Problem before you quit.

On Windows only, you can call it by using this:

Sketchup.send_action(21124)

(I do not have BugSplat! either! )

Just a theory, but I wonder if the issue is with creating a new group using entities from the same group?

1 Like

sorry there are no internet connection in mars. wow…you know everything. what food you eat, what book you read. i learn ruby sketchup 3 years. but i dont know anything. i just read book Automatic SketchUp by Matthew Scarpino. btw thank you very much much much for the respond…sorry my english

Please submit BugSplat when you encounter them. They are very useful statistics to us.

Did you submit at least one of them? And enter some kind of information that we can use to lookup your crash?

2 Likes

Creating a group from existing entities isn’t recommended. If you want to delete the existing content of the group, you can delete them directly.

e.entities.erase_entities(e.entities.to_a)

or this

e.entities.clear!

He actually is trying to redraw and replace the entities of a definition when the user chooses a different design or size. (He showed me a pier footing as an example.)

Consider changing to

ents = Sketchup.active_model.active_entities

You cannot add a group directly into model.entities AND add objects into it at the same time as you define it.
You can only do that with model.active_entities

Your temp = e.entities.add_group(old) will almost certainly give a bugsplat when ‘old’ is not in the model.active_entities context…

In fact I can’t see why you do it this way anyway ??
If you simply collect all groups which have your attribute_dictionary and add the new face, pushpull etc, then where is your ‘temp’ step needed ???
You make it and erase it without ever needing it - except when it bugsplats !
You can clear each group’s existing faces etc before adding the new ones by using e.entities.clear! immediately before adding the new faces etc back into the group…

1 Like

This is only 1 in a series of attempts. The others were either in another topic thread or a PM thread.

I asked the same question. But the OP insists on trying to replace the entities of a group, instead of replacing the old group with a new group (or component.)

There’s nothing wrong with replacing the contents of a group. This is the foundation to many parametric extensions. It keeps properties, attributes, references in other extensions etc.

However, this

groups.each {|e|
  old  = e.entities.to_a
  temp = e.entities.add_group(old)
  main_face = e.entities.add_face(
    [0,0,0], [6,0,0], [6,8,0], [0,8,0]
  )
  main_face.reverse!
  main_face.pushpull(10)
  temp.erase!
}

can be replaced with this

groups.each {|e|
  e.entities.clear!
  main_face = e.entities.add_face(
    [0,0,0], [6,0,0], [6,8,0], [0,8,0]
  )
  main_face.reverse!
  main_face.pushpull(10)
}

You don’t need to cerate yet another group to clear the content of a group.

That wasn’t the purpose of creating the temp group. It was (I think) mainly to prevent merging of new geometry. (But perhaps also there was some data attached to the old geometry that needed to be copied to the new geometry? [I can’t remember.] The condensed snippet above does not show this.)

But yes, I would have cleared and just added a temp cpoint if the code had the undesired effect of GC’ing the group before the new geometry could be added. (And yea, rather attach data if possible at the group level than the element level.)

But again, this is related to a bunch of his other topic threads. You’d have to go through his recent activity to try to understand what he’s trying to do.

i have did it. because of help from this forum specially DanRathbun. Thank you for you all. my plugin almost complete. i hope i can share in this forum. before that i must find “what is poor”. sorry my english
sklik

1 Like