by dedmin » Sat Nov 14, 2009 10:36 am
Is there a way to attach a same string to the names of different components?
-
dedmin
-
- Posts: 926
- Joined: Thu Oct 02, 2008 10:40 pm
by TIG » Sat Nov 14, 2009 12:01 pm
- Code: Select all
Sketchup.active_model.definitions.each{|d| d.name="MyPrefix-"+d.name+"-MySuffix" }
Adds a prefix AND a suffix to ALL component definition names ! If you want to match a particular kind of name then use a regexp... - Code: Select all
...d.name=d.name+"-MyDoorSuffix" if d.name=~/Door/...
would only add '-MyDoorSuffix' onto the ends of any Component names that include the text 'Door' somewhere inside it...
TIG
-

TIG
- Global Moderator
-
- Posts: 20272
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by dedmin » Sat Nov 14, 2009 1:42 pm
Thanks, Master TIG How about applying this on a selection of components? What I'm trying is to add a banding information to the names of the components as a suffix. If I have a components that share the same banding, to first select them and attach that suffix at once.
-
dedmin
-
- Posts: 926
- Joined: Thu Oct 02, 2008 10:40 pm
by TIG » Sat Nov 14, 2009 4:05 pm
- Code: Select all
defs=[] Sketchup.active_model.selection.each{|e| defs<<e.definition if e.class==Sketchup::ComponentInstance } defs.uniq! defs.each{|d|d.name=d.name+"-SUFFIX"}
This processes the definitions - I'm assuming that you want to rename the component-definition NOT the component-instance which can also have a separate name... It's easy to adjust the code if instances are to be renamed... like this... - Code: Select all
insts=[] Sketchup.active_model.selection.each{|e| insts<<e if e.class==Sketchup::ComponentInstance } insts.each{|i|i.name=i.name+"-SUFFIX"} ### NOTE: the component-definition's name is NOT changed by this...
TIG
-

TIG
- Global Moderator
-
- Posts: 20272
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by dedmin » Sat Nov 14, 2009 4:39 pm
Thanks!! Yes, I want to change component-definition.  I saved the ruby as a banding.rb in the Plugins folder, selected the components and run the script in the ruby console. Never been messed with this before - maybe I'm doing something wrong here? - Code: Select all
banding Error: #<NameError: (eval):42: undefined local variable or method `banding' for main:Object> (eval):42
-
dedmin
-
- Posts: 926
- Joined: Thu Oct 02, 2008 10:40 pm
by TIG » Sat Nov 14, 2009 6:15 pm
Without seeing your code I don't know what's up - what have you pasted into the file - I only showed snippets which need some 'structure' ! You have to have - Code: Select all
def banding() ### The code... end#def
To run it by typing 'banding'... It'd be relatively easy to sort - please paste you code inside a [ code ][ /code ] set...
TIG
-

TIG
- Global Moderator
-
- Posts: 20272
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by dedmin » Sun Nov 15, 2009 11:37 am
I see. I thought it's a finished script ready to run. Never touched any scripting before. Thanks - will do it by hand.
-
dedmin
-
- Posts: 926
- Joined: Thu Oct 02, 2008 10:40 pm
by TIG » Sun Nov 15, 2009 12:50 pm
Copy/paste this into a banding.rb file, then typing banding "-suffix" in the console should work on selected components... - Code: Select all
def banding(suffix="") suffix=suffix.to_s model=Sketchup.active_model model.start_operation("banding "+suffix) ss=model.selection defs=[] ss.each{|e| if e.class==Sketchup::ComponentInstance defs<<e.definition if not defs.include?(e.definition) end#if } defnames=[] defs.each{|d| d.name=d.name+suffix defnames<<d.name } puts "Processed "+defs.length.to_s+" Component Definitions" defnames.each{|n|puts n} puts "" model.commit_operation end#def
PS: I've attached the .rb too... banding.rb
TIG
-

TIG
- Global Moderator
-
- Posts: 20272
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by dedmin » Sun Nov 15, 2009 1:01 pm
-
dedmin
-
- Posts: 926
- Joined: Thu Oct 02, 2008 10:40 pm
by dedmin » Sun Nov 15, 2009 1:38 pm
It works great, but there is a problem. If I make a cabinet component with all the banding info for the parts set and then stretch with FredoScale to get new dimensions the components get renamed - Code: Select all
drawer_left;0W-1L#1
- they become new components. Since i'm using the names as a way to export banding info into the CutList Plus using ";" as a delimiter i have to rename again. But if i put this info as a prefix then everything will be fine and no need to rename again. Can You please make this script do the same but as a prefix? Sorry, if i sound too insolent 
-
dedmin
-
- Posts: 926
- Joined: Thu Oct 02, 2008 10:40 pm
by TIG » Sun Nov 15, 2009 2:01 pm
Here's an update: banding.rb ### Usage: ### banding "prefix-" [or banding "prefix-","" or banding "prefix-",nil] adds a prefix ### banding "","-suffix" [or banding nil,"-suffix"] adds a suffix ### banding "prefix-","-suffix" adds a suffix and a prefix
Last edited by TIG on Sun Nov 15, 2009 3:56 pm, edited 1 time in total.
TIG
-

TIG
- Global Moderator
-
- Posts: 20272
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
dedmin
-
- Posts: 926
- Joined: Thu Oct 02, 2008 10:40 pm
by DavorP » Tue Apr 14, 2015 5:24 am
Is there a plugin that would export list of component names, definitions and perhaps other details to .csv file And the more tricky part - to import back the new filenames after you are done with editing?
Or a plugin that would list all components with details in an editable spreadsheet within SU?
-
DavorP
-
- Posts: 15
- Joined: Wed Jan 18, 2012 12:51 pm
- Name: DavorP
by Dan Rathbun » Tue Apr 14, 2015 3:20 pm
What "other details" ?
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5042
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by jeynay » Fri Nov 30, 2018 10:34 pm
Hi, Is there a way to remove certain words from multiple components at the same time? for example I have 50 components that their name has "3D - johnsmith_google_com level 1" at the end of the name. like: "10016001_S_DLGBldg1_Central_detached_rvt-1-3D - 3D - johnsmith_google_com level 1" "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1" "Aluminum Sill Extension - Aluminum Sill Extension-2131210-3D - johnsmith_google_com level 1" Is there a script that can remove a certain prefix or suffix? or just removing the first/last 15 or 10 characters in the name would also work. This issue is very annoying since the models imported from revit to sektchup end up having more than 100 characters. Thanks
-
jeynay
-
- Posts: 3
- Joined: Wed Aug 29, 2018 12:10 am
- Name: jeynay
- Operating system: Windows
- SketchUp version: 2018
- License type: Free/Make
- SketchUp use: architecture
- Level of SketchUp: Intermediate
by TIG » Sat Dec 01, 2018 6:50 pm
jeynay wrote:Hi, Is there a way to remove certain words from multiple components at the same time? for example I have 50 components that their name has "3D - johnsmith_google_com level 1" at the end of the name. like: "10016001_S_DLGBldg1_Central_detached_rvt-1-3D - 3D - johnsmith_google_com level 1" "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1" "Aluminum Sill Extension - Aluminum Sill Extension-2131210-3D - johnsmith_google_com level 1" Is there a script that can remove a certain prefix or suffix? or just removing the first/last 15 or 10 characters in the name would also work. This issue is very annoying since the models imported from revit to sektchup end up having more than 100 characters. Thanks
You can batch rename components. I assume you mean component-definitions, rather than component-instances which can have individual names based on a shared definition... Here's a simple one-liner to do it... Edit the initial togo="..."; to suit your needs... - Code: Select all
togo=" - 3D - johnsmith_google_com level 1";m=Sketchup.active_model;m.start_operation('rename defns',true);c=0;m.definitions.each{|d|(d.name=d.name.gsub(/#{togo}/,'');c+=1) if d.name=~/#{togo}/};puts"#{c} definitions renamed.";m.commit_operation;
Paste it into the Ruby Console + <enter>, it's one step undoable...
TIG
-

TIG
- Global Moderator
-
- Posts: 20272
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by jeynay » Mon Dec 03, 2018 9:25 pm
Thanks for the quick reply TIG.I'm assuming this would rename that portion of component's name as well? for exampe if i have 50 instances like "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1-01" "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1-02" so on so forth, would i be able to remove the" 3D - johnsmith_google_com level" portion of those instance names? Thanks in advance TIG wrote:jeynay wrote:Hi, Is there a way to remove certain words from multiple components at the same time? for example I have 50 components that their name has "3D - johnsmith_google_com level 1" at the end of the name. like: "10016001_S_DLGBldg1_Central_detached_rvt-1-3D - 3D - johnsmith_google_com level 1" "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1" "Aluminum Sill Extension - Aluminum Sill Extension-2131210-3D - johnsmith_google_com level 1" Is there a script that can remove a certain prefix or suffix? or just removing the first/last 15 or 10 characters in the name would also work. This issue is very annoying since the models imported from revit to sektchup end up having more than 100 characters. Thanks
You can batch rename components. I assume you mean component-definitions, rather than component-instances which can have individual names based on a shared definition... Here's a simple one-liner to do it... Edit the initial togo="..."; to suit your needs... - Code: Select all
togo=" - 3D - johnsmith_google_com level 1";m=Sketchup.active_model;m.start_operation('rename defns',true);c=0;m.definitions.each{|d|(d.name=d.name.gsub(/#{togo}/,'');c+=1) if d.name=~/#{togo}/};puts"#{c} definitions renamed.";m.commit_operation;
Paste it into the Ruby Console + <enter>, it's one step undoable...
-
jeynay
-
- Posts: 3
- Joined: Wed Aug 29, 2018 12:10 am
- Name: jeynay
- Operating system: Windows
- SketchUp version: 2018
- License type: Free/Make
- SketchUp use: architecture
- Level of SketchUp: Intermediate
by TIG » Tue Dec 04, 2018 1:34 pm
The initial part of the code snippet togo=" - 3D - johnsmith_google_com level 1"; specifies which string will be deleted in the components' names. I you example: "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1-01" "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1-02" etc become "4_ Light Fixture - 4_ Light Fixture-1847101-01" "4_ Light Fixture - 4_ Light Fixture-1847101-02" etc
Just edit that to cover what you want to delete... So to leave the final 'ref' as say "1-01", you simply change the togo to say: togo=" - 3D - johnsmith_google_com level"; and the renaming is then: "4_ Light Fixture - 4_ Light Fixture-1847101 1-01" "4_ Light Fixture - 4_ Light Fixture-1847101 1-02" etc
You choose what's to be deleted... You can always run the code a second time with a new togo string, e.g. togo="4_ Light Fixture - "; Would strip off the duplicated starting reference, leaving: "4_ Light Fixture-1847101 1-01" "4_ Light Fixture-1847101 1-02" etc
TIG
-

TIG
- Global Moderator
-
- Posts: 20272
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by jeynay » Thu Jan 03, 2019 8:56 pm
TIG wrote:The initial part of the code snippet togo=" - 3D - johnsmith_google_com level 1"; specifies which string will be deleted in the components' names. I you example: "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1-01" "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1-02" etc become "4_ Light Fixture - 4_ Light Fixture-1847101-01" "4_ Light Fixture - 4_ Light Fixture-1847101-02" etc
Just edit that to cover what you want to delete... So to leave the final 'ref' as say "1-01", you simply change the togo to say: togo=" - 3D - johnsmith_google_com level"; and the renaming is then: "4_ Light Fixture - 4_ Light Fixture-1847101 1-01" "4_ Light Fixture - 4_ Light Fixture-1847101 1-02" etc
You choose what's to be deleted... You can always run the code a second time with a new togo string, e.g. togo="4_ Light Fixture - "; Would strip off the duplicated starting reference, leaving: "4_ Light Fixture-1847101 1-01" "4_ Light Fixture-1847101 1-02" etc
This worked beautifully!!! thank you much appreciated 
-
jeynay
-
- Posts: 3
- Joined: Wed Aug 29, 2018 12:10 am
- Name: jeynay
- Operating system: Windows
- SketchUp version: 2018
- License type: Free/Make
- SketchUp use: architecture
- Level of SketchUp: Intermediate
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|