Custom Attributes
-
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?
-
Can you post a screenshot of the attribute you've set using the GUI tool?
-
Here's a screenshot.
-
You'll need to look in the attribute dictionary named 'dynamic_attibutes' either attached to the instance, or possibly to the definition.
-
@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?
-
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.
-
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.
-
Found a page that shows how to do this: http://code.google.com/apis/sketchup/docs/tutorial_attrreporting.html
-
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
Advertisement