sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Number of processors

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 262 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.
    • M Offline
      maricanis
      last edited by

      Hi,

      Is there a way to get number of processors with Ruby in Sketchup.
      I've found on internet solutions like this

      require 'win32ole'
      wmi = WIN32OLE.connect("winmgmts;//")
      num = wmi.ExecQuery("select * from Win32_ComputerSystem").NumberOfProcessors
      

      problem is when I run this in Sketchup I get error

      - unknown property or method `NumberOfProcessors'
          HRESULT error code;0x80020006
            Unknown name.
      Error; #<WIN32OLERuntimeError; unknown property or method `NumberOfProcessors'
          HRESULT error code;0x80020006
            Unknown name.>
      
      

      I'm using win32ole posted here: [Plugin Library] Win32API and Win32OLE so files

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

        Is this any help?

        # Returns the number of processor for Linux, OS X or Windows.
        def number_of_processors
          if RUBY_PLATFORM =~ /linux/
            return `cat /proc/cpuinfo | grep processor | wc -l`.to_i
          elsif RUBY_PLATFORM =~ /darwin/
            return `sysctl -n hw.logicalcpu`.to_i
          elsif RUBY_PLATFORM =~ /win32/
            # this works for windows 2000 or greater
            require 'win32ole'
            wmi = WIN32OLE.connect("winmgmts;//")
            wmi.ExecQuery("select * from Win32_ComputerSystem").each do |system| 
              begin
                processors = system.NumberOfLogicalProcessors
              rescue
                processors = 0
              end
              return [system.NumberOfProcessors, processors].max
            end
          end
          raise "can't determine 'number_of_processors' for '#{RUBY_PLATFORM}'"
        end
        

        TIG

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          On Windows, an environment var is set for the number of processors:

          num = ENV['NUMBER_OF_PROCESSORS'].to_i

          I'm not here much anymore.

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

            ☀ num = ENV['NUMBER_OF_PROCESSORS'].to_i is much easier than the other way and should be fine unless you want to have a cross-platform solution... We don't know if MAC has the same ENV variable 0 - some references are similar to PC, while others can be the same ??

            TIG

            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