Author Topic: User System Variables  (Read 2646 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 494
User System Variables
« 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

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 ?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: User System Variables
« Reply #1 on: July 28, 2020, 05:23:20 AM »
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.

d2010

  • Bull Frog
  • Posts: 323
Re: User System Variables
« Reply #2 on: July 28, 2020, 09:42:08 AM »
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/
 :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 ???
« Last Edit: July 29, 2020, 02:35:46 AM by d2010 »

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: User System Variables
« Reply #3 on: July 28, 2020, 08:57:16 PM »
I think I got this from Afralisp and customised to suit my task.

Code: [Select]
(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)
  )
)
A man who never made a mistake never made anything

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ahsattarian

  • Newt
  • Posts: 112
Re: User System Variables
« Reply #5 on: November 17, 2020, 10:01:47 AM »
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    !!!!     

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2125
  • class keyThumper<T>:ILazy<T>
Re: User System Variables
« Reply #6 on: November 17, 2020, 03:30:17 PM »
The problem with hammers is that everything looks like a nail.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: User System Variables
« Reply #7 on: November 18, 2020, 03:16:43 AM »
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.
A man who never made a mistake never made anything

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: User System Variables
« Reply #8 on: November 22, 2020, 03:11:08 AM »
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:
Code: [Select]
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
Speaking English as a French Frog