Observer for multi-copy elements with Move tool

In sketchup there is a function to copying and multiplying geometry with move tool.

For example:
I have a group, copied it using move tool (ctrl), press ‘*7’ and I have a lot of groups.

Can I catch somehow that new elements and modify them?
For example to change copied names to ‘Copied Element of Wall’
In the past I have used EntityObserver, but resigned with it, because sketchup crashes and started using ToolObserver.

But after typing ‘*7’ and pressing ok the observer doesn’t response

Note that groups are just instances of “special” component definitions that do not appear in the component browser panel. So, to modify them, you must modify their definition’s entities. If you wish to modify these group instances separately, then you must make each instance unique, so it has a unique component definition.

To “catch” new instances being created you can attach a DefinitionObserver with a #onComponentInstanceAdded callback defined to the group’s definition object, …

… OR, … you can use the snapshot pattern (implementing array subtraction):

before = model.active_entities.grep(Sketchup::Group)
## do the multiple copy
after = model.active_entities.grep(Sketchup::Group)
added_groups = after - before

You need to be careful about modifying entities within observer callbacks. This could trigger more observers to fire, which could crash SketchUp. So try to cache references to added or modified entities in an array and process them after observers have called. Possibly using a timer.

DefinitionObserver is a part of EntityObserver which…

Which ofcource you mentioned that I would need to be careful with it. From my previous experience I would avoid this observer

That’s interesting solution. Do you have experience with that kind of solution? For example if I would add ‘checker’ per 0.1sec to ‘catch’ added group. if that would impact SketchUp? Or make more unstable?

---- Edit:

Aaah, your proposition was to ‘detect’ that change using observers and use the logic inside ‘timer’ for example 0.5 sec after that change. Right?
Yeee. that could be solution

1 Like


1 Like