Component List Renaming

Is this something what you are looking for?
Copy-paste the code below to Ruby console and hit Enter (Return)
Type the string what you want to replace and for what…
the first occurrence of string will be replaced in all definition names in a model
(You can undo it)

See animation (Click on it if not animating)
NOTE: I don’t think it’s going to go wrong, but it’s best to try a “non-live” model or have a backup.



def replace_in_comp_defname
  mod = Sketchup.active_model
  defins = mod.definitions
  prompts = ["original string:", "new string:"]
  defaults = ["", ""]
  input = UI.inputbox(prompts, defaults, "Change component definition name ")
  return unless input
  old,new = input
  mod.start_operation("Change definition names", true)
  i = 0
  defins.each{|defin|
    next unless defin.name.include?(old)
    defin.name = defin.name.sub(old,new)
    i += 1
  }
  mod.commit_operation
  "#{i} changes"
end
replace_in_comp_defname
5 Likes

You are allowed to create one extension per day😀

1 Like

This is just a five-minute code snippet… :blush:

Yes, this looks like it might do the trick. Mike the SketchUp Sage already sent me the link. Coding is a little over my head. It’d be like learning Arabic or Klingon. I got a syntax error, after ‘copy and paste’ so obviously did something wrong. I’ll figure it out. Thank you Learned One.

How do I change this for renaming groups?

This is amazing!
I’m drawing up a library of elements in order to use Quantifier Pro.
However, sometimes I only need to change the name of some of the components with partly the same name.
For example, I have 100 components with name ‘AA_L_x_y_z’ with x/y/z being variables.
I want to change 50 of them to ‘AA_P_x_y_z’. If I were to use this method in the same model, all 100 of them would change. So I copy the 50 ones I want to rename to a blank model, change the name, and then copy them back in the master model. The problem here is that the name changes back to the original name.
Any remedy for this would be very welcome.

Thanks!

I guess it is because SU somehow keep the internal reference of definition of the components.
Perhaps you can cut (instead of copy) then purge the component definition out from your original file then you can insert the components with modified componetinstances with new definition names.

OR

I modified the code snippet.

If there is no selection will work as before.

If there is a selection and contains componentinstance(s) it will replace the string in definition names of selected componentinstance(s).

If the selection does not contains componentinstance(s), will do nothing.

def replace_in_selected_or_all_comp_defname
  mod = Sketchup.active_model
  sel = mod.selection
  if sel.empty?
    defins = mod.definitions
  else
    defins = sel.grep(Sketchup::ComponentInstance).map(&:definition).uniq
    return "No component selected" if defins == []
  end
  prompts = ["original string:", "new string:"]
  defaults = ["", ""]
  input = UI.inputbox(prompts, defaults, "Change component definition name ")
  return unless input
  old,new = input
  mod.start_operation("Change definition names", true)
  i = 0
  defins.each{|defin|
    next unless defin.name.include?(old)
    defin.name = defin.name.sub(old,new)
    i += 1
  }
  mod.commit_operation
  "#{i} changes"
end
replace_in_selected_or_all_comp_defname

As usual: No warranties. Use your own risk!

PB3 has this feature built in

Page 123

1 Like

Thanks guys! Will look into it later.

Hi guys,

I have some simillar problem I am trying to solve but it’s more focused on profile builder.
I have created some moldings with profile builder and I use the “generate as components” feature because I need to extract a cut list at the end with OCL.
My issue is that profile builder adds auto names for the generated components so the definition is something like “Group#”. It does add the profile name in the instance field but this does not help me. I am looking for a way to make profile builder create componenets using the profile name as the definition. Looking for a workaround is the reason I got to this thread, so this could be a workaround to have a script that can change the instance names.

Can you guys help me figure this out ?

Check this post:

I know about that one Mike, but it doesn’t change the definitian name, only the instance name.

(I just saw my double post in this thread)
How much do you rely on OCL?
PB3 works great with Quantifier Pro, FWIW.

Mike, I do ALL with OCL for woodworking, I still miss a couple of things (posibility of adding veneer similar to the edge banding beeing one of them) but it is the best tool so far.
I do have Quantifier Pro, bought it with PB3 as a bundle but for the life of me I can’t figure out how to use it, specifically in my workflow. I was planing to ask for help from Dale and his team.

If you are curios I can upload a model I’m working on and give you a quick tour of my workflow. maybe some of you guys can give me some improvement ideas.

That can help (adding a model) there are some simular things about the two extensions, but certain aspects just need another approach.

Hallway cabinet.skp (879.1 KB)
Nomenclator repere - Cuier in stil Philippe.pdf (96.6 KB)
Cuier - Hallway cabinet 04.02.2022.pdf (334.0 KB)

So what you have there is the model, and then I added the 2 pdfs that we print for production, the printed versions will be distributed in the factory in the specific area, solid wood sheet to the team that prepares the wood pieces, panels sheet to the panel cutting area and the subasembly sheet to the assembly team.

The thing I lose time with (not taking in to account layout in the past, the 2022 version is, so far, brilliantly smooth and fast) is making the bill of materials the way we need it, I have to export multiple csv files that I then import back in google sheet and then I have to make a lot of manual adjustments. Thats why I need some extra functionality in Open Cut List, hopfully the guys will make time for this in the future.

Ok, some parts are actually profiles, but some are more sheetgoods with a routed profile. I guess you don’t create them with Profile builder.

Quantifier is good in reporting lengths and volumes (By Profile Members, Layers or Materials and Object) but doesn’t have a Cutting diagram possibility like OCL.

Renaming would be the quickest.
I found this post:

So, create the Solid Woods with PB3, batch rename the instances and then run the extension.

If you create a plain textfile, copy paste the code and save with the extension ‘.rb’, you can save it in the %AppData%/SketchUp/SketchUp[ 2021/SketchUp/Plugins location

Mike, I don’t need and use the cutting diagram, if you take a look at the first pdf with the list of parts (the BOM) that is the reason I use OCL, you think I can do that with Quantifier Pro?
I tried a couple of times but didn’t get it, I don’t know how to use it yet.

The fastest way is to create a component report, but first edit the settings of the report
Schermafbeelding 2022-02-07 om 09.15.22
QPRO
You can save different reports for different use cases, best to start a new and uncheck all, then select the ones you want, only and adjust some settings (precision etc.)

You can also attach cost data to specific objects:

object

Or attach cost data to Tags, it will use the volume or surface area to calculate costs.
You can than run summary cost reports, Detailed cost reports or switch back to the original component report:

TAG

You can create a Profile Members report, also, but my guess is that you find the Component report more usefull.

Holly … Mike!
I need to play around some more with quantifier pro. This seams I can do everything I need.

Thanks a lot Mike.

1 Like