# Override copy/paste method

**URL:** <https://forums.sketchup.com/t/override-copy-paste-method/167757>\
**Category:** Ruby API\
**Created:** [June 16, 2021, 8:51am UTC](https://forums.sketchup.com/t/override-copy-paste-method/167757 "2021-06-16T08:51:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattda909](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@mattda909](https://forums.sketchup.com/u/mattda909)\
**Post date:** [June 16, 2021, 8:51am UTC](https://forums.sketchup.com/t/override-copy-paste-method/167757/1 "2021-06-16T08:51:39Z")

</div>

Hello,  
I have some objects that have tags and I would like to copy these objects and assign new tags directly to them, but I don’t know how to override the Sketchup.send\_action(CMP\_PASTE) action.  
For example I have my table with tag t1 after copying it I want the new table (copy-table) to be tag t2.

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [June 16, 2021, 9:44am UTC](https://forums.sketchup.com/t/override-copy-paste-method/167757/2 "2021-06-16T09:44:48Z")

</div>

There is no API for that.

There’s also not really a notion within SketchUp to know when something is being copied. It just knows that things are created/deleted.

I guess you could monitor the active\_entities with an entities observer and catch new entities being created. If your object (I assume a group or component instance) stored an attribute to ID it you could check that and reassign tags as needed. For instance, if you added an attribute with the PID of the original object, then the copy would also get that attribute copied, but it’d have a new PID. You could then check that the attribute ID matched the PID and assume that’s a copy.

---

<div class="post-metadata">

**Author:** ![mattda909](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@mattda909](https://forums.sketchup.com/u/mattda909)\
**Post date:** [June 16, 2021, 4:06pm UTC](https://forums.sketchup.com/t/override-copy-paste-method/167757/3 "2021-06-16T16:06:09Z")

</div>

ok, I’ll try to make my own copy function

---

<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:** [June 16, 2021, 5:24pm UTC](https://forums.sketchup.com/t/override-copy-paste-method/167757/4 "2021-06-16T17:24:17Z")

</div>

If your objects (like the table) are component instances or groups, you can create new instances at a new location ([transformation](https://ruby.sketchup.com/Geom/Transformation.html)) using the [`Entities.add_instance`](https://ruby.sketchup.com/Sketchup/Entities.html#add_instance-instance_method) factory method.

> **Note** : The [`Group#copy`](https://ruby.sketchup.com/Sketchup/Group.html#copy-instance_method) method is a convenience wrapper for the above. Ie, it is the same as:
> 
> ```ruby
> group2 = entities.add_instance(group1.definition, group1.transformation)
> 
> ```
> 
> This means that `group2` would be superimposed over `group1` and would need to be moved to a new location.

After your new instances exist, create new tag(s) then assign the new instance(s) to use them.
