# .add\_group causes deleted entity

**URL:** <https://forums.sketchup.com/t/add-group-causes-deleted-entity/346140>\
**Category:** Ruby API\
**Created:** [April 13, 2026, 9:51pm UTC](https://forums.sketchup.com/t/add-group-causes-deleted-entity/346140 "2026-04-13T21:51:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![JimG55](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@JimG55](https://forums.sketchup.com/u/JimG55)\
**Post date:** [April 13, 2026, 9:51pm UTC](https://forums.sketchup.com/t/add-group-causes-deleted-entity/346140/1 "2026-04-13T21:51:35Z")

</div>

In my program, the line:

saddle1 = newcomp.entities.add\_group

causes “undefined method ‘entities’ for #\<Deleted Entity:0x470…….

the line before this one is: puts ““deleted ? = #{newcomp.deleted?}”

That outputs “deleted ? = false”, which makes sense because newcomp was just created. If I don’t try to add a saddle then the whole program runs without error. It looks alot like garbage collection is deleting newcomp just by calling .entities.add\_group on it.

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [April 13, 2026, 10:05pm UTC](https://forums.sketchup.com/t/add-group-causes-deleted-entity/346140/2 "2026-04-13T22:05:12Z")

</div>

SketchUp is very aggressive about deleting empty groups. So, if you create one the longstanding safeguard is to immediately add a cpoint as a placeholder that you delete after you have added the actual content you need.

---

<div class="post-metadata">

**Author:** ![JimG55](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@JimG55](https://forums.sketchup.com/u/JimG55)\
**Post date:** [April 13, 2026, 10:28pm UTC](https://forums.sketchup.com/t/add-group-causes-deleted-entity/346140/3 "2026-04-13T22:28:41Z")

</div>

I don’t get it. newcomp is a component instance fully defined and transformed and it works. I am trying to create a saddle group for it. But newcomp deletes before I can add a single point to saddle.

My chatbot told me to just to add “newcomp.make\_unique” but that changed nothing.

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [April 13, 2026, 10:38pm UTC](https://forums.sketchup.com/t/add-group-causes-deleted-entity/346140/4 "2026-04-13T22:38:04Z")

</div>

I think we need to see more of the surrounding code to figure out what is happening.

---

<div class="post-metadata">

**Author:** ![JimG55](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@JimG55](https://forums.sketchup.com/u/JimG55)\
**Post date:** [April 13, 2026, 11:00pm UTC](https://forums.sketchup.com/t/add-group-causes-deleted-entity/346140/5 "2026-04-13T23:00:50Z")

</div>

Here is a large excerpt. More available if necessary:

```
side_noz_array=\["tank child","Pipe","NozzleTankSide",@scope,@wbs,@system,"S1","","","",

                "bottom outlet nozzle","","","SS02","OUT","","","","","",90,3,"Radial",0,"",

                "","",side_noz_base_pt.x/12.0,side_noz_base_pt.y/12.0,

                side_noz_base_pt.z/12.0,

                0,0,3,"ANSI",8.0,false,"","",0,"","",@equipID,""\]

@data_array\[42\] << side_noz_array  

top_noz_base_pt=Geom::Point3d.new(0,tankRadius,@tankBaseHeight+@tankSS-3)

top_noz = ent.add_group()

top_noz_array = \["tank child","Pipe","NozzleTankHead",@scope,@wbs,@system,"B","","","",

                "top center nozzle","","","SS02","OUT","","","","","",0,0,"VERTICAL",0,"",

                "","", top_noz_base_pt.x/12.0, top_noz_base_pt.y/12.0,

                top_noz_base_pt.z/12.0,

                0,90,3,"ANSI",8.0,false,"","",0,"","",@equipID,""\]

@data_array\[42\] << top_noz_array  

heightAdjustment=50

ent.erase_entities(tankcircle)

@groundClearance=24

@supportSpacingFactor=50.0 # zero to 100

supportSpacing=(@supportSpacingFactor/100.0)\*(@tankSS-4)/2.0

tp=Geom::Transformation.new(\[@x,@y,@z+@tankDiameter+24\])

tr1=Geom::Transformation.rotation(ORIGIN,Z_AXIS,@orientation.degrees)

tr2=Geom::Transformation.rotation(ORIGIN,X_AXIS,90.degrees)

newcomp=this_model.active_entities.add_instance(new_comp_def,tp\*tr2\*tr1)

newcomp.make_unique

puts "deleted? #{newcomp.deleted?} nc = #{newcomp}"

saddle1 = newcomp.entities.add_group()

make_tank_saddle(saddle1, tankRadius, saddleWidth, saddleHeight, saddleLength)

```

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 14, 2026, 1:44am UTC](https://forums.sketchup.com/t/add-group-causes-deleted-entity/346140/6 "2026-04-14T01:44:54Z")

</div>

> [@JimG55](#):
>
> `saddle1 = newcomp.entities.add_group()`

If `newcomp` is a [`Sketchup::ComponentInstance`](https://ruby.sketchup.com/Sketchup/ComponentInstance.html) object, it does **not** have an `entities` method. Only the model litself and [`Sketchup::ComponentDefinition`](https://ruby.sketchup.com/Sketchup/ComponentDefinition.html) objects have an [`Entities`](https://ruby.sketchup.com/Sketchup/Entities.html) collection.

You really need to call:

```ruby
saddle1 = newcomp.definition.entities.add_group()

```

.. OR …

```ruby
saddle1 = new_comp_def.entities.add_group()

```

Prevent the group from being cleaned up:

```ruby
saddle1.definition.entities.add_cpoint(ORIGIN)

```

… and **delete** the line making `newcomp` unique.

---

<div class="post-metadata">

**Author:** ![JimG55](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@JimG55](https://forums.sketchup.com/u/JimG55)\
**Post date:** [April 14, 2026, 1:27pm UTC](https://forums.sketchup.com/t/add-group-causes-deleted-entity/346140/7 "2026-04-14T13:27:24Z")

</div>

Thanks Dan. This answer is clear and accurate, the opposite of what I got from my chatbot. AI is good at data mining but bad at computer programming. In my own defense, I suggest that the error message is misleading. newcomp is not deleted, it just has no entities method.

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [April 14, 2026, 1:57pm UTC](https://forums.sketchup.com/t/add-group-causes-deleted-entity/346140/8 "2026-04-14T13:57:52Z")

</div>

I wondered why you weren’t seeing that exception, which is why I requested a larger code context. I wasn’t sure what the thing you were calling a component really was.

Your experience fits with others I have helped: AI today generates usable code a lot of the time, but when it goes astray a non-programmer doesn’t know how to fix the errors. It often takes a long session of refining the request to get AI back on track.

---

<div class="post-metadata">

**Author:** ![JimG55](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@JimG55](https://forums.sketchup.com/u/JimG55)\
**Post date:** [April 14, 2026, 2:31pm UTC](https://forums.sketchup.com/t/add-group-causes-deleted-entity/346140/9 "2026-04-14T14:31:06Z")

</div>

Yes, I see now that I was not including quite enough code. I was assuming that everyone in the world knows what a “newcomp” is. My bad.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 14, 2026, 5:59pm UTC](https://forums.sketchup.com/t/add-group-causes-deleted-entity/346140/10 "2026-04-14T17:59:17Z")

</div>

> [@JimG55](#):
>
> In my own defense, I suggest that the error message is misleading. newcomp is not deleted, it just has no entities method.

Agreed. It should have output something like:  
`#<NoMethodError: undefined method ‘entities’ for #<Sketchup::ComponentInstance:0x470…>>"`

> [@JimG55](#):
>
> I was assuming that everyone in the world knows what a “newcomp” is.

I **did** see the line that created the object:

```ruby
newcomp = this_model.active_entities.add_instance(new_comp_def,tp\*tr2\*tr1)

```

* * *

BTW, it does not save the interpreter much work by collapsing spaces and it makes code much harder to read. Most code style guides say to always have a space on each side of an operator.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sketchup/original/3X/f/2/f2a121500b085ed60806607a82720b092d800bb3.png) [@system](https://forums.sketchup.com/u/system)\
**Post date:** [October 10, 2026, 9:51pm UTC](https://forums.sketchup.com/t/add-group-causes-deleted-entity/346140/11 "2026-10-10T21:51:48Z")

</div>

Closed on October 10, 2026, 9:51pm UTC

This topic was automatically closed after 180 days. New replies are no longer allowed.
