Author Topic: User System Variables  (Read 159 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 465
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: 1799
  • 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

  • Newt
  • Posts: 56
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

  • Bull Frog
  • Posts: 471
  • 30 + 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: 17662
  • Have thousands of dwgs to process? Contact me.
Engineering Technologist CAD Specialist Programmer Analyst
Design Drafting Document Control Automation.
cadanalyst@fastmail.com https://cadanalyst.slack.com http://linkedin.com/in/cadanalyst