Sorry I'm pretty new to Xdata, Xrecords & dictionaries and I got some code from "AfraLisp website and I'm trying to modify it to work for what i need. I'm going to store multiple "Part" dictionary information in Xrecords. Then I want to append these dictionaries to an entity (below only shows one dictionary, but in the future I will have "PartL1, PartL2, PartL3" that will all be applied to one entity). Then down the road I will make a lisp that will change the values for the "PartNum" "QTY" & "Spacing" for each.
The problem is I can't get the Xrecord dictionary to append to the entity's dictionary. Everything works fine until I get to this line of code:
Code:
(dictadd ent "PartL1" adict)
I don't know if i have the formating correct or I'm referencing this incorrectly. Please help, i've done research and I can't get past this.
Code:
(defun c:applyassem (/ vars varlist)
;;retrieve XRecord "PartL1" from dictionary "WSI_DICT"
;;which in turn calls both functions below
(setq vars (get-or-make-Xrecord))
;;get dictionary were "PartL1" is stored
(setq adict (cdr (car (dictsearch (namedobjdict) "WSI_DICT"))))
;;get entity to app
(setq ent (car (entsel)))
(dictadd ent "PartL1" adict)
(princ)
)
(defun get-or-create-Dict (/ adict)
;;test if "WSI_DICT" is already present in the main dictionary
(if (not (setq adict (dictsearch (namedobjdict) "WSI_DICT")))
;;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) "WSI_DICT" adict)))
)
;;if present then just return its entity name
(setq adict (cdr (assoc -1 adict)))
)
);defun
(defun get-or-make-Xrecord(/ adict anXrec)
(cond
;;first get our dictionary. make here in case it doesn't exit
((setq adict (get-or-create-Dict))
(cond
;;if "WSI_DICT" is now valid then look for "PartL1" Xrecord
((not (setq anXrec (dictsearch adict "PartL1")))
;;if "PartL1" was not found then create it
(setq anXrec (entmakex '((0 . "XRECORD")
(100 . "AcDbXrecord")
(7 . "PART#") ;will be part number
(90 . 1) ;will be default qty of part
(91 . 16) ;will be spacing in inches
)
);entmakex
);setq anXrec
;;if creation succeeded then add it to our dictionary
(if anXrec (setq anXrec (dictadd adict "PartL1" anXrec)))
);not
;;if it's already present then just return its entity name
(setq anXrec
(cdr (assoc -1(dictsearch adict "PartL1")))
);setq anxrex
);cond
);setq adict
);cond
);defun