Override copy/paste method

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.

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.

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

If your objects (like the table) are component instances or groups, you can create new instances at a new location (transformation) using the Entities.add_instance factory method.

Note: The Group#copy method is a convenience wrapper for the above. Ie, it is the same as:

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.