• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Material Attributes

Scheduled Pinned Locked Moved Developers' Forum
14 Posts 7 Posters 2.3k Views 7 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.
  • A Offline
    Al Hart
    last edited by Al Hart 26 Dec 2007, 22:40

    I finally got around to trying to store some attributes on a material. It worked fine for attributes in my model, but when I saved the attribute as a material and tried to reuse it the attributes were lost.
    [Note: I added some additional detail to this posting after it was originally posted.]

    Here is a Ruby script to place some attributes on a material.

    def test_atts
    		model = Sketchup.active_model
    		material = model.materials[0]
    		material.set_attribute("dict1","att11","value_11")
    		material.set_attribute("dict1","att12","value_12")
    		material.set_attribute("dict1","att13","value_13")
    		material.set_attribute("dict2","att21","value_21")
    		material.set_attribute("dict2","att22","value_22")
    		material.set_attribute("dict2","att23","value_23")
    		material.set_attribute("dict3","att31","value_21")
    		material.set_attribute("dict3","att32","value_22")
    		material.set_attribute("dict3","att33","value_23")	
    	end#def
    

    I can fetch the attributes just fine from the Material in SketchUp:

    atts1.jpg

    But when I load that material into another model and place it on a face, the attributes are wrong.

    atts2.jpg

    Here is the XML code for the attributes from the saved material.
    (This is extracted from the .SKM file saved by SketchUp using WinZip.)
    (They are correct. So I presume SketchUp is not reading these properly when it saves the materials.)

    - <n0;AttributeDictionaries count="3">
    - <n0;AttributeDictionary count="3" name="dict1">
      <n0;Attribute key="att11" type="10">value_11</n0;Attribute> 
      <n0;Attribute key="att12" type="10">value_12</n0;Attribute> 
      <n0;Attribute key="att13" type="10">value_13</n0;Attribute> 
      </n0;AttributeDictionary>
    - <n0;AttributeDictionary count="3" name="dict2">
      <n0;Attribute key="att21" type="10">value_21</n0;Attribute> 
      <n0;Attribute key="att22" type="10">value_22</n0;Attribute> 
      <n0;Attribute key="att23" type="10">value_23</n0;Attribute> 
      </n0;AttributeDictionary>
    - <n0;AttributeDictionary count="3" name="dict3">
      <n0;Attribute key="att31" type="10">value_21</n0;Attribute> 
      <n0;Attribute key="att32" type="10">value_22</n0;Attribute> 
      <n0;Attribute key="att33" type="10">value_23</n0;Attribute> 
      </n0;AttributeDictionary>
      </n0;AttributeDictionaries>
    

    I saved the loaded material and looked in its XML file and the attributes were messed up.
    (This is extracted from the .SKM file saved by SketchUp using WinZip.)
    (The material was loaded and saved using the SketchUp Materials Window.)

    
    - <n0;AttributeDictionaries count="3">
    - <n0;AttributeDictionary count="1" name="dict1">
      <n0;Attribute key="att11" type="10">value_11</n0;Attribute> 
      </n0;AttributeDictionary>
    - <n0;AttributeDictionary count="1" name="dict1">
      <n0;Attribute key="att11" type="10">value_11</n0;Attribute> 
      </n0;AttributeDictionary>
    - <n0;AttributeDictionary count="1" name="dict1">
      <n0;Attribute key="att11" type="10">value_11</n0;Attribute> 
      </n0;AttributeDictionary>
      </n0;AttributeDictionaries>
    
    

    Has anyone else run into this?

    SketchUp - are you working on a fix?

    Al Hart

    http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
    IRender nXt from Render Plus

    1 Reply Last reply Reply Quote 0
    • D Offline
      Didier Bur
      last edited by 27 Dec 2007, 09:19

      Hi,
      How do you export the XML code for the materials ? Maybe it's in this process that there is something wrong ?

      DB

      1 Reply Last reply Reply Quote 0
      • A Offline
        AdamB
        last edited by 27 Dec 2007, 14:13

        FWIW I use attributes on materials and it "works-fine-for-me" (tm)

        ie Attributes getting serialised works fine - so I agree with Didier, I'd revisit your processing code.

        Adam

        Developer of LightUp Click for website

        1 Reply Last reply Reply Quote 0
        • A Offline
          Al Hart
          last edited by 27 Dec 2007, 16:33

          Thanks for the response.

          I go to the SketchUp Material Window and use Save As, and then view the XML after loading the .SKM file with WinZip.

          The .XML is not part of the process, I was just using it to see if SketchUp had saved the attributes materials properly.

          Note: This is not a problem creating materials and saving them into the.SKP file. I wanted to be able to put Attributes on a material, save it in a library, use the material in a different drawing and have the attributes still be valid.

          Here is the process:

          1. Select a SketchUp Material and place it on a face.
          2. Place more than 1 attribute directly on the material.
          3. Use the SketchUp materials window to save the material as a .SKM file.
          4. Start a new SketchUp session and a new drawing.
          5. Select the .SKM material with the SketchUp materials window
          6. Query the material to see if the attributes are still set.

          If you can do all this, I would love to have the .SKM file for the material, and also a new model with a single face in which you have placed the material.

          This would be a great help for me if we could get it to work.

          Al

          Al Hart

          http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
          IRender nXt from Render Plus

          1 Reply Last reply Reply Quote 0
          • A Offline
            avariant
            last edited by 13 Oct 2008, 20:04

            Sorry for digging up an old post, but I can't find anywhere the answer to the question posed here, the question I need answered as well.

            When you apply attributes to a material, and save that material as an SKM, the attributes are saved correctly. If you rename the SKM as a zip and examine the document.xml, the attribute dictionaries are all listed, all correct.

            But when you load that material into a new scene and apply it to a face, the attribute dictionaries are not restored correctly. What I've observed is that the number of dictionaries is reported correctly, but each dictionary reports it's name and keys/values as those stored only in the first dictionary. That you get multiple dictionaries with the same name seems a bug straight off the bat. Shouldn't all attributes with the same dictionary name be stored in a single dictionary? I suspect this is a Sketchup bug in loading the attributes from the SKM. Does anyone have any info about this?

            1 Reply Last reply Reply Quote 0
            • A Offline
              Al Hart
              last edited by 13 Oct 2008, 20:40

              Yes. This appears to be a SketchUp bug. Attributes and Attribute Dictionaries stored on materials are not saved properly in the SKM file and/or not reloaded properly.

              Al Hart

              http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
              IRender nXt from Render Plus

              1 Reply Last reply Reply Quote 0
              • A Offline
                avariant
                last edited by 13 Oct 2008, 20:44

                Ok. Has this been reported to SU as an official "bug"? It would be very nice to get it fixed some day.

                1 Reply Last reply Reply Quote 0
                • A Offline
                  Al Hart
                  last edited by 13 Oct 2008, 20:51

                  @avariant said:

                  Ok. Has this been reported to SU as an official "bug"? It would be very nice to get it fixed some day.

                  I didn't report it.

                  I suppose I hoped hey might read these threads.

                  Also, has anyone ever reported a bug and felt that the report had anything to do with the final resolution. Especially a bug like this which does not effect almost anyone? (Except we Ruby programmers who want to store attributes on materials and be able to save and reload them).

                  Al Hart

                  http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                  IRender nXt from Render Plus

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    dburdick
                    last edited by 6 Mar 2010, 09:01

                    The problem/bug of saving multiple material attributes with a material is still there but I found a workaround. It seems that the saved .skm material file when loaded will only retain a single attribute parameter. So I packed all the material params into a single string using a single parameter and then saved the material. If I need to do anything with the material attributes, I unpack them into Sketchup attributes at run-time. Kind of a kludge, but it works.

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      Al Hart
                      last edited by 6 Mar 2010, 14:23

                      That will work in some cases, and is a clever solution.

                      One of the things we are trying to do is save multiple images with a material - e.g. a bump map and specular map - in addition to the diffuse map. First we have to convert the binary to ASCII because SketchUp does not handle binary attributes properly, then we run into the problem that SketchUp can only handle about one megabyte (I don't remember the exact limit) per attribute, so we split large images up into several attributes.

                      Al Hart

                      http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                      IRender nXt from Render Plus

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by 6 Mar 2010, 14:59

                        @al hart said:

                        That will work in some cases, and is a clever solution.

                        One of the things we are trying to do is save multiple images with a material - e.g. a bump map and specular map - in addition to the diffuse map. First we have to convert the binary to ASCII because SketchUp does not handle binary attributes properly, then we run into the problem that SketchUp can only handle about one megabyte (I don't remember the exact limit) per attribute, so we split large images up into several attributes.

                        there's a attribute size limit? hm... that would have been useful info to have seen in the manual.

                        binary to ASCII? you mean base64?

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

                        1 Reply Last reply Reply Quote 0
                        • A Offline
                          Al Hart
                          last edited by 6 Mar 2010, 16:07

                          @thomthom said:

                          there's a attribute size limit? hm... that would have been useful info to have seen in the manual.

                          binary to ASCII? you mean base64?

                          We use HEX sometimes and Base64 sometimes.

                          Try this little example:

                          
                          def test_att(size)
                          	test_string = "A"*size
                          	printf("size; %s test_string.length; %s\n",
                          		size, test_string.length)
                          	model = Sketchup.active_model
                          	model.set_attribute("test_string","test_string", test_string)
                          	test_string2 = model.get_attribute("test_string","test_string")
                          	printf("size; %s test_string.length; %s test_string2.length; %s\n",
                          		size, test_string.length, test_string2.length)
                          end#def
                          
                          

                          If you load it and type in:
                          test_att(100) - works
                          test_att(100000) - works
                          test_att(1000000) - works
                          test_att(2000000) - dumps core

                          Al Hart

                          http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                          IRender nXt from Render Plus

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            dburdick
                            last edited by 6 Mar 2010, 19:56

                            @al hart said:

                            That will work in some cases, and is a clever solution.

                            One of the things we are trying to do is save multiple images with a material - e.g. a bump map and specular map - in addition to the diffuse map. First we have to convert the binary to ASCII because SketchUp does not handle binary attributes properly, then we run into the problem that SketchUp can only handle about one megabyte (I don't remember the exact limit) per attribute, so we split large images up into several attributes.

                            Al, are you implying that you've found a way for Sketchup materials to load with multiple attributes attached? If so, can you share the magic of this invention.

                            1 Reply Last reply Reply Quote 0
                            • Dan RathbunD Offline
                              Dan Rathbun
                              last edited by 24 Mar 2017, 12:15

                              @avariant said:

                              Ok. Has this been reported to SU as an official "bug"? It would be very nice to get it fixed some day.

                              for SketchUp 2017

                              @unknownuser said:

                              (https://help.sketchup.com/en/article/141303)":2kct16r6]
                              Fixes/Improvements General

                              SketchUp API Release Notes

                              • (Mac) Fixed issue where SKM files lost attribute dictionaries when saved from ‘In Model’ to local library.

                              I'm not here much anymore.

                              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