sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Basic operation on char...

    Scheduled Pinned Locked Moved Developers' Forum
    16 Posts 2 Posters 297 Views 2 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.
    • N Offline
      njeremy2
      last edited by

      @thomthom said:

      Btw, did you create the component? Is it intended for the user to read that reference code?
      If not, then you might want to store it in an attribute:

      Entity#get_attribute: https://developers.google.com/sketchup/docs/ourdoc/entity#get_attribute
      Entity#set_attribute: https://developers.google.com/sketchup/docs/ourdoc/entity#set_attribute
      class AttributeDictionary: https://developers.google.com/sketchup/docs/ourdoc/attributedictionary
      class AttributeDictionaries: https://developers.google.com/sketchup/docs/ourdoc/attributedictionaries

      no no ! it's ok !

      Components are already create when I put components in design I launch my plug test.
      My plugin search all components and then I ask it to display each references include in their description

      1 Reply Last reply Reply Quote 0
      • N Offline
        njeremy2
        last edited by

        @thomthom said:

        Btw, did you create the component? Is it intended for the user to read that reference code?
        If not, then you might want to store it in an attribute:

        Entity#get_attribute: https://developers.google.com/sketchup/docs/ourdoc/entity#get_attribute
        Entity#set_attribute: https://developers.google.com/sketchup/docs/ourdoc/entity#set_attribute
        class AttributeDictionary: https://developers.google.com/sketchup/docs/ourdoc/attributedictionary
        class AttributeDictionaries: https://developers.google.com/sketchup/docs/ourdoc/attributedictionaries

        Sorry I don't understand the first time I read your post...
        I can use attributes but I see in AUTOMATIC Sketchup.pdf that's attributes cannot be stored when you save a component (I understand that)

        And put the reference into the description was for me the easiest solution (I hope, if someone has a better solution, tell me).

        In that way, I'm sure the reference is shared when I sent a component to my database

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

          @njeremy2 said:

          Sorry I don't understand the first time I read your post...
          I can use attributes but I see in AUTOMATIC Sketchup.pdf that's attributes cannot be stored when you save a component (I understand that)

          If you store attributes with the definition then you can export the component with the attributes.

          Example:

          componentinstance.definition.set_attribute('MyTest', 'Foo', 'Bar')

          Export component

          New model

          Import exported model

          componentinstance.definition.get_attribute('MyTest', 'Foo')
          ( returns 'Bar' )

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

          1 Reply Last reply Reply Quote 0
          • N Offline
            njeremy2
            last edited by

            hmmmm, well...

            With that, you can add an attribute called "reference" for all components and set attribute then ?

            So if I do like that : componentinstance.definition.set_attribute('Reference', '755480RED', 'Valuedefaultif 755480RED doesnt exist')

            That would work ?

            And to list all references, how should I do ?
            componentinstance.definition.set_attribute('Reference') ?

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

              Read the API docs again.

              set_attribute takes three arguments. The third one is the value.

              entity.set_attribute( 'DictionaryName', 'Key', 'Value' )
              entity.get_attribute( 'DictionaryName', 'Key' )

              So, if you do something like to to add a reference ID:
              entity.set_attribute( 'nJeremy2', 'Reference', referenceID )

              You can list all definitions with a reference set like so:

              <span class="syntaxdefault"><br />for definition in Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions<br />  next if definition</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">image</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault">  next if definition</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault">  referenceID </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> entity</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxstring">'nJeremy2'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Reference'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  next if referenceID</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">nil</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault">  </span><span class="syntaxcomment"># Do something to the definition here...<br /></span><span class="syntaxdefault">end<br /></span>
              

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

              1 Reply Last reply Reply Quote 0
              • N Offline
                njeremy2
                last edited by

                yeah ok !
                I will try but the result is not guarantee

                1 Reply Last reply Reply Quote 0
                • N Offline
                  njeremy2
                  last edited by

                  my solution by putting the reference in description work, it isn't good programming but it works lol

                  thank you thom !

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

                    What if your user accidentally modify the description? Or some other plugin the user has install modifies it?

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

                    1 Reply Last reply Reply Quote 0
                    • N Offline
                      njeremy2
                      last edited by

                      @thomthom said:

                      What if your user accidentally modify the description? Or some other plugin the user has install modifies it?

                      right...

                      But I try to use attributes, but I cannot do it right

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

                        What is not working right?
                        Do you have a sample code?

                        When assigning an attribute to the definition the attribute is stored whenever you export - it works fine. But if it doesn't work for you then it's probably something in your code that isn't quite right.

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

                        1 Reply Last reply Reply Quote 0
                        • N Offline
                          njeremy2
                          last edited by

                          @thomthom said:

                          What is not working right?
                          Do you have a sample code?

                          When assigning an attribute to the definition the attribute is stored whenever you export - it works fine. But if it doesn't work for you then it's probably something in your code that isn't quite right.

                          I have nothing at home, tomorrow I'll show you what I need to do with that (with screenshots)

                          1 Reply Last reply Reply Quote 0
                          • N Offline
                            njeremy2
                            last edited by

                            For this example I put a tree and a Blue cube.
                            The tree has no description and the Cube has code reference then the real description after "b755480 BLABLABLA".
                            Then I create a groupe with the 2 objects called "Tree+cube"

                            http://img840.imageshack.us/img840/23/designpx.png

                            Now I export all information with my plugin :

                            http://img689.imageshack.us/img689/8130/exports.png

                            then I export all information in CSV File :

                            http://img804.imageshack.us/img804/2953/exportcsv.png

                            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