Thursday, April 19, 2007

Determine programmatically if AutoCAD 2008 is 32-bit or 64-bit

Here are some alternative ways that can help you know if AutoCAD 2008 or another AutoCAD version is 32-bit or 64-bit as well as what the platform is.
Why would you want to do this? One reason is that DOSLib 7.5 has separate ARX files for 32 and 64 bit and you might want to check this using AutoLISP before loading DOSLib if you have users with different OS's.
The system variable PLATFORM might also be used. It indicates which platform is in use. The result can be something like: "Microsoft Windows NT Version 6.0 (x86)"
Windows Environment variable PROCESSOR_ARCHITECTURE is x86 for 32-bit and x64 for 64-bit.
vlax-get-acad-object in 64-bit return a longer object ID number than in the 32-bit so the function Acad64Bit-version will return T if AutoCAD is a 64-bit version.
Acad64Bit-platform will return T if the Windows OS platform is 64-bit.

(defun Acad64Bit-version () (vl-load-com) (> (strlen (vl-prin1-to-string (vlax-get-acad-object))) 40) ) (defun Acad64Bit-platform () (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE")) )

You can call the above like this:

(princ (if (Acad64Bit-version) "AutoCAD 64-bit, " "AutoCAD 64-bit, "))
(princ (if (Acad64Bit-platform) "Windows 64-bit" "Windows 32-bit"))

3 comments:

  1. Restored comments

    R.K. McSwain said...

    Your first function works on my 64-bit machine. The second one doesn't because of the return value of my "PROCESSOR_ARCHITECTURE" variable.


    Command: (acad64bit-version)
    T
    Command: (acad64bit-platform)
    nil
    Command: (getenv "PROCESSOR_ARCHITECTURE")
    "AMD64"


    Obviously, the following would work

    (defun Acad64Bit-platform ()
    (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64")
    )
    -- but who knows what other values may be returned by (getenv "PROCESSOR_ARCHITECTURE") on various systems...
    April 19, 2007
    Matt Mason said...

    Doesn't this just determine whether your machine is 64-bit, rather than which version of AutoCAD you're running (it's possible to run 32-bit AutoCAD on a 64-bit machine).

    (sorry I don't have a solution yet, either).
    April 19, 2007
    Anonymous said...

    You cannot run AutoCAD 32bit on a 64bit OS.
    May 14, 2008

    ReplyDelete
  2. To Anonymous above;
    What you say may be true, but the statement by Matt Mason you're commenting to talked about a 64-bit "machine" (cpu), not OS. A 64-bit processor can, in fact, run a 32-bit OS.

    ReplyDelete
  3. On the topic I found this blog post
    http://blogs.msdn.com/david.wang/archive/2006/03/26/HOWTO-Detect-Process-Bitness.aspx

    The general idea is to check the following environment variables:

    PROCESSOR_ARCHITECTURE - reports the native processor architecture EXCEPT for WOW64, where it reports x86.
    PROCESSOR_ARCHITEW6432 - not used EXCEPT for WOW64, where it reports the original native processor architecture.

    One thing that was strange when I looked on my Turion 64 X2 running Windows 7 32-bit is that PROCESSOR_ARCHITECTURE reports x86 when the OS is 32-bit. So PROCESSOR_ARCHITECTURE seem to report on the OS and not on the actual processor.

    ReplyDelete