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

    Script check-->materials

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 511 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.
    • P Offline
      Pout
      last edited by

      This is my script:

      ss.each{|e| 
           mat= e.get_attribute 'xdid_dict', 'sumatdisplay'
           if not mat
      	     UI.messagebox("no material specs in dict.")
             
               
      	     if e.material.display_name      
              UI.messagebox("has a material")
             else 
             UI.messagebox("has no material")
      	     end	
           end
      }
      

      What i want it to do is:
      A. See if the selected object already has dictionary attributes defined:

      ss.each{|e| 
           mat= e.get_attribute 'xdid_dict', 'sumatdisplay'
           if not mat
      	     UI.messagebox("no material specs in dict.")
      
      

      These values are written in an earlier stage after some command is executed (this command writes the folowing values:

      orig_name=e.material.name
                 orig_materialtype=e.material.materialType
                 orig_display_name=e.material.display_name
                 orig_texture=e.material.texture
                 orig_color=e.material.color
                 orig_alpha=e.material.alpha
                 e.set_attribute 'xdid_dict', 'sumatname', orig_name
                 e.set_attribute 'xdid_dict', 'sumattype', orig_materialtype
                 e.set_attribute 'xdid_dict', 'sumatdisplay', orig_display_name
                 e.set_attribute 'xdid_dict', 'sumattexture', orig_texture
                 e.set_attribute 'xdid_dict', 'sumatcolor', orig_color
                 e.set_attribute 'xdid_dict', 'sumatalpha', orig_alpha
      
      

      )
      Question: Isn't it just possible to get the ID of the material the object has? Instead of the need to keep all these seperate variables?

      B. Now i have noticed that fresh created objects who have no material attached do not have any material values (how does SU stores their color-visual representation?). So i check these:

      if e.material.display_name      
              UI.messagebox("has a material")
             else 
             UI.messagebox("has no material")
      	     end
      

      This does not work. If there is no material assigned, then the script stops and does not sign "has no material". If there is a material assigned then the message "has a material" shows up ok.

      Now maybe i'm a bit on the wrong path here, so i'll try to explain what i try to do:
      Store the material-color (the visual part of an entity-group-...) in an attribute dictionary.
      So when i do changes to them then i can get the original back.
      It would be great if each material in SU had an ID and each object had this ID so i just have to store that one in the attribute dict.

      Thanks!!

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        Have a look at the Greyscale plugin recently posted. It saves a material's original color before changing the material's color to greyscale.

        301 Moved Permanently

        favicon

        (www.sketchucation.com)

        Hi

        1 Reply Last reply Reply Quote 0
        • fredo6F Offline
          fredo6
          last edited by

          Pout

          You should turn on the Ruby Console, and use "puts <message>", instead of UI.messagebox. This will help you to understand what's going wrong.

          You could also take some inspiration from an old script I wrote, which toggle the selection between xray and normal.
          I reattach it here


          XraySelection.rb

          1 Reply Last reply Reply Quote 0
          • P Offline
            Pout
            last edited by

            works, thank you very much πŸ˜„

            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