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

    Check for existing material

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 298 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 want to check if a material (name) exists, and if not create one with that name.
      However I can't get the syntax right.
      Can't seem to find any reference to it anywhere either.
      Here's my try:

      
      if(Sketchup.active_model.materials["MyMaterial"])
      		face.material = model.materials "MyMaterial"  #If material exist use it
      	else #Else create a new material with that name
      		face.material = Sketchup;;Color.new(100,100,100) 
      		face.material.name = "MyMaterial"
      	end
      
      
      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        ` model=Sketchup.active_model
        mats=model.materials
        mname="SomeMaterialName"
        unless mat=mats[mname] ### nil if no match
        mat=mats.add(mname) ### reference to the new material

        set up 'mat' properties - RGB, alpha etc...

        end The variable ' mat' points at the material named ' mname'. If it's 'new' then you can set its properties, otherwise it be opaque/black ! ... Finally use face.material=mat` ...

        TIG

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

          Thanks. Its working now. 👍

          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