Results 1 to 5 of 5

Thread: (HELP) Trying to Apply Xrecord Dictionary to an Entity

  1. #1
    Member
    Join Date
    2013-01
    Posts
    3
    Login to Give a bone
    0

    Question (HELP) Trying to Apply Xrecord Dictionary to an Entity

    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

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: (HELP) Trying to Apply Xrecord Dictionary to an Entity

    It appears that you are attempting to add information to an object.
    LData is very versatile and can easily add lists of information to an object.

    In the following example I add a list of dotted pairs to an object with PutData and then retrieve the data using GetData.

    Would that work for you?

    If not can you describe using words what you are trying to do?

    P=

    Code:
    (defun C:PutData (/ entSelection
                        lstLData
                        lstSelection
                        objSelection
                     )
     (if (and
          (setq lstLData (list (cons "PART#" "A")(cons "QUANTITY" 1)(cons "SPACING" 16)))
          (setq lstSelection (entsel "\nSelect Part: "))
          (setq entSelection (car lstSelection))
          (setq objSelection (vlax-ename->vla-object entSelection))
         )
      (vlax-ldata-put objSelection "MYDATA" lstLData)
     )
    )
    
    (defun C:GetData (/ entSelection
                        lstSelection
                        objSelection
                     )
     (if (and
          (setq lstSelection (entsel "\nSelect Part: "))
          (setq entSelection (car lstSelection))
          (setq objSelection (vlax-ename->vla-object entSelection))
         )
      (vlax-ldata-get objSelection "MYDATA")
     )
    )
    (vl-load-com)
    AutomateCAD

  3. #3
    Member
    Join Date
    2013-01
    Posts
    3
    Login to Give a bone
    0

    Default Re: (HELP) Trying to Apply Xrecord Dictionary to an Entity

    Thanks Peter!

    That works perfectly, I read previously that I should try to stay away from LData for compatibility reasons, but this seems simple and works well. Thanks!

  4. #4
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: (HELP) Trying to Apply Xrecord Dictionary to an Entity

    The only people who do not like LData are those who are programming in other languages.

    LData is great if you are programming in LISP.

    Also a little secret... The layerzero object (vlax-ename->vla-object (tblobjname "layer" "0")) cannot be deleted and will accept LData if you want to store information using LData in a drawing file.

    Remember that you should not store vla-objects, enames, elists, etc... as LData only strings, sublists, numbers etc...

    Peter
    AutomateCAD

  5. #5
    AUGI Addict
    Join Date
    2015-12
    Posts
    2,095
    Login to Give a bone
    0

    Default Re: (HELP) Trying to Apply Xrecord Dictionary to an Entity

    Quote Originally Posted by peter View Post
    The only people who do not like LData are those who are programming in other languages.

    Incorrect.

    I've found it easier to work with XRecords and even XDATA, as LDATA is very flat ie. doesn't do "tree" style storage as you would with dictionaries; that means there is no segregation of data when there could be multiple types/classes/etc. on a single object. It also throws up a proxy object warning (about application "VLISP") when an LDATA-containing file is opened by double-clicking. Oh, and it doesn't do pointers or intelligent handle storage either. And... well, I think you get the point.

Similar Threads

  1. Dictionary and xRecord Names
    By jason907238 in forum Dot Net API
    Replies: 5
    Last Post: 2012-02-12, 06:36 PM
  2. C# sample attaching XRecord to a graphical object
    By ozwings in forum Dot Net API
    Replies: 1
    Last Post: 2009-09-17, 11:48 AM
  3. DXF file has some data in XRecord
    By B_Roche in forum VBA/COM Interop
    Replies: 3
    Last Post: 2008-02-28, 07:55 PM
  4. Replies: 1
    Last Post: 2007-09-14, 02:26 PM
  5. Proxy Entity Code 310 to Normal Entity
    By KevinBarnett in forum AutoCAD General
    Replies: 2
    Last Post: 2005-05-26, 07:21 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •