Replace Several Textures?
-
**Hello,
To replace several definitions with the "next name" definition, I tried this:
def handles @mod = Sketchup.active_model @ent = @mod.active_entities @last3 ||= '1' @next = @last3.next @next = '1' if @next == '4' last3_name = ['1-HANDLE','2-HANDLE','3-HANDLE'] next_name = "#{@next}-HANDLE" if @mod.definitions[last3_name] && @mod.definitions[last3_name].instances[0] cd = @mod.definitions[next_name] unless cd cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/# {next_name}.skp") cd = @mod.definitions.load cmp end @mod.definitions.find{|d|d.name==last3_name}.instances.each{|ci|ci.definition=cd} @last3 = @next else UI.messagebox "#{last3_name} not found." end end
But the code does not work for a list of definitions between these brackets "[]".
How to replace a list of definitions with the definition "next name" ?
Any help would be of great help to me.
Cordially
David**
-
**There is news
As my code is in a class, I tried to apply the advises of TIG, put in "@@".
Now "@@ next" continues to evolve from 1 to 19, even if the definition that needs to be replaced is not found.
Even if the situation is better than before, it is not perfect because the code restarts to
"1-Handle" every time SketchUp runs.If the handles on the stage are defined "5-Handle", you have to click 4 times on the icon to change the handle.
Thank you in advance for your help.**
def Handle @@mod = Sketchup.active_model @@ent = @@mod.active_entities @@avant ||= '1' @@next = @@avant.next @@next = '1' if @@next == '19' @@last1 = "#{@@avant}-HANDLE" @@next_name = "#{@@next}-HANDLE" if @@mod.definitions[@@last1] @@cd = @@mod.definitions[@@next_name] unless @@cd cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/# {@@next_name}.skp") @@cd = @@mod.definitions.load cmp end @@mod.definitions.find{|d|d.name==@@last1}.instances.each{|ci|ci.definition=@@cd} @@avant = @@next else UI.messagebox "#{@@last1} not found." end end
-
-
**Great Thanks sdmitch.
The general change of all the Handles furniture is finally perfect.
I will do the same for all the components of a kitchen, sink, taps, oven etc ...
Thanks to your help, "Click-Cuisine 2" will be even easier than ever.
A small remark without great consequence:
The current code does not replace the unique handles, such as "1-HANDLE # 1".
Is it possible to circumvent the problem, if so how?
The 2nd Great Steps is to replace the Handles of a single piece of furniture selected, without affecting other furniture.
How would you do that?
Any help from you is very good news to me.
Thank you
David**
-
@tntdavid said:
The current code does not replace the unique handles, such as "1-HANDLE # 1".
Is it possible to circumvent the problem, if so how?
@@mod.definitions.find{|cd|cd.name=~/#{@@last1}?/i}.instances.each{|ci|ci.definition=@@cd}
The 2nd Great Steps is to replace the Handles of a single piece of furniture selected, without affecting other furniture.
How would you do that?
This would be difficult indeed. The easiest way would be to move the single piece to a new model, make the changes then import it back.David
-
**Thanks for your Sdmitch solution, but the definitions rendered unique "1-HANDLE # 1" still do not change.
Maybe I made a mistake somewhere?
def poignee @@mod = Sketchup.active_model @@ent = @@mod.active_entities @@avant = Sketchup.active_model.get_attribute("Handles","Last","1") @@next = @@avant.next @@next = '1' if @@next == '19' @@last1 = "#{@@avant}-POIGNEE" @@next_name = "#{@@next}-POIGNEE" if @@mod.definitions[@@last1] @@cd = @@mod.definitions[@@next_name] unless @@cd cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/# {@@next_name}.skp") @@cd = @@mod.definitions.load cmp end @@mod.definitions.find{|cd|cd.name=~/#{@@last1}?/i}.instances.each{|ci|ci.definition=@@cd} @@avant = @@next Sketchup.active_model.set_attribute("Handles","Last",@@next) else UI.messagebox "#{@@last1} not found." end end
Perhaps it is more interesting not to reload the rendered unique models to find a solution to my 2nd Objective?
Here is a simpler idea for the 2nd Objective:
1 - I select a piece of furniture.
2 - I Click on the icon "Freeze the model". (The method that is executed makes all unique components and subcomponents of my selection.)
3 - I can execute the first code without changing the handles of the furniture made unique.
How to write this method?
Thanks in advance for your help.**
-
@tntdavid said:
[size=110]Thanks for your Sdmitch solution, but the definitions rendered unique "1-HANDLE # 1" still do not change.
Maybe I made a mistake somewhere?
def poignee > @@mod = Sketchup.active_model > @@ent = @@mod.active_entities > @@avant = Sketchup.active_model.get_attribute("Handles","Last","1") > @@next = @@avant.next > @@next = '1' if @@next == '19' > > @@last1 = "#{@@avant}-POIGNEE" > @@next_name = "#{@@next}-POIGNEE" > > if @@mod.definitions[@@last1] > @@cd = @@mod.definitions[@@next_name] > unless @@cd > cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/# > {@@next_name}.skp") > @@cd = @@mod.definitions.load cmp > end > @@mod.definitions.find{|cd|cd.name=~/#{@@last1}?/i}.instances.each{|ci|ci.definition=@@cd} > @@avant = @@next > Sketchup.active_model.set_attribute("Handles","Last",@@next) > else > UI.messagebox "#{@@last1} not found." > end > end
I think you need to use the same @@mod.definitions.find when checking for existence also.
if @@mod.definitions.find{|d|d.name=~/#{@@last1}?/} @@cd = @@mod.definitions.find{|d|d.name=~/#{@@next_name}?/} unless @@cd cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/#{@@next_name}.skp") @@cd = @@mod.definitions.load cmp end @@mod.definitions.find{|cd|cd.name=~/#{@@last1}?/i}.instances.each{|ci|ci.definition=@@cd} @@avant = @@next Sketchup.active_model.set_attribute("Handles","Last",@@next) else UI.messagebox "#{@@last1} not found." end
-
@tntdavid said:
Here is a simpler idea for the 2nd Objective:
1 - I select a piece of furniture.
2 - I Click on the icon "Freeze the model". (The method that is executed makes all unique components and subcomponents of my selection.)
3 - I can execute the first code without changing the handles of the furniture made unique.
How to write this method?
Thanks in advance for your help.[/size]
Could you post or PM me a sample model,version<=2016, that I could test.
-
@sdmitch said:
I think you need to use the same @@mod.definitions.find when checking for existence also.
**It does not work yet.
For the code that makes it unique all of it is found.
Here is the example of the updated cube:
TNT_Teste.rbz
**1.**Open the SKP file Teste 2.
2. Install the extension.
**3.**Click on the color icon. (All cubes will change texture.)
**4.**Click the cube icon. (This will reload the subcomponents.)
5. Select the middle cube and click on the padlock.
6. Click the cube icon again, you will see that the sub-components of the middle cube will no longer change.
7. Click on the color icon, the texture of the middle cube no longer changes. (Unfortunately this is not yet the case and I need your help to write this method.)
Thank you
David**
-
@tntdavid said:
6. Click the cube icon again, you will see that the sub-components of the middle cube will no longer change.
7. Click on the color icon, the texture of the middle cube no longer changes. (Unfortunately this is not yet the case and I need your help to write this method.)
-
I'm not sure why this works at all since we changed to pattern matching of the name to over come the problem with names containing '#'!
-
This is never going to work because there is only a single 'color' involved and making a component unique has no effect on the material applied.
I'll keep thinking about it but I'm not optimistic about finding a solution.
-
-
I have PM'd you a possible solution to #7
Advertisement