What is wrong with this script?
-
I got inspired by a thread here about shadow threshold and thought I'd try it, but I get an error: #<ArgumentError: comparison of Float with Array failed>
What am I doing wrong?
# Name ; JS Shadow Threshold # Description ; Sets cast shadow with a threshold # Author ; Jan Sandstrom (http://www.pixero.com) # Date ; 12 Aug 2007 require 'sketchup.rb' def jsShadowThreshold model = Sketchup.active_model entities = model.active_entities ss = model.selection if ss.empty? UI.messagebox("Nothing selected!") return nil end # Dialog @thresh = 0.7 if not @thresh prompts = ["Shadow threshold; "] values = [@thresh] results = inputbox(prompts, values, "Shadow threshold") thresh = results @thresh = thresh ss.each {|e| next if not (e.is_a? Sketchup;;Face) #Ignore items in the selection that are not faces. alpha = e.material.alpha if (alpha < thresh) #Error; #<ArgumentError; comparison of Float with Array failed> e.cast_shadows= false else e.cast_shadows= true end #if } #end of ss.each end #jsShadowThreshold if( not file_loaded?("jsShadowThreshold.rb") ) UI.menu("Plugins").add_separator UI.menu("Plugins").add_item("JS Shadow Threshold") { jsShadowThreshold } end file_loaded("jsShadowThreshold.rb") -
results, as returned from inputbox, is an array.
Todd
-
thresh=results[0]
will work...
-
Thanks, but now another error has occured.

For the following line:alpha = e.material.alpha #Error; #<NoMethodError; undefined method `alpha' for nil;NilClass>Sorry if it's elementary but I can't seem to get it right.
Thanks in advance.
/Jan -
e is most likely valid. When e does not have a material assigned, the .material method returns nil.
Todd
-
Ok, progressing veeery slowly....

When I assign a material to the faces I now get this:e.cast_shadows= false #Error; #<NoMethodError; undefined method `cast_shadows=' for #<Sketchup;;Face;0x7532bb0>>If I remove the e in front of cast_shadows I don't get the error but nothing happens.
Sigh...

-
The doc is bad. Use .casts_shadows=.
To see the methods a entities allows, in the Ruby Console, enter (for example, with a face)
(face.methods - Object.methods).sort.join("\n")
Todd
-
Thanks that did it!
Now if only I can get it to work with grouped objects... -
Got it working! Thanks for the help. Read more here:
http://www.sketchucation.com/scf/viewtopic.php?f=9&t=1986
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement