sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Checking wether material exists before declaring it

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 212 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.
    • K Offline
      kiesewetter
      last edited by

      Hallo!

      I want to declare a material in a method, but before it's declared it should checked wether the material already exists to avoid overloading the memory with tons of the same material. Here is the code i used but it doesn't work so far...

      
      def status_anzeigen 
        mod = Sketchup.active_model
        ents = mod.entities 
        sel = mod.selection 
        mats = mod.materials
        unless mats.include?("im_bau")
          bau_mat = mats.add "im_bau"
          bau_mat.color = [255,127,38] 
          fertig_mat = mats.add "fertig"
          fertig_mat.color = [211,211,211] 
          inplanung = mats.add"noch_nicht_angefangen"
          inplanung.color = [176,196,222]  
          inplanung.alpha = 0.3 
        end
      
      #and so on
      
      
      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        model=Sketchup.active_model materials=model.materials mat=materials.add("MyNewMaterial")if not mat=materials["MyNewMaterial"]
        This test adds a new material named "MyNewMaterial" IF it doesn't already exist AND sets ' mat' to refer to it, whether it exists OR it has just had to be made... πŸ€“

        TIG

        1 Reply Last reply Reply Quote 0
        • K Offline
          kiesewetter
          last edited by

          Ok, great. thank you. I'll change it this weekend. Hope you have a nice one πŸ˜„
          Bye.
          Tim

          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