另一个例子可能有用
- (defun get-or-create-Dict (/ adict)
- ;;test if "MyDict" is already present in the main dictionary
- (if (not (setq adict (dictsearch (namedobjdict) "MyDict")))
- ;;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) "MyDict" adict)))
- )
- ;;if present then just return its entity name
- (setq adict (cdr (assoc -1 adict)))
- )
- )
- (defun get-or-make-Xrecord (/ adict anXrec)
- ; change to allow w1 etc and thickness
- (cond
- ;;first get our dictionary. Notice that "MyDict" will be
- ;;created here in case it doesn't exist
- ((setq adict (get-or-create-Dict))
- (cond
- ;;if "MyDict" is now valid then look for "MyDictVARS" Xrecord
- ((not (setq anXrec (dictsearch adict wallvar)))
- ;the variable MyDictvars is name of xrecord so need to be a variable to add lots
- ;;if "MyDictVARS" 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 getMyDictvars (/ vars varlist)
- ;;retrieve XRecord "wallvar" from dictionary "MyDict"
- ;;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)
- )
- )
|