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)
)
)