TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mailmaverick on July 28, 2020, 04:44:52 AM
-
Refer this documentation :-
https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-Core/files/GUID-BDC0BB08-FCDD-4E4F-AC3F-407696911F8B-htm.html (https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-Core/files/GUID-BDC0BB08-FCDD-4E4F-AC3F-407696911F8B-htm.html)
There are 5 User System Variables USERI1, USER2, USER3, USER4 and USER5 which provide storage and retrieval of integer values.
Is there any system variables providing storage of REAL, STRING or LIST values ? If not, shouldn't this be a very basic functionality provided by AutoCAD ?
-
I would personally advise against using USERI1 etc.
But USERR1-USERR5 and USERS1-USERS5 also exist.
Note that USERS1-USERS5 values will not get saved.
There are better ways to store data in a DWG: Xdata and dictionaries.
-
I would personally advise against using USERI1 etc.There are better ways to store data
My solution, is push/pop in/from kHomeRegistry. How to storeList in kHomeRegistry?
http://lisp2arx.3xforum.ro/post/141/vla-AutoLispR4-Top_GetInt_with_Save_and_Restore_in_all_drawings/ (http://lisp2arx.3xforum.ro/post/141/vla-AutoLispR4-Top_GetInt_with_Save_and_Restore_in_all_drawings/)
:smitten:
How to save and restore LIST (many values-types)?
1)One solution convert list to STR with (vl-princ-to-string your-list)
2)Two solution ???
-
I think I got this from Afralisp and customised to suit my task.
(defun get-or-create-Dict (/ adict)
;;test if "BIGAL" is already present in the main dictionary
(if (not (setq adict (dictsearch (namedobjdict) "BIGAL")))
;;if not present then create a new one and set the main
;; dictionary as owner
(progn
(setq adict (entmakex '((0 . "DICTIONARY")(100 . "AcDbDictionary"))))
;;if succesfully created, add it to the main dictionary
(if adict (setq adict (dictadd (namedobjdict) "BIGAL" adict)))
)
;;if present then just return its entity name
(setq adict (cdr (assoc -1 adict)))
)
)
(defun get-or-make-Xrecord (wallvar wallsize / adict anXrec)
; change to allow w1 etc and thickness
(cond
;;first get our dictionary. Notice that "BIGAL" will be
;;created here in case it doesn't exist
((setq adict (get-or-create-Dict))
(cond
;;if "BIGAL" is now valid then look for "BIGALVARS" Xrecord
((not (setq anXrec (dictsearch adict wallvar)))
;the variable BIGALvars is name of xrecord so need to be a variable to add lots
;;if "BIGALVARS" was not found then create it
;(setq anXrec (entmakex '((0 . "XRECORD")
(setq anXrec (entmakex (list (cons 0 "XRECORD")
(cons 100 "AcDbXrecord")
;(1 . wallvar)
(cons 1 wallvar)
(cons 40 wallsize)
;(40 . wallsize)
)
)
)
;;if creation succeeded then add it to our dictionary
(if anXrec (setq anXrec (dictadd adict wallvar anXrec)))
)
;;if it's already present then just return its entity name
(setq anXrec
(cdr (assoc -1 (dictsearch adict wallvar)))
)
)
)
)
)
(defun getBIGALvars (/ vars varlist)
;;retrieve XRecord "wallvar" from dictionary "BIGAL"
;;which in turn calls both functions above
(setq vars (get-or-make-Xrecord))
;;if our Xrecord is found, then get values in group code
(cond (vars
(setq varlist (entget vars))
(setq WALLname (cdr (assoc 1 varlist)))
(setq WALLTHICK (cdr (assoc 40 varlist)))
)
;;otherwise return nil
(T nil)
)
)
-
Very close to something I wrote ... hmmm ... carry the 2 ... 15 years ago. (http://www.theswamp.org/index.php?topic=5003.msg60453;topicseen#msg60453) :lol:
-
Hello
I Use Environments to save and get everything I need in AutoCAD and between drawings.
Also all the registration keys are also saved in environments to activate lisp softwares you buy.
use : Setenv and Getenv !!!!
-
The problem with hammers is that everything looks like a nail.
-
Open the dwg on another PC and get setenv will fail writes to the pc registery.
from Autodesk
variable-name
Type: String
A string specifying the name of the variable to be read. Environment variable names must be spelled and cased exactly as they are stored in the system registry.
-
Hi,
I know vl-registry-write LISP function cannot access to LOCAL_MACHINE, anyway I think it's good to know you can create your own system variable wich work the same as native ones.
From the .NET documentation (https://help.autodesk.com/view/OARX/2019/ENU/?guid=OREFNET-Autodesk_AutoCAD_Runtime_Variable):
Variables are created by declaring them in the registry.
The following format should be used (elements between {} should be replaced with a legal value for the property or type indicated inside the {}).
[HKEY_LOCAL_MACHINE{ProductRegistryRoot}Variables{Variable.Name()}]
@="{default value}" : Required, will be converted to PrimaryDataType
"PrimaryType" = dword:{Variable.PrimaryType()} : Required
"SecondaryType" = dword:{Variable.SecondaryType()} : Optional
"TypeFlags" = dword:{Variable.TypeFlags()} : Optional
"StorageType" = dword:{Variable.StorageType} : Required
"Range" = "{lowerbound},{upperbound}" : Optional, applies to RTREAL, RTANG, RTSHORT and RTLONG primary types
Note these variables can be get/set using getvar/setvar LISP functions in AutoCAD. They are also visible to the SETVAR command.
PrimaryType allowed values:
RTREAL = 5001
RTSHORT = 5003
RTSTR = 5005
RTLONG = 5010
SecondaryType allowed values:
None = 0
Boolean = 1
SymbolName = 2
Area = 3
Distance = 4
Angle = 5
Last = 6
UnitlessReal = 6
TypeFlags allowed values:
None = 0
SpacesAllowed = 1
DotMeansEmpty = 2
NoUndo = 4
Chatty = 8
StorageType allowed values:
PerSession = 0
PerUser = 1
PerProfile = 2
PerDatabase = 3
PerViewport = 4