• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Ruby - find a model's maximum height

Scheduled Pinned Locked Moved Newbie Forum
sketchup
3 Posts 2 Posters 224 Views
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.
  • T Offline
    Thaje
    last edited by 19 Oct 2010, 07:50

    Hello, I have searched google tirelessly for the past two hours and have not found anything remotely like I am trying to do, so I appeal to the great minds of sketchucation.

    I started ruby programming tonight so know very little. I am trying to create a ruby script which finds and saves the maximum height, length, and width of a complicated model (eg. The statue of liberty, or something) to a text file. Sounds simple, and I think it is, but I have no idea were to start.

    If someone could point me in the right direction I would be very grateful.

    Thaje

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 19 Oct 2010, 09:01

      =begin
      (c) TIG 2010
      Copy/Paste code into ../Plugins/modelXYZ.rb
      Usage; type 'modelXYZ' in Ruby Console
      =end
      require 'sketchup.rb'
      def modelXYZ()
        model = Sketchup.active_model
        bb = model.bounds
        ### NB; 'bounds' xyz values do NOT follow model axes logic
        x = bb.width.to_s
        y = bb.height.to_s
        z = bb.depth.to_s
        ### message in Ruby Console
        puts("X = " + x)
        puts("Y = " + y)
        puts("Z = " + z)
        ### text into File
        if model.path != "" ### SKP was saved
          filepath = File.dirname(model.path)
          filename = model.title + "_XYZ.txt"
          file = File.join(filepath, filename).tr("\\","/")
          f = File.new(file, "w")
          f.puts(x)
          f.puts(y)
          f.puts(z)
          f.close
          ### Tip; to make a 'spreadsheet' file change suffix to ".csv" or ".tsv"
          ### and then 'puts' one line only, thus; f.puts(x+","+y+","+z)
          puts("XYZ values written to file;")
          puts(file)
        else ### SKP is not yet saved
          UI.beep
          puts("Save this SKP to write these XYZ values to a file...")
        end#if
        puts()
      end#def
      
      

      TIG

      1 Reply Last reply Reply Quote 0
      • T Offline
        Thaje
        last edited by 20 Oct 2010, 04:40

        @tig said:

        =begin
        > (c) TIG 2010
        > Copy/Paste code into ../Plugins/modelXYZ.rb
        > Usage; type 'modelXYZ' in Ruby Console
        > =end
        > require 'sketchup.rb'
        > def modelXYZ()
        >   model = Sketchup.active_model
        >   bb = model.bounds
        >   ### NB; 'bounds' xyz values do NOT follow model axes logic
        >   x = bb.width.to_s
        >   y = bb.height.to_s
        >   z = bb.depth.to_s
        >   ### message in Ruby Console
        >   puts("X = " + x)
        >   puts("Y = " + y)
        >   puts("Z = " + z)
        >   ### text into File
        >   if model.path != "" ### SKP was saved
        >     filepath = File.dirname(model.path)
        >     filename = model.title + "_XYZ.txt"
        >     file = File.join(filepath, filename).tr("\\","/")
        >     f = File.new(file, "w")
        >     f.puts(x)
        >     f.puts(y)
        >     f.puts(z)
        >     f.close
        >     ### Tip; to make a 'spreadsheet' file change suffix to ".csv" or ".tsv"
        >     ### and then 'puts' one line only, thus; f.puts(x+","+y+","+z)
        >     puts("XYZ values written to file;")
        >     puts(file)
        >   else ### SKP is not yet saved
        >     UI.beep
        >     puts("Save this SKP to write these XYZ values to a file...")
        >   end#if
        >   puts()
        > end#def
        > 
        

        Thanks man, this looks exactly like what I'm after. Now I just have to work through and understand it...

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

        Advertisement