Jump to content

Lisp Routine HELP! Can't append Xrecord dictionary to an Entity


Recommended Posts

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:

(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.



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


(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
     (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 get-or-make-Xrecord(/ adict anXrec)


   ;;first get our dictionary. make here in case it doesn't exit
   ((setq adict (get-or-create-Dict))


      ;;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
      );setq anXrec

;;if creation succeeded then add it to our dictionary
(if anXrec (setq anXrec (dictadd adict "PartL1" anXrec)))

      ;;if it's already present then just return its entity name
      (setq anXrec
(cdr (assoc -1(dictsearch adict "PartL1")))
);setq anxrex


    );setq adict



Link to comment
Share on other sites

Or to make it simpler, how can I get this code to work:


(defun c:assemapply (/ ent xname datalist)
 (setq ent (car (entsel)))

 (setq datalist (append (list '(0 . "XRECORD")
			 '(100 . "AcDbXrecord"))
			 '((1 . "PartL1") (7 . "PART#") (90 . 1) (91 . 16))))
 (setq xname (entmakex datalist))

 (dictadd ent "PartL1" xname)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...