sketchucation logo sketchucation
    • Login
    1. Home
    2. hank
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now
    H
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 9
    • Posts 40
    • Groups 1

    hank

    @hank

    10
    Reputation
    1
    Profile views
    40
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    hank Unfollow Follow
    registered-users

    Latest posts made by hank

    • RE: [Plugin] Material Tools

      OK, figured out what is up with "List Textures in Console" I think...

      I changed puts to print in the following def from Plugins/tt_material_tools/core.rb and it works in SU2018 (sorry ThomThom - I'm probably not supposed to be messing around in there!?). So general question... is puts no longer valid in 2018?

      def self.list_textures
          Sketchup.send_action('showRubyPanel;')
          # Collect textures and sort by size
          mats = Sketchup.active_model.materials.select { |m|
            !m.texture.nil?
          }
          mats.sort! { |a,b|
            size_a = a.texture.image_width * a.texture.image_height
            size_b = b.texture.image_width * b.texture.image_height
            size_b <=> size_a
          }
          # Print textures
          print "=== TEXTURE MATERIALS BY SIZE ==="
          buffer = ''
          mats.each { |m|
            next if m.texture.nil?
            t = m.texture
            size = t.image_width * t.image_height
            file = File.basename( t.filename )
            path = File.dirname( t.filename )
            #puts "#{m.display_name} - #{t.image_width}x#{t.image_height} - #{t.filename}"
            buffer << "#{m.display_name}\n"
            buffer << "  Size; #{t.image_width}x#{t.image_height} pixels\n"
            buffer << "  Size; #{self.readable_file_size(size*3, 2)} estimated uncompressed RGB\n"
            buffer << "  Size; #{self.readable_file_size(size*4, 2)} estimated uncompressed RGBA\n"
            if File.exist?( t.filename )
              disksize = File.size( t.filename )
              buffer << "  Size; #{self.readable_file_size(disksize, 2)} on disk\n"
            end
            buffer << "  File; #{file}\n"
            buffer << "  Path; #{path}\n"
          }
          print buffer
          print "---"
        end
      
      posted in Plugins
      H
      hank
    • RE: [Plugin] Material Tools

      Thanks for a great plugin thomthom. As is mentioned on Extension Warehouse, "List Textures in Console" generates a blank console window. Is this just a SU2018 thing or are other folks experiencing that issue?

      posted in Plugins
      H
      hank
    • RE: Search a DC attribute string value

      YES! I see now. That is some pretty sweet re-engineering of the pretty remedial string functions! I do wish FIND would just return FALSE if the string is not found but oh well. Thanks Again pcmoor!

      posted in Dynamic Components
      H
      hank
    • RE: Search a DC attribute string value

      Thanks pcmoor.

      So... trying to understand this. You have:

      =if((find("hello",Astring&"hello",1)-len(Astring))<0,"true","false")
      

      where Astrin is set to

      hellggggheloxxhell
      

      So in other words

      =if((find("hello","hellggggheloxxhell"&"hello",1)-len("hellggggheloxxhell"))<0,"true","false")
      

      Which I think means:
      If FIND returns a number that is greater than the length of the search string, return true.

      So you are sort of forcing FIND to return something if the search string is not found by a certain position by adding the search string onto the end of the search haysatck,right?

      I'm not sure I understand completely but this seems like some ninja stuff!

      posted in Dynamic Components
      H
      hank
    • Search a DC attribute string value

      If you wanted to see if the string "Hello" was in the following attribute string value...

      qwertyHello12345

      How would you do it?

      The trick is, can you return one value (like "TRUE" or "1") if found and another (like "FALSE" or "0") if not?

      I would be interested in a Ruby solution too if necessary!

      posted in Dynamic Components sketchup
      H
      hank
    • RE: Ruby Group Copy - Regardless of Context?

      Thank you Dan!

      posted in Developers' Forum
      H
      hank
    • RE: How to use FIND() in an IF() statement

      Thank You Jim!

      So how about if I wanted to find out if the string "SINGLE" exists anywhere in the string?

      posted in Dynamic Components
      H
      hank
    • RE: Ruby Group Copy - Regardless of Context?

      Thanks Dan.

      So it sounds like really what I am doing is saying

      give me entities whose layer property is 'X'
      Right?

      And regarding...

      @unknownuser said:

      And yes, transformations of nested objects are a PITB.

      I am glad I'm not alone in that sentiment!

      posted in Developers' Forum
      H
      hank
    • RE: Importing Bulk Attribute Values from CSV

      BTW, the answer to the original question was that

      
      input = UI.inputbox(@prompts, @defaults, @list, "Select Attribute Target")
      
      

      returns an array of values because typically the inputbox would present more than 1 option. In my case there was only one input or prompt so when I put input into

      
      set_result = Sketchup.active_model.set_attribute("dynamic_attributes", input, att_string.to_s )
      
      

      I was actually sending in an array and thus setting a new key in the format ["whatever user put into inputbox"]. Even .to_s did not seem to help...

      
      set_result = Sketchup.active_model.set_attribute("dynamic_attributes", input.to_s, att_string.to_s )
      
      

      The answer was to get the first item in the array like so:

      
      set_result = Sketchup.active_model.set_attribute("dynamic_attributes", input[0], att_string.to_s )
      
      
      posted in Developers' Forum
      H
      hank
    • RE: Importing Bulk Attribute Values from CSV

      Alright @TIG, I re-wrote this script trying to comply with your suggestions and it worked! Thank you for your help!

      Here is the updated script for your entertainment:

      
      require 'sketchup.rb'
      module AttModuleTop
      	module AttModuleBottom
      		class<<self
      			def list_att()
      				model = Sketchup.active_model
      				attrdicts = model.attribute_dictionaries
      				attrdict = attrdicts["dynamic_attributes"]
      				if(!attrdict)
      					UI.messagebox("AttTools is intended for use within Dynamic Component Files only")
      				else
      					@prompts = ["What attribute to overwrite"]
      					@defaults = [""]
      					@list = []
      					@option_pairs = ""
      					option_string = "select attribute to overwrite"
      					attrdict.each{|key,value|
      						@option_pairs += "key; #{key} | value; #{value}\n"
      						option_string += "|#{key}"
      					}
      					@list << option_string
      				end
      			end
      			def replace_att()
      				list_att()
      				new_prompt = "What should it be set to?"
      				@prompts << new_prompt
      				input = UI.inputbox(@prompts, @defaults, @list, "Select Attribute Target")
      				set_result = Sketchup.active_model.set_attribute("dynamic_attributes", input[0], input[1] )
      				UI.messagebox('succesfully set ' + input[0] + ' to ' + set_result + '!')
      			end
      			def load_att()
      				list_att()
      				input = UI.inputbox(@prompts, @defaults, @list, "Select Attribute Target")
      				att_string = ""
      				csv=UI.openpanel("Choose CSV File...")
      				lines=IO.readlines(csv)
      				lines.each{|line|
      					line.chomp!
      					next if line.empty?
      					new_line = line.gsub(",", " ") #replace commas
      					new_line = new_line.gsub("  ", "") #replace double spaces
      					new_line = new_line.gsub("   ", "") #replace double spaces (again)
      					new_line = new_line.gsub("& ", "&") #replace double spaces (again)
      					new_line = new_line.gsub("= ", "=") #replace double spaces (again)
      					att_string += new_line.to_s 
      				}
      				set_result = Sketchup.active_model.set_attribute("dynamic_attributes", input[0], att_string.to_s )
      				UI.messagebox('succesfully set ' + input[0] + ' to ' + set_result + '!', MB_MULTILINE)
      			end
      			def report_att()
      				list_att()
      				if(@option_pairs)
      					UI.messagebox(@option_pairs, MB_MULTILINE)
      					#puts @option_pairs
      				end
      			end
      		end # end of class
      	end # end of module AttModuleBottom
      end # end of module AttModuleTop
      
      # menus ##############################################################
      
      if( not file_loaded?("att_tools.rb") )
      	main_menu = UI.menu("Plugins").add_submenu("Att Tools")
      	main_menu.add_item("Load Attributes") {(AttModuleTop;;AttModuleBottom;;load_att)}
      	main_menu.add_item("Replace Attribute") {(AttModuleTop;;AttModuleBottom;;replace_att)}
      	main_menu.add_item("Report Attributes") {(AttModuleTop;;AttModuleBottom;;report_att)}
      end
      file_loaded("att_tools.rb")
      
      
      posted in Developers' Forum
      H
      hank