sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    [Plugin] Global_Material_Change

    Scheduled Pinned Locked Moved Plugins
    19 Posts 16 Posters 14.6k Views 16 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • TIGT Online
      TIG Moderator
      last edited by

      This script [Global_Material_Change.rb] works on everything in a selection [or if there is no selection it uses all active entities]...

      You can choose any material that's loaded in the model to be replaced - you can also choose <Default>, or << ALL >> - 'ALL' will change all materials in the selection to the new one - that's useful if you want to remove all materials from something and go for say the <Default> material to replace it... You can likewise choose any 'new' material from those currently available. You are warned about processing 'ALL' materials and also 'ALL' active entities...

      The end result is everything in the selection (or active_entities) that uses the chosen material is globally changed to the chosen new one. I works on entities, groups or component definitions - mining down into them to change any nested things too...

      It's one step undoable...
      PayPalButton


      Global_Material_Change.rb

      TIG

      1 Reply Last reply Reply Quote 0
      • M Offline
        mateo soletic
        last edited by

        Tig
        Thanks a lot, I just tried it , Great script. 👍

        [Concept Illustrations](http://concept-illustrations.com/)

        1 Reply Last reply Reply Quote 0
        • M Offline
          Matt666
          last edited by

          Hi Tig !
          Excellent Plug-in !!
          I have translated it in French language...

          I tried to create similar script... It works differently, and I have some problems...
          1- Select a face with the old texture
          2- Choose the new texture in the 'paint' palette
          3- Apply "Add to the model" in the right click context menu in the palette
          4- Run the script.

          The third stage is a problem. I can't add the texture directly with the code... And if you don't do that, the texture is not saved. Do you have any method ??

          #Replace texture definition of a face with the active texture in the palette
          
          def process_textures(entities, anctxt, newtxt)
          	entities.each do |entity| 
          		case entity.typename
          		when 'Group'
          			process_textures entity.entities, anctxt, newtxt
          		when 'ComponentInstance'
          			if entity.material == anctxt
          					entity.material = newtxt
          			end
          			edef = entity.definition
          			process_textures edef.entities, anctxt, newtxt
          		when 'Face'
          			if entity.material == anctxt
          					entity.material = newtxt
          			end
          			if entity.back_material == anctxt
          					entity.back_material = newtxt
          			end
          		end
          	end
          end
          
          def reptxt
          	model = Sketchup.active_model
          	ss = model.selection
          	model.start_operation "Remplacer textures"
          	if model.materials.current !=nil
          		active_material = model.materials.current.name
          		puts "Texture active = " + active_material
          		if ss.empty?
          			UI.messagebox("Aucune selection.")
          			return nil
          		else
          			ent = ss[0]
          			if ent.typename == "Face"
          				puts "\nL'entité sélectionnée est de type Face."
          				if ent.material !=nil
          					process_textures model.active_entities, ent.material, active_material
          					model.commit_operation
          				end
          			else
          				UI.messagebox("\nL'entité sélectionnée n'est pas de type Face (" + ss[0].typename + ").")
          			end
          		end
          	else
          		UI.messagebox("Aucune texture active.")
          		return nil
          	end
          end
          
          if not file_loaded?("reptxt.rb")
          	UI.menu("Plugins").add_item("Replace texture definition"){reptxt}
          end
          

          Thank you !


          fr_Global_Material_Change.rb

          Frenglish at its best !
          My scripts

          1 Reply Last reply Reply Quote 0
          • PixeroP Offline
            Pixero
            last edited by

            Thanks, I know I'll have great use of it.

            1 Reply Last reply Reply Quote 0
            • TIGT Online
              TIG Moderator
              last edited by

              Here's v1.1...

              Usage:

              1. Select entities.
                [IF there's no selection ALL active entities are used]
              2. Activate the script from the Plugins Menu.
              3. Choose Old Material [to be replaced].
                [<< DEFAULT >>=NO Material, << ALL >>=ALL Materials &
                then Alphabetical list]
              4. Choose the desired New Material.
                [<< DEFAULT >> = No Material]
                To access Materials that are off the visible list type the first letter - e.g. 'W' and use up/down arrow-keys to move to the one you want e.g. 'W'hite...

              History:
              1.0 20080522 First issue.
              1.1 20080523 Lists alphabetical & guidance on arrows.
              Progress 'ticker' added...

              .


              Global_Material_Change.rb

              TIG

              1 Reply Last reply Reply Quote 0
              • CadFatherC Offline
                CadFather
                last edited by

                Thank you TIG - i'll give it a try - it's a plug in i've been thinking about for some time.. 😛

                1 Reply Last reply Reply Quote 0
                • J Offline
                  Julius
                  last edited by

                  really useful!

                  1 Reply Last reply Reply Quote 0
                  • JClementsJ Offline
                    JClements
                    last edited by

                    So far, so good. I can see it being a big time saver.

                    Thanks, John

                    John | Illustrator | Beaverton, Oregon

                    1 Reply Last reply Reply Quote 0
                    • boofredlayB Offline
                      boofredlay
                      last edited by

                      Very useful, thanks.

                      http://www.coroflot.com/boofredlay

                      1 Reply Last reply Reply Quote 0
                      • plot-parisP Offline
                        plot-paris
                        last edited by

                        may be I am stupid. but I cant find the ruby (I pasted it in the SketchUp Plugin folder. but it doesn't show up in the plugins window (neither does it in any context menu or the paint bucket window)...

                        is there something I dont know?

                        1 Reply Last reply Reply Quote 0
                        • boofredlayB Offline
                          boofredlay
                          last edited by

                          Here it is on my screen.


                          GMC.jpg

                          http://www.coroflot.com/boofredlay

                          1 Reply Last reply Reply Quote 0
                          • plot-parisP Offline
                            plot-paris
                            last edited by

                            thanks Boofredlay,

                            I deleted it, copied it in the pluginsfolder again and it worked... no idea what happend.

                            now it shows up in the plugins tool bar and is doing a great job! 😍

                            1 Reply Last reply Reply Quote 0
                            • P Offline
                              perk
                              last edited by

                              Thanks Tig

                              Huge time saver!!

                              1 Reply Last reply Reply Quote 0
                              • D Offline
                                Dan
                                last edited by

                                My thanks too, Tig!
                                Very useful script.

                                1 Reply Last reply Reply Quote 0
                                • M Offline
                                  Morpeth
                                  last edited by

                                  very useful.. ☀

                                  1 Reply Last reply Reply Quote 0
                                  • S Offline
                                    sepo
                                    last edited by

                                    Thanks.. It works like charm.

                                    1 Reply Last reply Reply Quote 0
                                    • B Offline
                                      bassie
                                      last edited by

                                      Just what I needed. Thanks!!

                                      1 Reply Last reply Reply Quote 0
                                      • X Offline
                                        xrok1
                                        last edited by

                                        bravo!!

                                        “There are three classes of people: those who see. Those who see when they are shown. Those who do not see.”

                                        http://www.Twilightrender.com try it!

                                        1 Reply Last reply Reply Quote 0
                                        • F Offline
                                          fewltu
                                          last edited by

                                          Thank you so much!!! This is a huge help to me for setting up renderings for export. One huge improvement I would suggest is the ability to select multiple "old" materials to be replaced with one "new" material all at once. Thanks again!

                                          1 Reply Last reply Reply Quote 0
                                          • 1 / 1
                                          • First post
                                            Last post
                                          Buy SketchPlus
                                          Buy SUbD
                                          Buy WrapR
                                          Buy eBook
                                          Buy Modelur
                                          Buy Vertex Tools
                                          Buy SketchCuisine
                                          Buy FormFonts

                                          Advertisement