SketchUcation Premium Membership

 

 

Number of processors

Number of processors

Postby maricanis » Tue Jul 03, 2012 9:54 am

Hi,

Is there a way to get number of processors with Ruby in Sketchup.
I've found on internet solutions like this
Code: Select all
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
Code: Select all
- 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
maricanis
 
Posts: 12
Joined: Fri Jun 26, 2009 10:20 am
Name: maricanis

Re: Number of processors

Postby TIG » Tue Jul 03, 2012 10:20 am

Is this any help?
Code: Select all
# 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
User avatar
TIG
Global Moderator
 
Posts: 14310
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Number of processors

Postby Dan Rathbun » Tue Jul 03, 2012 12:42 pm

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

num = ENV['NUMBER_OF_PROCESSORS'].to_i
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4146
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: Number of processors

Postby TIG » Tue Jul 03, 2012 2:50 pm

:enlight: 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
User avatar
TIG
Global Moderator
 
Posts: 14310
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Need Authorised SketchUp Training by experts in various disciplines? Check out our Training details.

Ad Machine
Robot
 
Posts: 2012


Return to Developers' Forum

Who is online

Users browsing this forum: Bing [Bot] and 4 guests