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

How to store an Entity between sessions?

Scheduled Pinned Locked Moved Developers' Forum
8 Posts 3 Posters 200 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.
  • D Offline
    draftomatic
    last edited by 26 May 2011, 19:43

    I would like to be able to store an entity or a reference to an entity between sessions, and retrieve the entity quickly (i.e. without iterating every entity in the model). Is there a way? Entity.entityID doesn't last between sessions, and placing entities in attribute dictionaries isn't working for me.

    1 Reply Last reply Reply Quote 0
    • J Offline
      Jim
      last edited by 26 May 2011, 19:48

      Using Attributes is about the only way - what isn't working about them?

      Hi

      1 Reply Last reply Reply Quote 0
      • D Offline
        draftomatic
        last edited by 26 May 2011, 19:51

        @jim said:

        Using Attributes is about the only way - what isn't working about them?

        m = Sketchup.active_model
          #<Sketchup;;Model;0xdc02f80>
        m.set_attribute("mydict", "mykey", m.selection[0])
          #<Sketchup;;Face;0xe286438>
        m.get_attribute("mydict", "mykey")
          nil
        
        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 26 May 2011, 20:02

          You have to give the entity an enduring attribute like a 'guid' based on say Time.now.to_f+rand ...
          As it's a group you can iterate all definitions using .group? and break once you have a match...

          TIG

          1 Reply Last reply Reply Quote 0
          • D Offline
            draftomatic
            last edited by 26 May 2011, 20:03

            Hmm I suppose since I will be grouping the Entity, I could iterate all the groups in the model to find it... less intense than iterating entities, but still not ideal...

            This seems like it must be a common problem. Plugins will inevitably have special geometry that they want to tag and keep track of. Some of the messier models I've worked with have been >100MB and iterating model.entities isn't acceptable.

            1 Reply Last reply Reply Quote 0
            • D Offline
              draftomatic
              last edited by 26 May 2011, 20:04

              @tig said:

              You have to give the entity an enduring attribute like a 'guid' based on say Time.now.to_f+rand ...
              As it's a group you can iterate all definitions using .group? and break once you have a match...

              Yea, I've done this in the past... number of groups should be WAY less than number of entities. Sure there's no other way?

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 26 May 2011, 21:08

                @draftomatic said:

                @tig said:

                You have to give the entity an enduring attribute like a 'guid' based on say Time.now.to_f+rand ...
                As it's a group you can iterate all definitions using .group? and break once you have a match...

                Yea, I've done this in the past... number of groups should be WAY less than number of entities. Sure there's no other way?

                That's the way I do it, when I have to...
                If you have to save a particular 'thing' across sessions it must have some sort of enduring 'handle' - so if you think about it... no matter what that is you'll have to sort through lists of 'similar things' to find it... be it 'naming', 'layer', 'guid-attribute', 'material' or whatever... you'll need to 'sift' the model's entities when you reopen it...

                TIG

                1 Reply Last reply Reply Quote 0
                • D Offline
                  draftomatic
                  last edited by 26 May 2011, 22:14

                  Thanks TIG 😃

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  1 / 1
                  • First post
                    1/8
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement