Reputation: 155
I have recently started writing scripts for AUTOCAD. I want to do the following:
Suppose,I place my script in the current location. In current location,I have several folders. Each folder in turn contain many folders,which again contain some drawing files (of type .DWG and .DWT). I want to loop through each of the folder and get a list containing only .DWT files.
Now,I want to loop through each of the .DWT file and open the file in AUTOCAD, change the value of the parameter "DELOBJ" to 1 (say) and finally save,close the document.
Can we do it with normal SCR Scripting (or) can we do it using LISP Command? I would be really glad,if someone can help me in this context
Thanks in advance.
Upvotes: 0
Views: 2388
Reputation: 99
You would be able to pull the value from registry with this code.
(vl-registry-read (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (vla-get-ActiveProfile (vla-get-profiles (vla-get-preferences (vlax-get-Acad-Object)))) "\\General") "Delobj")
Check if its not 1 and then use vl-registry-write
Upvotes: 0
Reputation: 1195
The 'DELOBJ' Systemvariable is saved in the registry, so it has nothing to do with any documents... (indeed, some Sysvars are saved in Documents, but if you only need focus on this...)
refer: ADSK Knowledge Network
So you set it once per profile (a simple .reg file would be enough)
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\[Release]\[Product]\Profiles\[Profile]]
"Delobj"=dword:00000001
Upvotes: 0
Reputation: 1697
Today I don't have enought time to prepare full sample (sorry) but let's start with:
Get the list of all *.DWT files. You may do it like this:
(defun CMD::Dir ( pattern / Shell Dirinf Outbuf CmdVal)
(setq cmd (strcat "%comspec% /C dir /S /B " pattern ) )
(print cmd )
(setq Shell (vlax-get-or-create-object "Wscript.Shell"))
(setq Dirinf(vlax-invoke-method Shell 'Exec cmd ))
(setq Outbuf(vlax-get-property Dirinf 'StdOut ))
( while (= :vlax-false (vlax-get-property Outbuf 'AtEndOfStream ) )
(setq CmdVal (append CmdVal (list (vlax-invoke-method Outbuf 'ReadLine ) ) ) )
)
(vlax-release-object Shell)
CmdVal
)
(setq files (CMD::Dir "**YourPath**\\*.dwt" ) )
then using (foreach file files .. )
open each drawing, and set value of DELOBJ
. But remember, that LISP context is only in active drawing, so You can't use (setvar 'DELOBJ 1)
Probably you may to do it by vlax. but this is the time, when I can not help You now. When I have sample I will update.
Upvotes: 0