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

    [WIP] CleverClay - Need help

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 269 Views 2 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.
    • PixeroP Offline
      Pixero
      last edited by

      I'm writing a script to change all materials to gray but leave transparency if any.
      It works on non grouped geometry.
      How to make it work on Grouped geometry as well?

      # CleverClay.rb
      # Version; 1.0
      # Turns all materials Gray but keeps transparency if any
      # Jan Sandström www.pixero.com
      # Based on Thomthoms "Blackout"
      
      require 'sketchup.rb'
      
      #-----------------------------------------------------------------------
      is_this_file=File.basename(__FILE__)
      if not file_loaded?(is_this_file)
        UI.menu("Plugins").add_item("JS Clever Clay"){claymaker}
      end
      #-----------------------------------------------------------------------
      file_loaded(is_this_file)
      
      	def claymaker
      		# Make use of the SU7 speed boost with start_operation while making sure it works in SU6.
      		if Sketchup.version.split('.')[0].to_i >= 7
      			Sketchup.active_model.start_operation("claymaker", true)
      		else
      			Sketchup.active_model.start_operation("claymaker")
      		end
      		
      			model = Sketchup.active_model 
      			materials = model.materials
      			entities = model.entities
      			
      			m = materials.add "ClayMat" 
      			m.color = [200, 200, 200]
      			m.alpha = 1
      
      		entities.each { | e |
      			if (e.material == nil) && (e.kind_of?(Sketchup;;Face))
      				e.material = "ClayMat"
      				e.back_material = "ClayMat" if e.respond_to? "back_material"
      			end
      			if (e.kind_of?(Sketchup;;Face) && (e.material.alpha < 1 )) 
      				e.material.texture = nil
      				e.material.color = [200, 200, 200]
      			end
      			if (e.kind_of?(Sketchup;;Face) && (e.material.alpha == 1 )) 
      				e.material = "ClayMat"
      				e.back_material = "ClayMat" if e.respond_to? "back_material"
      			end
      		}
      		Sketchup.active_model.commit_operation
      	end
      
      
      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        
            # CleverClay.rb
            # Version; 1.0
            # Turns all materials Gray but keeps transparency if any
            # Jan Sandström www.pixero.com
            # Based on Thomthoms "Blackout"
        
            require 'sketchup.rb'
        
            #-----------------------------------------------------------------------
            is_this_file=File.basename(__FILE__)
            if not file_loaded?(is_this_file)
              UI.menu("Plugins").add_item("JS Clever Clay"){claymaker}
            end
            #-----------------------------------------------------------------------
            file_loaded(is_this_file)
        
               def claymaker
                  # Make use of the SU7 speed boost with start_operation while making sure it works in SU6.
                  if Sketchup.version.split('.')[0].to_i >= 7
                     Sketchup.active_model.start_operation("claymaker", true)
                  else
                     Sketchup.active_model.start_operation("claymaker")
                  end
                  
                     model = Sketchup.active_model
                     materials = model.materials
                     entities = model.entities
                     
                     m = materials.add "ClayMat"
                     m.color = [200, 200, 200]
                     m.alpha = 1
        
                  entities.each { | e |
                     if (e.material == nil) && (e.kind_of?(Sketchup;;Face))
                        e.material = "ClayMat"
                        e.back_material = "ClayMat" if e.respond_to? "back_material"
                     end
                     if (e.kind_of?(Sketchup;;Face) && (e.material.alpha < 1 ))
                        e.material.texture = nil
                        e.material.color = [200, 200, 200]
                     end
                     if (e.kind_of?(Sketchup;;Face) && (e.material.alpha == 1 ))
                        e.material = "ClayMat"
                        e.back_material = "ClayMat" if e.respond_to? "back_material"
                     end
                  }
        		  
        		  # Loop over all the definitions in the model
        		  model.definitions.each { |d|
        			d.entities.each { |e|
        				# do the same stuff you did to the model.entities here.
        			}
        		  }
        		  
        		  
                  Sketchup.active_model.commit_operation
               end
        
        
        

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

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

          Thanks! 👍

          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