Set up new entities to group or create a new entites list

Is it possible to create a new entities container for a group? or is it possible to add new entity to an existing group?

I am wondering if this is the right function for that:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.pages.first.entities

# From here, we can iterate over the entities in draw order or pick order
entities.each { |entity|
  puts entity
}
entities.reverse_each(skip_locked: true) { |entity|
  puts entity
}

however, I am wondering how this doc document.layout is created or formed. as when I create a new file, there are only one *.skp file being created.

That is, whenever we right click on an existing group. The first option shown up is the “Entity Info”. Is it possible to create an customized Entity Info just down the existing one?

Or is it possible to add new items in the Entity Info?

Furthermore, I would like to create something to export the modified Entity Info just like some plugins which create a cutlist of the object.

In your snippet above, …

… this statement opens an existing .layout document from the C disk drive.

You are confounding 2 separate APIs.
The LayOut API is for working with .layout files that users open in the LayOut application.

Layout::Entity class is 2D and NOT the same as Sketchup::Entity 3D class.
They are saved in different documents (files).

Whenever you make changes to a .layout file (whether new or existing) you need to save it.


I suggest you first learn Ruby, then the SketchUp API, … before you try to tackle the LayOut API.


YES. It is easy.

model = Sketchup.active_model
ments = model.entities
group = ments.add_group
gents = group.entities
# Immediately add a construction point to prevent Ruby garbage collection
cpt = gents.add_cpoint(ORIGIN)
# Now add more entity objects to gents. Erase cpt when done.

YES. You need only have (or find) the reference to the existing group.

There is a very informative topic thread on finding a group by name already …

You can use those examples but substitute a test for your plugin attribute dictionary, if desired.