SelectionObserver and get attributes....
-
Hello,
I see the classe http://code.google.com/intl/fr-FR/apis/sketchup/docs/ourdoc/selectionobserver.html, i use this to run a ruby script when i click on a component in skecthup.
for example:
My component "Component#1" has in "Component Attribute" an identity, adress, and others descriptions... i want when i click on this component, run my ruby script (I already did that), but i don't know to retrieve "Component Attribute". I wish put for example the attribute "identity" of "Componente#1" in a variable in ruby.
require 'sketchup.rb' class MySelectionObserver < Sketchup;;SelectionObserver def onSelectionBulkChange(selection) wd=UI;;WebDialog.new( "Somfy Controller", true, "",950, 700, 100, 100, false ) wd.show #################### #I WANT TO PUT IDENTITY ATTRIBUE OF MY COMPONENT#1 IN THIS VARIABLE identity= '000003' wd.set_url("http://localhost/final_programme/index.php?identity="+identity+"") #################### end end # Attach the observer. Sketchup.active_model.selection.add_observer(MySelectionObserver.new) # end of sample.rb
thx to help me
Pauline
-
How to set attributes?
entity.get_attribute
http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/entity.html#get_attribute
entity.set_attribute
http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/entity.html#set_attribute -
Hi Pauline, the attributes for a Dynamic Component are in the the "dynamic_attributes" attribute_dictionary.
# Check "dynamic_attributes" dictionary for a Dynamic Component identity = selected[0].get_attribute("dynamic_attributes", "identity") # the Definition may have the attribute, so... if identity.nil? identity = selected.definition.get_attribute("dynamic_attributes", "identity") end if identity.nil? # there is not attribute named "identity" else # Yes, we found "identity" end
Advertisement