Component name mismatching during component save

In the Ruby API we can write entries to menus, context-menus and tool’s toolbars - unfortunately there’s no access to the Components dialog itself…

The context menu sounds good.

Here’s a simple script that does what you want.
Put the RB file into your Plugins folder and restart SketchUp…
It is not an extension and it’s not signed…

Usage: There are 2 tools…

a. Select one instance of a definition in your model to see the entry, then get…
Context-menu > Save_As… Definition ‘Xxxx.skp’ [where Xxxx is the name of the selected instance’s definition]

b. File menu || Context-menu > Save All Definitions into a Collection…
There is a file-counter displayed in the directory-selector header and the status-bar.

The directory-selector always defaults to the user’s Components folder, as set in Preferences…

TIG-DefnSaver.rb (3.4 KB)

5 Likes

It works great. Thanks a lot for the help!

Prove

perhaps a few adjustments needed for saving unused components? :slight_smile:

For this guy, please https://forums.sketchup.com/t/identifying-unused-components/136182

1 Like

Perhaps you could purge unused definitions first, then save-to-collection, then do an undo to undo purge if you want to keep the unused ones ?
The saving-out does nothing to the model itself…

No, I don’t have that problem. I’m happy with the algorithm I’m using because it fully meets my needs.

Thanks, Mike, for linking me to this thread. As I’m just now learning how to save collections, I’m having all sorts of problems including over half the components not saving, and seeing name changes. Following…

Interesting conversation and thanks for the plugin TIG. This is exactly what I thought was a bug and reported in the early engagement site.

2 Likes

@LEGOsketcher I read your correspondence with @MikeTadros from the SketchUp Team.

I still consider this to be a bug, especially created by the developers. As an ordinary user, I do not need to know the nuances of programming or database architecture, that is not my business, but be able to get a logical and predictable result with the tools given to me. However, in this situation, the developers may have solved some of their own problems, but created unwanted problems for me as a user. This is not good practice.

I have worked with various databases and my experience in this case says:
if the definition names of different components within a single file cannot be non-unique, then they are sufficient component uniqueness identifiers. Why create another parallel system that is not accessible and usable by users, especially if it allows for duplication of identifiers and generates situations where information is lost (overwritten files)?

1 Like

Hi All, I know this topic has been going for a while but here is a summary as I understand it:

When you create a New component using the ‘Make Unique’ command on a component that has a ‘Loaded From’ address (found in Edit tab in Components window) these problems start -

  1. It retains the Old ‘Loaded From’ address (not helpful!)

  2. If you then right click on this new component and ‘Save As’ the Old name shown is often displayed in the ‘Save As window’, so you have to correct this manually.

  3. Some times when you import this component into another document it comes in with its OLD name. Not very useful; where is this OLD name located? (see below)

As a work-around, after I create a new Component using ‘Make Unique’ method; I make changes as required, then ‘Save As’, giving it the correct name I gave it after ‘Make Unique’ was used. This corrects the ‘Loaded From’ address.

Stopping it from being imported with its OLD name was the next problem! The Old name must be stored somewhere? I found it in the Model Info / File window, under ‘Name’! All I do is DELETE this name and don’t replace it! It then imports with its correct file name.

So a couple of Big question arise from this:

1 - Why is the ‘Loaded From’ address retained when you create a new component via ‘Make Unique’ command? This should have been removed when you ‘Make Unique’ it’s now a Internal Component.
2 - what is the ‘Name’ entry in Model Info / File used for? You you can delete it as I have done because its incorrect or when it’s correct (I tried that as well!) with no adverse affects on the file.
3 - Why is the components old/original name not replaced with the new name in the Model Info / File window?

Cheers
perplexed

1 Like

Yes, it is part of this global issue. Quite often you also have to change the name of the component in the work process. The consequences are the same as creating a unique component. But the most incomprehensible is that it doesn’t always happen, but only SOMETIMES! When working on a large project, there is no time to pay special attention to possible mismatch of component names in the later storage process. Here, two levels of the program are mixed together: one that I don’t need to know as a user because I don’t use it at all (but is probably necessary for some program activities that I’m not interested in as a user), and the other that should be logical for users.

BB

For example, this model contains 4502 instances of 623 unique components. During its development, I had to think not only about its construction, but also about the choice of materials, the order in which it will be built and disassemble on the stage with a minimum of staff in a short time, in what parts it needs to be divided so that it can be safely loaded into a sea container and elevators with limited dimensions, how to move it within NYC with smaller trucks and many other conditions, rather than wasting time “tricky” renaming components in a model.

@TIG
Unfortunately, the second part of the script (Save All Definitions into a Collection…) does not always work. I have noticed that this happens in large projects with many nested components. Is it possible that the script is limited by the number of components or the depth of nesting?

Could you explain what happens…
Run it with the Ruby Console open - any errors…

If you get a list of definition names how does that compare with the exported subfolder’s list ?
Use this in the Ruby Console to see what the list should be…

defns=Sketchup.active_model.definitions.each{|defn|
  next if defn.image? || defn.group?
  puts defn.name.gsub(/[\x00\/\\:\*\?\"<>\|#,]/, "_")
}

Nothing. From both File and context menus.

I got the correct list of 121 components. If I use the native Save as a local collection…, I lost 4 components and many others have incorrect names.

Do the definition names given by my snippet in the RC match those in the exported subfolder ?
By ‘incorrect names’ what do you mean e.g. XXX#1 becomes XXX_1, because # is best avoided in SKP file names…
What are the names of the ‘lost’ ones ?
At the moment if you have a definition named XXX#1 and another named XXX_1 they’ll both become XXX_ due to the ‘safe-naming’ tool…
As much info as you can give will help fix theis…
However I can sidestep that…
I’ll look into publishing an update shortly…

TIG-DefnSaver.rb (3.7 KB)
This v1.1 checks for existing SKPs in a collection subfolder and increments the end of the name to avoid overwriting…
So if you have definitions named XXX#1 and XXX_1 previously they’d both get SKPs named XXX_1.skp and so the later one would overwrite the older one, with v1.1 if XXX#1 is saved as XXX_1.skp now when it’s the turn of XXX_1 it’s renamed XXX_2.skp to avoid the overwriting issue…
This clash of exported names can be avoided by using definitions naming so that if the SKP’s name is ‘fixed’, e.g. to replace a : or # with _ - then duplicated SKPs are never produced when making a collection…

1 Like

Thanks, @Tig, sorry for the late reply! Your plugin was fine with component names. I think the problem is probably with the file itself, because files with a simpler structure don’t have a problem saving all components with their definition names, but the latest version of the plugin doesn’t work for that file either.

I wrote about the shortcomings of the native command at the beginning of this topic. This is exactly what happens when I use it: components disappear (apparently overwritten), some components are given old names.

Sorry - I’ve rewritten the RB because you found it contained a typo, here it is again: TIG-DefnSaver.rb (3.7 KB)
v1.2

As I explained in our recent PM, it works fine for me with your example SKP, despite it being full of definitions with accented characters in their names ! There’s no need for my code to ‘fix’ any naming at all, and the definition-name matches the exported SKP-name perfectly…

So back to your issue ??
Are you saving to an empty new subfolder so there’s no ‘duplication’ ?
Are you saving locally - rather than to a network drive or drop-box etc ??