;;;some functions to make it easier to deal with data dictionaries in AutoLISP ;;;© 2001 Herman Mayfarth ;;;no warranty, express or implied. use at your own risk. ;;;Date this file: 15 April 2001 ;;;external functions: mcdrs mcdrsread ;;;load the file mcdrs.lsp to load the above functions ;;;this file is considered work in progress by its author ;;;but you are welcome to use it for any purpose ;;;getNOD ;;;get Entity Association List for master dictionary record (defun getNOD () (entget(namedobjdict))) ;;;listNOD ;;;get a list of names of all items in the named object dictionary (defun listNOD () (mcdrs 3 (getNOD)) ) ;;;dictent ;;;get entity name for a dictionary named dstring ;;;this is very limited - dictionaries can live inside ;;;other dictionaries (defun dictent (dstring / nodlst OK) (setq nodlst (getnod)) (if (setq OK (assoc (read dstring) (mcdrsread 3 nodlst))) (cdr (nth (cadr OK) nodlst)) ) ) ;;;dictget ;;;get EAL for a dictionary named dstring (defun dictget (dstring / OK) (if (setq OK (dictent dstring)) (entget OK) nil ) ) ;;;dictitems ;;;get list of records in a dictionary (defun dictitems (dstring) (mcdrs 3 (dictget dstring)) ) ;;;dictmake ;;;make an empty top-level dictionary (defun dictmake (dictname /) (if (null(dictsearch (namedobjdict) dictname)) (dictadd (namedobjdict) dictname (entmakex '((0 . "DICTIONARY") (100 . "AcDbDictionary")))) ) ) ;;;make a new dictionary in existing 1st level dictionary (defun dictmakex (dictname newdict / dict) (if (setq dict (cdr (assoc -1 (dictsearch (namedobjdict) dictname)))) (dictadd dict newdict (entmakex '((0 . "DICTIONARY") (100 . "AcDbDictionary")))) ) ) (defun dxf (code ent) (cdr (assoc code (entget ent)))) (defun etype (ename) (cdr (assoc 0 (entget ename))) ) ;;;dictlist ;;;return an association list of all dictionaries in a dictionary ;;;and their enames, ("NAME1" . "NAME2" . ...) ;;;top level call: (dictlist (namedobjdict)) (defun dictlist ( ename / nodlst 3list ret val) ;;first get the contents of the dictionary (setq nodlst (entget ename) 3list (mcdrpos 3 nodlst) ) ;;;step through the list & determine if each entity is a dictionary ;;;if so, add it to a return list (foreach n 3list (if (= "DICTIONARY" (etype (setq val (cdr (nth (cadr n) nodlst))))) (setq ret (cons (cons (car n) val) ret)) ) ) ret );dictlist