sketchucation logo sketchucation
    • Login
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Entity ID and Materials!

    Scheduled Pinned Locked Moved Developers' Forum
    15 Posts 4 Posters 3.8k Views 4 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.
    • M Offline
      Marc477
      last edited by

      Then how can I find: starting from a ruby API material: the corresponding SDK material ?

      1 Reply Last reply Reply Quote 0
      • M Offline
        Marc477
        last edited by

        I don't really understand how it is possible to have no persistent ID. In the skp file: how each face knows to which material it is bound? I supposed there is an ID saved with the face that tells which material is linked to the face.

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

          Any Material will have a unique '.name'.

          So that is effectively its 'ID' spanning sessions...

          TIG

          1 Reply Last reply Reply Quote 0
          • tt_suT Offline
            tt_su
            last edited by

            The serialization and serialization use its own way to store the material references for each face. But entityID is not something restored between sessions. As TIG mentions, the material name is the persistent ID for materials.

            1 Reply Last reply Reply Quote 0
            • M Offline
              Marc477
              last edited by

              Ok thank you! I though 2 materials could have the same name.

              1 Reply Last reply Reply Quote 0
              • jiminy-billy-bobJ Offline
                jiminy-billy-bob
                last edited by

                @tt_su said:

                As TIG mentions, the material name is the persistent ID for materials.

                But the name can change, right? How is that a persistent ID?

                25% off Skatter for SketchUcation Premium Members

                1 Reply Last reply Reply Quote 0
                • tt_suT Offline
                  tt_su
                  last edited by

                  @jiminy-billy-bob said:

                  @tt_su said:

                  As TIG mentions, the material name is the persistent ID for materials.

                  But the name can change, right? How is that a persistent ID?

                  It's persistent in the sense that it will have the same name when you reopen the file and for as long as until you change it - as oppose to entityID which will change. And it's an ID because you cannot have two identical material names in a model.

                  1 Reply Last reply Reply Quote 0
                  • jiminy-billy-bobJ Offline
                    jiminy-billy-bob
                    last edited by

                    Yeah but the plugin has to be installed and active to keep track of name changes.
                    As opposed to groups/instances GUIDs which will remain the same no matter what. The plugin will always be able to retreive it.

                    For me that's a huge difference.

                    25% off Skatter for SketchUcation Premium Members

                    1 Reply Last reply Reply Quote 0
                    • tt_suT Offline
                      tt_su
                      last edited by

                      @jiminy-billy-bob said:

                      Yeah but the plugin has to be installed and active to keep track of name changes.

                      Yes a GUID is a different animal. I see where you are coming from.

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

                        In that case you need to give the material you want to keep track of an attribute that will endure across sessions and is thereby independent of its 'name' etc.
                        tid = Time.now.to_f some_material.set_attribute("matID", "tid", tid)
                        Now save 'tid' in some meaningful data collection 'external' to the SKP, or say in an array in an attribute dictionary attached to the model itself...

                        Later on you reopen the model and you want to find a specific material that has some recovered 'tid' float value...
                        material = nil model.materials.each{|mat| if tid == mat.get_attribute("matID", "tid", nil) material = mat break end }
                        If the material has been deleted you get no match - material == nil - and you adjust your stored data collection accordingly.
                        Otherwise it exists...
                        You can also batch process a model.materials, and if there is not one already you add a 'matID' with a 'tid' attribute to each material, and also update the stored data collection...

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • jiminy-billy-bobJ Offline
                          jiminy-billy-bob
                          last edited by

                          Yeah TIG, I already do just that with layers πŸ˜„

                          But calling the name a "persistent ID" was not right to me.

                          25% off Skatter for SketchUcation Premium Members

                          1 Reply Last reply Reply Quote 0
                          • M Offline
                            Marc477
                            last edited by

                            Also, I found that 2 materials CAN have the same name in a specific case: If you name one material Color_000 for example, it will be named like the Sketchup internal material of the same name: [Color_000]. (It seems that the SDK removes the brakets '[' and ']' when you get the name of an internal material with SUMaterialGetName()).

                            1 Reply Last reply Reply Quote 0
                            • tt_suT Offline
                              tt_su
                              last edited by

                              Ah, yea - there is name and display_name - at least in the Ruby API. name is the unique one that should be used to refer to materials. display_name should be used only to display the material name to the UI.

                              However, it appear that the C API doesn't quite do that. Let me have a chat with the rest of the team.

                              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