sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Materials again

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 222 Views 3 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

      me again...

      i don't know why, but the attribut "ablauf", "material" always receives a new value, even if the face's material is included in the array called invalid_material. i'll post the code, because i realy don't know how to fix it.

          
      ents.each{|e|
                if e.typename == "Face"
                   start = e.get_attribute "ablauf", "baubeginn"
                   ende = e.get_attribute "ablauf", "bauende"
                   if (e.material)
                     invalid_materials = ['bau_mat', 'fertig_mat', 'inplanung']
                     unless invalid_materials.include?( e.material.name )
                       mat_vorher = e.material.name
                       e.set_attribute("ablauf", "material", mat_vorher)
                     end
                   end
                           
                           
                if @woche.to_i >= start.to_i && @woche.to_i < ende.to_i
                  e.material = bau_mat
                end
                if @woche.to_i >= ende.to_i
                  e.material =fertig_mat
                end
                if @woche.to_i < start.to_i
                  e.material = inplanung
                end
             end
                           
              }
         
      
          #now the code that reloads the material
      
          def mat_back
             mod = Sketchup.active_model
             ents = mod.entities
             mats = mod.materials
             default_mat = mats.add "standardwert"
             default_mat.color = [50,250,50]
             ents.each{|e|
                        if e.typename == "Face"
                          if (e.get_attribute "ablauf", "material")
                            mat_temp=e.get_attribute "ablauf", "material"
                            e.material=mats[mat_temp]
                          else
                            e.material=default_mat
                          end
                        end
                       }
      
      
          end
      
      
      
      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        To check the materials' name make the line
        p mat_vorher = e.material.name
        Then it will print the name of the material in the [opened] Ruby Console to compare with your invalid_materials list...
        Looks like they don't match ?

        TIG

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

          it was my mistake. the materials were declared in a tool as a local variable. every time the tool was invoken, the materials werde declared. so to the materials name was a number added, because the material already existed in the materials container. when you only once invoke the tool everything is fine. one more an it didn't work.

          is it possible to declare a material as a constant or to declare it with an "@" in a class to avoid that?

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            Why not just check if the material exists?

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

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

              For example:

              
              if mats["standardwert"]
                default_mat = mats["standardwert"]
              else
                default_mat = mats.add("standardwert")
                default_mat.color = [50,250,50]
              end
              

              TIG

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

                it works. thanks a lot, once more πŸ˜„

                tommorow t'll try to declare the material in the constructor of the class anyway, to avoid putting all the trash in the memory.

                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