sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Custom Attributes

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 4 Posters 378 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.
    • F Offline
      fizgig
      last edited by

      Not sure what I'm missing here. I have a model where I've used the regular GUI "Component Attributes" tool to add a custom attribute to a component (a part number). I've done that to many components and now want to print out the list of all part numbers in the model. The attribute name is "PN"

      I thought this would do it:

      require 'sketchup'
      
      model=Sketchup.active_model
      entities = model.entities	
      
      entities.each { |yo|
      	  UI.messagebox(yo.get_attribute "PN" )
      }
      

      I get error messages referring to libraries. I see from the documentation that the get_attribute method requires a dict_name and a key but I don't know what those are, I only know "PN".

      Can anyone shed some light?

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

        Can you post a screenshot of the attribute you've set using the GUI tool?

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

        1 Reply Last reply Reply Quote 0
        • F Offline
          fizgig
          last edited by

          Here's a screenshot.


          attribute.PNG

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

            You'll need to look in the attribute dictionary named 'dynamic_attibutes' either attached to the instance, or possibly to the definition.

            Hi

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

              @fizgig said:

              I've done that to many components and now want to print out the list of all part numbers in the model. The attribute name is "PN"

              Can't you do File -> Generate Report?

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

              1 Reply Last reply Reply Quote 0
              • F Offline
                fizgig
                last edited by

                I can generate a report just fine.

                I'm looking to make a custom script that only looks at the items that have that custom attribute typed in, then reads in a list of prices for each part number from another csv file and calculates price based on that.

                First step is to identify all objects that have the custom attribute. Not having much luck yet.

                1 Reply Last reply Reply Quote 0
                • F Offline
                  fizgig
                  last edited by

                  I've modified my code trying to use what Jim suggested:

                  model=Sketchup.active_model
                  entities = model.entities
                  	
                  entities.each { |yo|
                    UI.messagebox(yo.get_attribute "dynamic_attibutes", "PN" )
                  }
                  

                  I get a blank UI message to hit OK and then it's done. I was expecting to get a lot of UI messages since there will be many entities in the model. Having one blank message is odd.

                  1 Reply Last reply Reply Quote 0
                  • F Offline
                    fizgig
                    last edited by

                    Found a page that shows how to do this: http://code.google.com/apis/sketchup/docs/tutorial_attrreporting.html

                    1 Reply Last reply Reply Quote 0
                    • Chris FullmerC Offline
                      Chris Fullmer
                      last edited by

                      Try this code. Have your Dynamic component selected, then run this in the web console:

                      model=Sketchup.active_model
                      entities = model.entities
                      sel = model.selection[0]
                      
                      
                      sel.attribute_dictionaries.each do |e|
                      puts "***DICTIONARY NAME***"
                      puts e.name
                      puts ""
                      puts "*****VALUES*****"
                      puts e.values
                      puts ""
                      puts "*****KEYS*****"
                      puts e.keys
                      puts ""
                      end
                      

                      It will output to the Ruby Console, so have that open. That should show you some info.

                      Chris

                      Lately you've been tan, suspicious for the winter.
                      All my Plugins I've written

                      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