TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MvdP on April 20, 2010, 02:36:06 AM
-
We are in the proces of upgrading to x64 workstations.
Now is on all 32 bits stations doslib loaded in startup suite.(becasue all the same.)
Now i want to detect somehow if a workstation is running autocad 32 or 64 and load the correct arx.
-
Hi
You should find your happiness
(defun c:info(/ item meth1 meth2 process wmi)
(defun lister(val / it)
(vlax-for it val
(princ (strcat "\n" (vlax-get it 'name) " : "))
(if (vlax-get it 'value)
(princ (vlax-get it 'value))
(princ "Nil")
)
)
)
(vl-load-com)
(setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (vlax-invoke WMI 'ConnectServer nil nil nil nil nil nil nil nil))
(foreach process (list "BIOS" "Processor" "VideoController" "SoundDevice" "CDROMDrive" "OperatingSystem" "ComputerSystem" "PhysicalMemory" "DiskDrive")
(setq meth2 (vlax-invoke meth1 'ExecQuery (strcat "Select * from Win32_" Process)))
(princ (strcat "\nCaractéristiques " process " :"))
(vlax-for item meth2
(lister (vlax-get item 'Properties_))
(lister (vlax-get item 'Qualifiers_))
(getkword "\nAppuyez sur entrée pour continuer...")
)
)
(mapcar 'vlax-release-object (list meth1 meth2 wmi))
(princ)
)
@+
-
Thanks Patrick, but sorry for the misunderstanding.I modified my guestion..
-
Patrick,
Regarding your code, if you wanted to retrieve the OS Bit width directly, could you just use this:
(defun c:info (/ WMI Serv OSArch item prop)
(vl-load-com)
(setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
Serv (vlax-invoke WMI 'ConnectServer nil nil nil nil nil nil nil nil)
OSArch (vlax-invoke Serv 'ExecQuery "Select OSArchitecture from Win32_OperatingSystem"))
(vlax-for item OSArch
(vlax-for prop (vlax-get item 'Properties_)
(princ (vlax-get prop 'Value))
)
)
(mapcar 'vlax-release-object (list OSArch Serv wmi))
(princ))
-
Or, would this be enough?
(vl-string-search "X64" (strcase (getvar 'PLATFORM)))
-
(getenv "PROCESSOR_ARCHITECTURE")
-
Doslib is demand loaded ... just drag it into the app when setting up ... don't jump through unnecessary hoops.
There are several add-ons that come in several versions .. personally I'd rely on my initial setup/install to make sure ONLY the correct versions are available.
-
Patrick,
Regarding your code, if you wanted to retrieve the OS Bit width directly, could you just use this:
(defun c:info (/ WMI Serv OSArch item prop)
(vl-load-com)
(setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
Serv (vlax-invoke WMI 'ConnectServer nil nil nil nil nil nil nil nil)
OSArch (vlax-invoke Serv 'ExecQuery "Select OSArchitecture from Win32_OperatingSystem"))
(vlax-for item OSArch
(vlax-for prop (vlax-get item 'Properties_)
(princ (vlax-get prop 'Value))
)
)
(mapcar 'vlax-release-object (list OSArch Serv wmi))
(princ))
Thanks Lee
But I would also like to provide further information because it is not always easy to find
@+
-
(getenv "PROCESSOR_ARCHITECTURE")
I knew there had to be something easier... :-)
Are there only certain registry keys that can be obtained using getenv? And which are they?
-
Patrick,
Regarding your code, if you wanted to retrieve the OS Bit width directly, could you just use this:
(defun c:info (/ WMI Serv OSArch item prop)
(vl-load-com)
(setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
Serv (vlax-invoke WMI 'ConnectServer nil nil nil nil nil nil nil nil)
OSArch (vlax-invoke Serv 'ExecQuery "Select OSArchitecture from Win32_OperatingSystem"))
(vlax-for item OSArch
(vlax-for prop (vlax-get item 'Properties_)
(princ (vlax-get prop 'Value))
)
)
(mapcar 'vlax-release-object (list OSArch Serv wmi))
(princ))
Thanks Lee
But I would also like to provide further information because it is not always easy to find
@+
I was just trying to understand the code you posted - I have never used the WMI before :|
-
Patrick,
Regarding your code, if you wanted to retrieve the OS Bit width directly, could you just use this:
(defun c:info (/ WMI Serv OSArch item prop)
(vl-load-com)
(setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
Serv (vlax-invoke WMI 'ConnectServer nil nil nil nil nil nil nil nil)
OSArch (vlax-invoke Serv 'ExecQuery "Select OSArchitecture from Win32_OperatingSystem"))
(vlax-for item OSArch
(vlax-for prop (vlax-get item 'Properties_)
(princ (vlax-get prop 'Value))
)
)
(mapcar 'vlax-release-object (list OSArch Serv wmi))
(princ))
Thanks Lee
But I would also like to provide further information because it is not always easy to find
@+
I was just trying to understand the code you posted - I have never used the WMI before :|
To protect a lisp, I was asked as a question of finding the ID of the processor.
This is the method I found. And as I was, I took the opportunity to identify any.
Like this, no need to seek :D
(getenv "PROCESSOR_ARCHITECTURE")
Great, I do not know.
How to see all the "getenv" ?
@+
-
I'll share with you what I have collected for GetEnv :
;; Shows how to use expanding environment strings
;; Usage: (ExpEnvStr "%TEMP%\\MYDATA")
;; Results of sample: "C:\\DOCUME~1\\Lee\\LOCALS~1\\Temp\\MYDATA"
(defun ExpEnvStr ( strVal / wshShell)
(vl-load-com)
(setq wshShell (vlax-create-object "WScript.Shell"))
(vlax-invoke-method wshShell 'ExpandEnvironmentStrings strVal)
)
;; Retreive the value of the environment variable
;; Usage: (GetEnvStr "SYSTEM" "USERID")
(defun GetEnvStr ( strVarType strVarName / wshShell envVars)
(vl-load-com)
(setq wshShell (vlax-create-object "WScript.Shell"))
(setq envVars (vlax-get-property wshShell 'Environment strVarType))
(vlax-get-property envVars 'Item strVarName)
)
;; Set the value to an environment variable
;; Usage: (SetEnvStr "SYSTEM" "USERID" "L123")
(defun SetEnvStr ( strVarType strVarName strVarVal / wshShell envVars)
(vl-load-com)
(setq wshShell (vlax-create-object "WScript.Shell"))
(setq envVars (vlax-get-property wshShell 'Environment strVarType))
(vlax-put-property envVars 'Item strVarName strVarVal)
)
Lee, although you shell object is obviously more powerful, I have found that
you can use (getenv) to return environment variables (at least the ones you can
access through the DOS [SET] command).
For example: (strcat (getenv "temp") "\\MYDATA")
So for simply retreiving the %temp% directory, the ComputerName, the UserDomain,
etc. - (getenv) should work.
Posted by: R.K. McSwain | Friday, December 09, 2005 at 07:42 AM
GETENV does work for getting the variables, but the problem is that even though
there is a SETENV function; it can't be used to update OS environment variables.
It instead is wired to specific locations under the AutoCAD registry keys.
So if I have a variable called ALLDOCS that is defined in as a System Variable
for the OS and use SETENV to update it, SETENV writes to the Fixed Profile >>
General location under HKEY_CURRENT_USER >> Software >> Autodesk >> AutoCAD >>
(Release) >> (ProdID).
So it is for this reason that I like to use FSO for everything. From what I have
seen, there is no slow down in performance getting a variable value this way.
Now setting one is a slightly different story.
Environment Variables Listing.
Compiled and kindly donated by Stig Madsen.
Remember that environment variables are dependent on .. well, the environment, so each may or may not apply to a certain setup.
Some are almost described, some are definitely not. The first are OS dependent, the rest are AutoCAD dependent.
--------------------------------------------------------------------------------
System related
(getenv "Path") ;string System search paths
(getenv "COMSPEC") ;string Cmd.exe path
(getenv "UserName");string User logon name
(getenv "Temp") ;string Temp path
(getenv "TMP") ;string Temp path
(getenv "ComputerName");string Computer name
(getenv "Windir") ;string Windows path
(getenv "OS") ;string Operating system
(getenv "UserProfile");string Current user profile path
(getenv "Pathext") ;string Exec extensions
(getenv "SystemDrive");string System drive
(getenv "SystemRoot");string System root path
(getenv "MaxArray");integer
--------------------------------------------------------------------------------
General
(getenv "ACAD") ;string Support search paths
(getenv "ANSIHatch");string Pattern file for ANSI setup 1)
(getenv "ANSILinetype");string Linetype file for ANSI setup 1)
(getenv "ISOHatch");string Pattern file for ISO setup 1)
(getenv "ISOLinetype");string Linetype file for ISO setup 1)
(getenv "StartUpType");string Current default for StartUp dialog
(getenv "acet-MenuLoad");string Loading of Express Tools menu
(getenv "Measureinit");string MEASUREINIT
(getenv "InsertUnitsDefSource");integer INSUNITSDEFSOURCE
(getenv "InsertUnitsDefTarget");integer INSUNITSDEFTARGET
(getenv "acet-Enable");string
(getenv "LastTemplate");string Last DWT used
(getenv "AcetRText:type");string Current default for RTEXT "Diesel"
(getenv "Pickstyle");integer
(getenv "Coords") ;integer
(getenv "ShowProxyDialog");integer
(getenv "Osmode") ;integer
(getenv "EdgeMode");integer
(getenv "PAPERUPDATE");integer
(getenv "ACADPLCMD");string Plotter command string
(getenv "ImageHighlight");integer
(getenv "Attdia") ;integer
(getenv "Attreq") ;integer
(getenv "Delobj") ;integer
(getenv "Dragmode");integer
(getenv "UseMRUConfig");integer
(getenv "PLSPOOLALERT");integer
(getenv "PLOTLEGACY");integer
(getenv "PSTYLEPOLICY");integer
(getenv "OLEQUALITY");integer
(getenv "Anyport") ;integer
(getenv "Validation Policy");integer
(getenv "Validation Strategy");integer
(getenv "CommandDialogs");integer CMDDIA
(getenv "TempDirectory");string Temp dir
(getenv "PlotSpoolerDirectory");string Spooler dir
(getenv "DefaultLoginName");string Default login
(getenv "MenuFile");string Default menu path
(getenv "NetLocation");string Default URL
(getenv "ACADDRV") ;string Driver path
(getenv "ACADHELP");string Help path
(getenv "PrinterConfigDir");string Plotter path
(getenv "PrinterStyleSheetDir");string Plot styles path
(getenv "PrinterDescDir");string Plotter driver path
(getenv "NewStyleSheet");string Default .stb/.ctb file
(getenv "DefaultFormatForSave");integer Default saveas
(getenv "DefaultConfig");string Default pc3
(getenv "LastModifiedConfig");string Last pc3
(getenv "MRUConfig");string pc3?
(getenv "ACADLOGFILE");string Logfile
(getenv "MaxDwg") ;integer
(getenv "AVEMAPS") ;string Texture files path
(getenv "TemplatePath");string Templates path
(getenv "DatabaseWorkSpacePath");string Data Links path
(getenv "DefaultPlotStyle");string e.g. "ByLayer"
(getenv "DefaultLayerZeroPlotStyle");string e.g."Normal"
(getenv "LineWeightUnits");integer
(getenv "LWDEFAULT");integer Default lineweight
(getenv "CustomColors");integer
(getenv "Blipmode");integer
(getenv "ToolTips");string
1) used by MEASUREINIT and MEASUREMENT sysvars
--------------------------------------------------------------------------------
Editor Configuration
(getenv "SDF_AttributeExtractTemplateFile");string ??
(getenv "AutoSnapPolarAng");string POLARANG
(getenv "AutoSnapPolarDistance");string POLARDIST
(getenv "AutoSnapPolarAddAng");string POLARADDANG
(getenv "AutoSnapControl");integer AUTOSNAP
(getenv "AutoSnapTrackPath");integer TRACKPATH
(getenv "PickBox") ;integer PICKBOX
(getenv "AutoSnapSize");integer
(getenv "PickFirst");integer PICKFIRST
(getenv "PickAuto");integer PICKAUTO
(getenv "MenuOptionFlags");integer MENUCTL
(getenv "FontMappingFile");string
(getenv "LogFilePath");string
(getenv "PSOUT_PrologFileName");string
(getenv "MainDictionary");string
(getenv "CustomDictionary");string
(getenv "MTextEditor");string
(getenv "XrefLoadPath");string
(getenv "SaveFilePath");string
(getenv "AcadLspAsDoc");string
--------------------------------------------------------------------------------
Drawing Window
(getenv "Background");integer Background color
(getenv "Layout background");integer PS Background color
(getenv "XhairPickboxEtc");integer Crosshair color
(getenv "LayoutXhairPickboxEtc");integer PS Crosshair color
(getenv "Autotracking vector");integer Autotracking vector color
(getenv "MonoVectors");integer
(getenv "FontFace");string Screen Menu
(getenv "FontHeight");integer
(getenv "FontWeight");integer
(getenv "FontItalic");integer
(getenv "FontPitchAndFamily");integer
(getenv "CursorSize");integer
(getenv "HideWarningDialogs");integer:00000008 <- hit
(getenv "ScreenMenu") ; interger, 1 turns it on;
(getenv "SDIMode") ;integer:00000000 <- hit
--------------------------------------------------------------------------------
Command Line Windows
(getenv "CmdLine.ForeColor");integer
(getenv "CmdLine.BackColor");integer
(getenv "TextWindow.ForeColor");integert
(getenv "TextWindow.BackColor");integer
(getenv "CmdLine.FontFace");string
(getenv "CmdLine.FontHeight");integer
(getenv "CmdLine.FontWeight");integer
(getenv "CmdLine.FontItalic");integer
(getenv "CmdLine.FontPitchAndFamily");integer
(getenv "TextWindow.FontFace");string
(getenv "TextWindow.FontHeight");integer
(getenv "TextWindow.FontWeight");integer
(getenv "TextWindow.FontItalic");integer
(getenv "TextWindow.FontPitchAndFamily");integer
-
Thanks Alan, appreciated. :-)
-
Found this on the Autodesk discussion groups.
(defun ISX64 (/ proc_arch)
(and
(setq proc_arch (getenv "PROCESSOR_ARCHITECTURE"))
(< 1 (strlen proc_arch))
(eq "64" (substr proc_arch (1- (strlen proc_arch))))
)
)
;; determine whether appropriate version of DOSLib is already loaded.
;; if not, try to load it.
(setvar "cmdecho" 0)
(setq CADver (substr (getvar "acadver") 1 2)) ;; i.e., "17", "18", etc.
(setq arxlist (arx))
(if (isX64)
(setq DOSLibname (strcat "doslib" CADver "x64.arx"))
(setq DOSLibname (strcat "doslib" CADver ".arx"))
)
(foreach a arxlist (if (equal a DOSLibname) (setq loadedAtStartup T) ))
(if (not loadedAtStartup)
(vl-cmdf "._arx" "_load" (findfile DOSLibname))
)
;; verify that load was successful.
;; if not, quit.
(setq arxlist (arx))
(foreach a arxlist (if (equal a DOSLibname) (setq loadedAtRuntime T) ))
(if (not loadedAtRuntime)
(progn
(prompt "Sorry - DOSLib is not loaded and cannot be found in the
AutoCAD search path.")
(vlr-beep-reaction)
(quit)
(setvar "cmdecho" 1)
)
)
http://discussion.autodesk.com/forums/thread.jspa?messageID=6347941� (http://discussion.autodesk.com/forums/thread.jspa?messageID=6347941�)
-
Thanks Cab :-)
@+
-
My 5 cents
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.
(defun Acad64Bit-version ()
;;; Get from http://forum.dwg.ru/showthread.php?t=31568
;;;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.
(vl-load-com)
(> (strlen (vl-prin1-to-string (vlax-get-acad-object))) 40)
)
-
Just to add to what others and I have already provided ...
These should work in theory, but as I'm not running 64 bit here -- no can test. Would be great if some 64 bit folks could test and report success/fail. Thanks in advance.
*Not better <hard to improve upon (getenv "PROCESSOR_ARCHITECTURE")>, just another way to skin the cat.*
(defun _Is64Bit ( / wmiLocater wmiService queryResult result )
;;========================================================================
;;
;; 2010/04/23 | Quick & Dirty | Michael Puckett
;;
;;========================================================================
(vl-catch-all-apply
'(lambda ( )
(vlax-for item
(setq queryResult
(vlax-invoke
(setq
wmiLocater (vlax-create-object "WbemScripting.SWbemLocator")
wmiService (vlax-invoke wmiLocater 'ConnectServer "." "root\\cimv2")
)
'ExecQuery
(strcat
"Select * "
"from Win32_Processor "
)
)
)
(setq result (vlax-get item 'Description))
)
)
)
(if queryResult (vlax-release-object queryResult))
(if wmiService (vlax-release-object wmiService))
(if wmiLocater (vlax-release-object wmiLocater))
(if result (wcmatch result "*64*"))
)
(defun _Is64Bit ( / wmiLocater wmiService queryResult result )
;;========================================================================
;;
;; 2010/04/23 | Quick & Dirty | Michael Puckett
;;
;;========================================================================
(vl-catch-all-apply
'(lambda ( )
(vlax-for item
(setq queryResult
(vlax-invoke
(setq
wmiLocater (vlax-create-object "WbemScripting.SWbemLocator")
wmiService (vlax-invoke wmiLocater 'ConnectServer "." "root\\cimv2")
)
'ExecQuery
(strcat
"Select * "
"from Win32_Processor "
)
)
)
(setq result (vlax-get item 'Architecture))
)
)
)
(if queryResult (vlax-release-object queryResult))
(if wmiService (vlax-release-object wmiService))
(if wmiLocater (vlax-release-object wmiLocater))
(if result (eq 9 result))
)
Edit: Fixed glaring typo.
-
All I have time for right now; have a meeting this afternoon.
Windows 7 x64
AutoCAD MEP 208 x32
Command:
Command: (getenv "PROCESSOR_ARCHITECTURE")
"x86"
Command: (defun _Is64Bit ( / wmiLocater wmiService queryResult result )
(_>
(_>
;;========================================================================
(_> ;;
(_> ;; 2010/04/23 | Quick & Dirty | Michael Puckett
(_> ;;
(_>
;;========================================================================
(_>
(_> (vl-catch-all-apply
((_> '(lambda ( )
(('(_> (vlax-for item
(('((_> (setq queryResult
(('(((_> (vlax-invoke
(('((((_> (setq
(('(((((_> wmiLocater (vlax-create-object
"WbemScripting.SWbemLocator")
(('(((((_> wmiService (vlax-invoke wmiLocater
'ConnectServer "." "root\\cimv2")
(('(((((_> )
(('((((_> 'ExecQuery
(('((((_> (strcat
(('(((((_> "Select * "
(('(((((_> "from Win32_Processor "
(('(((((_> )
(('((((_> )
(('(((_> )
(('((_> (setq result (vlax-get item 'Description))
(('((_> )
(('(_> )
((_> )
(_>
(_> (if queryResult (vlax-release-object queryResult))
(_> (if wmiService (vlax-release-object wmiService))
(_> (if wmiLocater (vlax-release-object wmiLocater))
(_>
(_> (if result (wcmatch result "*64*"))
(_>
(_> )
_IS64BIT
Command: (_is64bit)
T
Command: (defun _Is64Bit ( / wmiLocater wmiService queryResult result )
(_>
(_>
;;========================================================================
(_> ;;
(_> ;; 2010/04/23 | Quick & Dirty | Michael Puckett
(_> ;;
(_>
;;========================================================================
(_>
(_> (vl-catch-all-apply
((_> '(lambda ( )
(('(_> (vlax-for item
(('((_> (setq queryResult
(('(((_> (vlax-invoke
(('((((_> (setq
(('(((((_> wmiLocater (vlax-create-object
"WbemScripting.SWbemLocator")
(('(((((_> wmiService (vlax-invoke wmiLocater
'ConnectServer "." "root\\cimv2")
(('(((((_> )
(('((((_> 'ExecQuery
(('((((_> (strcat
(('(((((_> "Select * "
(('(((((_> "from Win32_Processor "
(('(((((_> )
(('((((_> )
(('(((_> )
(('((_> (setq result (vlax-get item 'Architure))
(('((_> )
(('(_> )
((_> )
(_>
(_> (if queryResult (vlax-release-object queryResult))
(_> (if wmiService (vlax-release-object wmiService))
(_> (if wmiLocater (vlax-release-object wmiLocater))
(_>
(_> (if result (eq 9 result))
(_>
(_> )
_IS64BIT
Command: (_is64bit)
nil
-
GAAA. F*****G LAME TYPING SKILLS.
The property should be 'Architecture, not 'Architure (epic facepalm).
Try this --
(defun _Is64Bit ( / wmiLocater wmiService queryResult result )
;;========================================================================
;;
;; 2010/04/23 | Quick & Dirty | Michael Puckett
;;
;;========================================================================
(vl-catch-all-apply
'(lambda ( )
(vlax-for item
(setq queryResult
(vlax-invoke
(setq
wmiLocater (vlax-create-object "WbemScripting.SWbemLocator")
wmiService (vlax-invoke wmiLocater 'ConnectServer "." "root\\cimv2")
)
'ExecQuery
(strcat
"Select * "
"from Win32_Processor "
)
)
)
(setq result (vlax-get item 'Architecture))
)
)
)
(if queryResult (vlax-release-object queryResult))
(if wmiService (vlax-release-object wmiService))
(if wmiLocater (vlax-release-object wmiLocater))
(if result (eq 9 result))
)
-
Both _Is64Bit functions return T on my 64 bit Win 7 computer. I added a function that ran (Print (_Is64Bit)) on each. It took almost 3 seconds to run on an Intel E8400 at 3GHz. (getenv "PROCESSOR_ARCHITECTURE") returns "AMD64".
-
3 seconds to execute (_Is64Bit)? Good gief that's horrible. Subtitle: Aside from possible academic value what I posted is worthless. DO NOT USE!
-
PS: thx for trying. :)
PS2: forgive 'gief' typo in preceding post - no can edit from blackberry.
-
The operating system isn't something that changes on a day-to-day basis, so if the value is needed a simple set and forget user registry entry could be used to store the value. The registry entry can then be checked when the 32/64 bit value is needed and if missing, query the user via a dialog or silently via other settings (even if it takes several seconds its a one-time deal).
-
PS2: forgive 'gief' typo in preceding post - no can edit from blackberry.
Eehhh Phone is not so smart as it thinks it is? Or is is the operator? :evil: :roll:
-
just putting some info...
(vl-registry-descendents "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node")
-
Doslib is not the only arx i want to load .Is it possible to add
Idwgtab
Periscope
Quikpik
to this code.?
(defun ISX64 (/ proc_arch)
(and
(setq proc_arch (getenv "PROCESSOR_ARCHITECTURE"))
(< 1 (strlen proc_arch))
(eq "64" (substr proc_arch (1- (strlen proc_arch))))
)
)
;; determine whether appropriate version of DOSLib is already loaded.
;; if not, try to load it.
(setvar "cmdecho" 0)
(setq CADver (substr (getvar "acadver") 1 2)) ;; i.e., "17", "18", etc.
(setq arxlist (arx))
(if (isX64)
(setq DOSLibname (strcat "doslib" CADver "x64.arx"))
(setq DOSLibname (strcat "doslib" CADver ".arx"))
)
(foreach a arxlist (if (equal a DOSLibname) (setq loadedAtStartup T) ))
(if (not loadedAtStartup)
(vl-cmdf "._arx" "_load" (findfile DOSLibname))
)
;; verify that load was successful.
;; if not, quit.
(setq arxlist (arx))
(foreach a arxlist (if (equal a DOSLibname) (setq loadedAtRuntime T) ))
(if (not loadedAtRuntime)
(progn
(prompt "Sorry - DOSLib is not loaded and cannot be found in the
AutoCAD search path.")
(vlr-beep-reaction)
(quit)
(setvar "cmdecho" 1)
)
)