sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    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.
    • PixeroP Offline
      Pixero
      last edited by

      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

        results, as returned from inputbox, is an array.

        Todd

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          thresh=results[0]

          will work...

          TIG

          1 Reply Last reply Reply Quote 0
          • PixeroP Offline
            Pixero
            last edited by

            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

              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
              • PixeroP Offline
                Pixero
                last edited by

                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

                  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
                  • PixeroP Offline
                    Pixero
                    last edited by

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

                    1 Reply Last reply Reply Quote 0
                    • PixeroP Offline
                      Pixero
                      last edited by

                      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
                      • First post
                        Last post
                      Buy SketchPlus
                      Buy SUbD
                      Buy WrapR
                      Buy eBook
                      Buy Modelur
                      Buy Vertex Tools
                      Buy SketchCuisine
                      Buy FormFonts

                      Advertisement