Advice on Copying Components Between Files to Avoid Creating Unique Definitions?

I’m looking for advice on how to copy components from one model (aka .SKP file) to another model, to cope with a definition-name problem. (I’m using SketchUp Pro 2018, but have licenses for all newer versions if they have different behaviors in this area.) Typically, I select a component in the source model, Copy it, and then Paste In Place in the destination model. That is fine, except that if the destination model already has (sub) components with the same definition name as what is being pasted, the new pasted definitions are (sometimes?) automatically made unique with #1 appended to their definition name.

For example, say that the destination model file has a component definition named “Screw NAS1218-6”. In the source model file, I have created a new hierarchical component named “X” which contains mostly brand new sub-components, but also has some instances of “Screw NAS1218-6” sub-components. When I copy the “X” hierarchical component from the source model and Paste In Place into the destination model, SketchUp creates a new definition named “Screw NAS1218-6#1” in the destination and associates the instances of the screws in “X” with that unique #1 definition. This “uniqueification” is annoying. I would like SketchUp to recognize the screws being pasted as identical to those already in the destination model, and associate the pasted instances with the destination’s existing definition. For what it’s worth, the screw definitions in both the source and target model are tagged with the same load file path on my computer (as shown in the Edit pane of the Component browser).

Paste in Place is very handy to preserve the original positioning of the component being copied. I have also tried using Save As in the source model to write the component “X” to a separate model file, then using Import in the destination model to load the saved “X” .SKP model into the destination. The same uniqueification renaming occurs as with Paste in Place.

I must admit I’m not quite following what you are doing, but, have tried saving the components as a local collection then drag them in from the component browser.

It’s the same problematic dynamic as with nested components in DC’s. Did you scale or mirrored some screws in the source or target file?

@Box Sorry to be confusing. I have created a hierarchical component in one model file. A fuel tank assembly (top-level component), consisting of two fuel tank hemispheres (sub-components), some screws (sub-components) and nuts (sub-components), some tubing (sub-components), etc. I want to place a copy of that fuel tank assembly into another model .SKP file, which already has some of the same screw and nut components. The instances of screws that are in the copied/pasted fuel tank assembly end up having new definitions created for them in the destination model, with the added “#1” definition-name suffix.

I confess to never having learned much about SketchUp’s concept of local component collections. I have simply been using SketchUp’s Save As (context-menu) function to store components into various folders (directories) that I manually created via the computer operating system.

@MikeWayzovski Yes some of the screws had been created as mirrored (Flip Along…) copies of others in the source model. I had done a Reset Scale on all of them, prior to copy/pasting the hierarchical component into the destination model. From doing some browsing in my model and some experiments just now, I do not see a correlation between (sub) components that had been flipped and whether they are assigned new unique definitions. In other words, some of the screw instances that I’m pretty sure were never flipped in the source model were assigned to the new “#1” unique definition when pasted into the destination model.

As an experiment, I just made a new hierarchical component in my source model which had two instances (sub-components) of a common screw, one of them flipped. I copy/pasted that hierarchical component into the destination model (which already had some instances of that same screw component), and neither of the pasted screws was assigned a new unique definition - they both are associated with the similar screw definition that was already in the destination model (which is great!).

So I haven’t figured out what conditions cause SketchUp to create new unique definitions for pasted components.

check this extension:

https://extensions.sketchup.com/extension/28691b5f-d472-4d26-a4d6-0a7c0b8068e0/kg-dev-select-by-id

A change and undo will alter the unique identifier, too. I think it is related.

If you paste or Import any component or sub component into a model with another component of the same name the newly pasted one will get a #1 suffix. SU doesn’t care if it is the same geometry or not, but won’t allow a new or pasted-in component to have the same name as an existing one in the model. It automatically adds a #1 suffix to the component name of the pasted-in one to make the name unique. It may use higher numbers if there’s an existing one of the same name and #1 suffix already.

You can use Outliner to search for instances of the #1 suffix, select identically named ones, then use Component Browser (make sure Expand is checked so you see sub- and sub-sub- components) to Select the original with no suffix, R-click, then Replace Selected.

To check you have replaced all of the #1 version, Purge unused, then check to see it has been removed from the Component Browser.

Repeat for any other #1 components.

Forgive me, but I do not think it is that clear-cut. Just now I selected and copied a component in one model (.SKP file) and pasted it into into another model that already had instances with the same definition name. The pasted instance did NOT get #1 appended to its definition name. I still do not know how SketchUp decides that pasted instances should be made unique from “similar” instances already in the destination model. It does not happen all the time (at least with 2018).

Yes, that’s what I am doing to clean up my model. It is a bit tedious when there are dozens of instances of “#1”-ized components scattered in a dozen or more hierarchical components. Each containing component must be done separately.

That’s interesting. It’s always done it for me, I think, but I’ll experiment tomorrow and check back late in the day (busy earlier). I should be asleep, but am feeling wakeful at almost 3 am!

I have v2018 on both Mac and windows 10, so I can try both, as well as SU 2021 on Mac only.

Scaling or ‘Reset Scale’ the instance has no impact on the definition, ‘Scale Definition’ however, seems to trigger something, which sounds logical, after all, you’re redefining.

And then there is context, to protect inserted components, for instance (pun!) you cannot use ‘Select Instances’ in the comp panel to select the nested components, you need to open the higher level for editing, first.
This protection is needed, because a component is just another model wether you create it inside the larger model or import or copy paste things from outside.

The new naming of Groups and Components to ‘Objects’ is just a cosmetic thing.
I would much rather see a new kind of entity in SketchUp’s universe ‘Assembly’ to deal with these.

That seems plausible. I don’t recall if I might have used Scale Definition in the components that were affected in my recent episode, but it is possible. I use that function very rarely. Thanks for the video.

Just done a few experiments in v2018 and v2021.

Both seem to behave the same.

I create two models, one cylinder component with the definition name Test and another model containing a cube component also with the definition name Test.

If copy and paste the cylinder component into the model with the cube, it is immediately named Test#1 as is shown both in Entity Infor for the component, and in the Component Browser.

If I copy the cube component from the cube model and paste it into the cylinder model, its definition is also immediately renamed Test#1.

If I copy the cylinder pasted into the original cube model (now named Test#1) and paste it back into the cylinder model, it keeps its original name of Test, which I find odd.

And if I now copy the cube called Test#1 from the cylinder model back into the cube model, it also reverts to its original name of Test, and there is still a cylinder component called Test#1.

In the cube model, I scale the pasted-in cylinder x2 along Z. Then copy/paste it back into the original cylinder model. It comes in as Test again.

But (quite reasonably) if I Scale Definition on the double height cylinder before copying and pasting it back into the original cylinder model, it comes in as Test#2. The geometry in the component has changed, so it can’t be the same component as the original any more.

The only part of this that surprises me is that the original component copied into another model, then pasted back into the original, keeps its original name.

Would that explain your experience with your Screw component, @TDahl?

I didn’t save either of the models during this process. That might make a difference…

{LATER]
But it doesn’t seem to.

I’m not sure, because I don’t know the full sequence of operations that I have done. Over the past few months I have been developing a new sub-system of my model. Recently I completed all ~300 unique components for the new sub-system, which also includes some instances of re-used components. I finally tried to paste this new sub-system into my overall model file the other day, and encountered the #1 definition-name issue.

I have seen the issue before (during the multi-year process of creating my overall model). This time, I decided to seek ideas for ways to avoid it, other than doing all model development in a single .SKP model file (which is not practical, because saving all 6M edges, 3M faces, ~1500 component definitions takes nearly a minute when validity-check is active).

I have similar issues when working with a collaborator. I export a model for him to update, and (mostly) add new components. When I re-import parts of his modified model that use the same components I exported, they usually come back in with a suffix #1. The only way I know to fix it is to replace them with the original, if it hasn’t in fact changed, as I described earlier.

Maybe someone else will have a better solution.

In principle, one could (I think - I’m no expert in Ruby) write a plugin to check for components that have exactly the same contents but different names. It would simplify the plugin if it only looked at cases where there are two or more components which differ only in that some have #n suffix and others don’t.

The SU Ruby API has a method for this:

The equals? method is used to determine if a component instance is geometrically equivalent to another instance.

Examples:

entities = Sketchup.active_model.entities
instance1 = entities[0]
instance2 = entities[1]
status = instance1.equals?(instance2)
Parameters:

instance (Sketchup::ComponentInstance) — The instance to compare this instance with.
Returns:

(Boolean)
Version:

SketchUp 8.0

Again, in principle, I imagine the plugin could iterate through all component instances in the model with a # and a number suffix in their definition name, and see if they are identical to one without the # but otherwise the same name. If it finds one or more, then it could Replace the # named one by the original without the #.

What I haven’t found in the API is the ruby command to replace one component by another - searching for a method ‘replace’ comes up with nothing, and ‘substitute’ does too.

I’m fairly sure it’s possible, but haven’t found out how.

1 Like