• Login
sketchucation logo sketchucation
  • Login
โš ๏ธ Libfredo 15.4b | Minor release with bugfixes and improvements Update

What is wrong with this script?

Scheduled Pinned Locked Moved Developers' Forum
9 Posts 3 Posters 1.7k Views 3 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.
  • P Offline
    Pixero
    last edited by 29 Nov 2007, 05:26

    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")
    
    1 Reply Last reply Reply Quote 0
    • T Offline
      todd burch
      last edited by 29 Nov 2007, 05:27

      results, as returned from inputbox, is an array.

      Todd

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 29 Nov 2007, 05:28

        thresh=results[0]

        will work...

        TIG

        1 Reply Last reply Reply Quote 0
        • P Offline
          Pixero
          last edited by 29 Nov 2007, 05:29

          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

          1 Reply Last reply Reply Quote 0
          • T Offline
            todd burch
            last edited by 29 Nov 2007, 05:29

            e is most likely valid. When e does not have a material assigned, the .material method returns nil.

            Todd

            1 Reply Last reply Reply Quote 0
            • P Offline
              Pixero
              last edited by 29 Nov 2007, 05:30

              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... ๐Ÿ˜ข

              1 Reply Last reply Reply Quote 0
              • T Offline
                todd burch
                last edited by 29 Nov 2007, 05:31

                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

                1 Reply Last reply Reply Quote 0
                • P Offline
                  Pixero
                  last edited by 29 Nov 2007, 05:32

                  Thanks that did it!
                  Now if only I can get it to work with grouped objects...

                  1 Reply Last reply Reply Quote 0
                  • P Offline
                    Pixero
                    last edited by 29 Nov 2007, 05:33

                    Got it working! Thanks for the help. Read more here:
                    http://www.sketchucation.com/scf/viewtopic.php?f=9&t=1986

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    1 / 1
                    • First post
                      1/9
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement