sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Assign a material in the ruby console

    Scheduled Pinned Locked Moved Newbie Forum
    sketchup
    3 Posts 2 Posters 174 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.
    • C Offline
      crustybaps
      last edited by

      I have tried to add a material to some of the faces in my model and I get the error material [Brick_Antique]" not found. Could someone show me the correct way to assign a material to a face
      for i in 1..10 faces[i].material= "[Brick_Antique]"

      1 Reply Last reply Reply Quote 0
      • renderizaR Offline
        renderiza
        last edited by

        Hi, here is an example;

        model = Sketchup.active_model ;
        ents = model.entities ;
        
        materials = model.materials ;
        m = materials.add "name for material" ;
        texture = m.texture = "c;\\Users\\User\\Desktop\\folder\\texture.jpg" ;  
        m.texture.size = 60 ;
        
        use_texture = true ; #Change to false to use color only
        
        faces = ents.grep(Sketchup;;Face) ;
        
        faces.each do |e|
        
           if use_texture 
              e.material = m
           else
              e.material = [190,190,190] #Use color instead of textures
           end ;
        
        end ; 
        

        Note: By the way there is a Developers forum section which might get you better answers to your questions.

        Cheers!

        [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

        1 Reply Last reply Reply Quote 0
        • C Offline
          crustybaps
          last edited by

          Thanks that worked really well.

          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