Report just one attribute
-
hi all,
i'm working on the following script:
require 'sketchup.rb' #---------------- #--------------------- def gewicht model = Sketchup.active_model selection=model.selection entity=selection.first entities=selection[1] attdict=entity.attribute_dictionary "dynamic_attributes" definitions = model.definitions component = definitions[0] #value = model.get_attribute "dynamic_attributes", "gewicht", 0 keys=attdict.keys[-4] value=attdict.values[-4] #UI.messagebox [keys, "; ", value] UI.messagebox [component.name, " ;", "Einzel-Gewicht;", value, " ", "kg"] end #-------------------------------- if( not file_loaded?("SINUS-gewichte.rb") ) toolbar = UI;;Toolbar.new "SINUS" cmd = UI;;Command.new("SINUS") { gewicht } cmd.small_icon = "weight.gif" cmd.large_icon = "weight.gif" cmd.tooltip = "Gewicht" cmd.status_bar_text = "Gewicht" cmd.menu_text = "Gewicht" toolbar = toolbar.add_item cmd toolbar.show end
i set the key index to -4 because "gewicht" is the one key i need.
any better way to retrieve a key by its name?but the script doesnt quite work yet the way i want it to.
i want to do the following:
selct one or more components i draged and dropped from my library.
(they already have a "gewicht" key with corresponding value attached to them under the dictionary "dynamic_attributes"!)
"gewicht" means weight by the way.now:
i want a messagebox to show me the following:
the single weight of each selected component
the sum of weights of all selected.that's practically it.
any suggestions?
thanks
cheers.
-
model=Sketchup.active_model ss=model.selection gewicht=0 ss.each{|e| if e.class==Sketchup;;ComponentInstance gewicht=gewicht + e.definition.get_attribute("dynamic_attributes","gewicht",0) end#if # If the component definition has no gewicht then its gewicht = 0 # Wenn die Komponente Definition hat keine gewicht dann seine gewicht = 0 } UI.messagebox("Gesamtgewicht = " + gewicht.to_s + " kg")
This should work?
Diese Arbeit sollte? -
wow thanks for the qucik and helpful reply.
when i select nothing its okay.
iget this error in the console when i have a component selected:
Error: #<TypeError: String can't be coerced into Fixnum>
C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/SINUS-gewichte.rb:13:in+' C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/SINUS-gewichte.rb:13:in
gewicht'
C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/SINUS-gewichte.rb:11:ineach' C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/SINUS-gewichte.rb:11:in
gewicht'
C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/SINUS-gewichte.rb:30
C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/SINUS-gewichte.rb:29:in `call'any suggestions?
again, thanks
-
I haven't actually tested this, but I'm guessing this should work
@tig said:
> gewicht=gewicht + e.definition.get_attribute("dynamic_attributes","gewicht",0) >
to:
gewicht=gewicht + e.definition.get_attribute("dynamic_attributes","gewicht",0).to_f -
If 'gewicht' is always a number it should add OK to the earlier version of itself...
Maybe initially set
gewicht=0.0
so it's a float rather than an integer ?
Then use cjt'sgewicht=gewicht + e.definition.get_attribute("dynamic_attributes","gewicht",0.0).to_f
Try
puts e.definition.get_attribute("dynamic_attributes","gewicht",0.0)
inside the{}
so that you see in the ruby console what it's doing... -
@artofseeing said:
i want a messagebox to show me the following:
the single weight of each selected component
the sum of weights of all selected.that's practically it.
do you want one messagebox with each weight and one with the sum, or do you want one with both the sum of the weights and each weight?
-
actually, i need one messagebox with all weiths shown(sum and single),
as a checkup if it got all the data right.then im gonna take what the messagebox has shown and save it first as a simple text file,
in the end even paste the data into cells of a scalc file where i can
estimate the final loads at certain points.
i.e.:
i have 10 lamps and 2 beamers and 4 loudspeakers hanging on a line of truss,
so i get all the weights of each part, and the sum.
this truss is i.e. hanging at 2 points, so i estimate half the final load to each point.so in the end, its a load calculation, which, up to now, i always had to do by hand.
-
got it!
the guess was right.
make all values and variables floats, and it works out.
i selected none> weight=0
i selected one> weight=6
i selected 2> weight=12thanks guys:)
now to get also the single weights...
but i can do that.
-
one more strange happening yet:
ijust found out that
the sum of weights i get is a rounded value.
for example:a lamp has the value "15,4" for the key "gewicht".
if i report on that i get "15.0"cant seem to figure out just why...
-
got it1
it was my error writing "15,4" instead of "15.4" into the value -
@artofseeing said:
got it1
it was my error writing "15,4" instead of "15.4" into the valueGerman decimal points 1,2 == 1.2 !!!
Advertisement