Persisting User Preferences Across Sessions via vl-registry-* & Lightweight JSON Parsers in AutoLISP (dev-cookbook-29)
Store per-user UI settings in the Windows Registry, Drawing Dictionaries (vlax-ldata-put), and external JSON config files in GstarCAD 2027 AutoLISP.
1. Choosing the Right Persistence Tier in GstarCAD 2027 AutoLISP
When designing enterprise AutoLISP tools for GstarCAD 2027, configuration data falls into three distinct lifecycle scopes, each served by a dedicated persistence mechanism:
| Persistence Tier | Visual LISP API / Mechanism | Ideal Engineering Use Case |
|---|---|---|
| 1. Per-Workstation User Profile | vl-registry-write / getenv / setenv |
Remembering a drafter's last-used dialog checkboxes, default duct velocity, or preferred CSV export folder across restarts. |
| 2. Inside the `.DWG` Binary File | vlax-ldata-put / vlax-ldata-get |
Storing project-specific datum elevations, structural wind zone codes, or revision history directly inside the `.dwg` Named Object Dictionary so it travels with the file. |
| 3. Enterprise Shared Network Config | JSON / INI file on UNC Share | Centralized discipline layer mappings, ERP material lookup codes, and standard title-block attribute schemas managed under Git version control. |
2. Production AutoLISP: Registry Preferences & Embedded `.DWG` LData Storage
The module below demonstrates how to combine per-user Windows Registry preferences (`HKEY_CURRENT_USER\Software\Gstarsoft\CorpTools\v2027`) with document-embedded `vlax-ldata-*` dictionaries that persist inside the AC1032 `.dwg` file across external email/CDE transfers:
;; CorpConfigManager.lsp - Registry User Prefs + DWG Embedded LData Dictionary
(vl-load-com)
(setq *CORP_REG_KEY* "HKEY_CURRENT_USER\Software\Gstarsoft\CorpBimTools\2027")
(setq *CORP_LDATA_DICT* "GSTAR_CORP_PROJECT_META")
;; Read user preference from HKCU Registry with fallback default value
(defun Corp:GetUserPref (valName defaultVal / raw)
(setq raw (vl-registry-read *CORP_REG_KEY* valName))
(if raw raw defaultVal)
)
;; Save user preference to HKCU Registry
(defun Corp:SetUserPref (valName valData)
(vl-registry-write *CORP_REG_KEY* valName valData)
)
;; Embed structured association list directly inside the active .DWG binary database
(defun Corp:SaveProjectMetaToDwg (assocList)
(vlax-ldata-put *CORP_LDATA_DICT* "ProjectSpec" assocList)
(princ "
[CorpConfig] Embedded project metadata into DWG Named Object Dictionary.")
)
;; Retrieve structured association list from the active .DWG database
(defun Corp:LoadProjectMetaFromDwg ( / data)
(setq data (vlax-ldata-get *CORP_LDATA_DICT* "ProjectSpec"))
(if data
data
'(("PROJECT_CODE" . "UNASSIGNED")
("SEISMIC_ZONE" . "PGA_0.20g")
("DESIGN_STD" . "ISO_19650_2027"))
)
)
3. Parsing External JSON Configs via `Msxml2` / JScript or Native Tokenizer
Because `vlax-ldata-put` natively serializes nested LISP association lists (`'((key . val) ...)`), numbers, strings, and 3D points without requiring any string parsing, many CAD Managers distribute shared network configuration files as `.lsp` data files (`CorpCatalog.dat`) loaded via `(read (read-line fp))`—which GstarCAD's C++ LISP reader parses into memory in under **0.4 milliseconds** for 5,000 catalog items.
4. Inspecting and Purging Custom `vlax-ldata-*` Dictionaries
Because `vlax-ldata-put` stores binary records inside the DWG's Named Object Dictionary (`NOD`), you can list all keys under your company dictionary at any time using `(vlax-ldata-list "GSTAR_CORP_PROJECT_META")` or delete obsolete keys via `(vlax-ldata-delete "GSTAR_CORP_PROJECT_META" "OldKey")`.
Unlike Extended Entity Data (`XDATA`)—which enforces a legacy 16 KB size limit per entity—Named Object Dictionary `LData` entries in GstarCAD 2027 have no 16 KB ceiling, making them ideal for storing full JSON string payloads or multi-hundred-row revision audit trails inside the `.dwg` container.
Validate This Workflow in GstarCAD 2027
Engineered by Suzhou Gstarsoft Co., Ltd. (SSE: 688657), GstarCAD 2027 delivers 100% native AC1032 DWG binary fidelity, perpetual licensing sovereignty, and zero-day AutoCAD command parity.