Read Data Dictionary Entries

Read Data Dictionary Entries

Anonymous
Not applicable
3,805 Views
5 Replies
Message 1 of 6

Read Data Dictionary Entries

Anonymous
Not applicable

*This post was moved from the Autodesk maps 3D developers forum by way of suggestion.*

 

 

I'm developing an Autolisp program to piggy back off of an ArcGIS plugin that was created by my company. Previously, we were importing *.SHP files using the mapimport command, so I was able to use the ADE_* commands to access this object data, but now the data is stored in a data dictionary associated with the ACAD object and I'm not sure how to access these values. The attached image shows the tag and value that I'm attempting to access, but this dialog is built into to the plugin. I've done multiple searches on this topic, with no avail, as I'm not very familiar with data dictionary's. Any help would be much appreciated.

 

 

 

Do you know the chapter inside the Autolisp-documentation:

 

Dictionary Functions Reference (AutoLISP/ActiveX)

http://help.autodesk.com/view/ACD/2018/DEU/?guid=GUID-F5F376FF-9BC2-476A-9EA9-1455D28DE264

 

 

 

*******- ;This has been omitted for anonymity.

 

Thank you for the prompt response! I was not aware of these functions, but sadly have not come across a decent example to pick through for my purposes. Maybe you can shed some light on what I may be doing wrong. Though my code may be unconventional, The following is my code so far for this portion

 

 

 

 

(vl-load-com)

(defun c:t ()
(get_intended_objects)
(setq x 0 tlis '())
(repeat (sslength ss)
(get_dictionary_data (ssname ss x))
(setq tlis (append tlis (list nlis)))
(setq x (+ x 1))
)
(princ)
)

(defun get_intended_objects ()
(setq ss (ssget (list (cons -4 "<or")
(cons 0 "point")
(cons -4 "or>")
)))
(princ)
)

(defun get_dictionary_data (ent)
(setq dict (cdr (assoc 3 (entget (cdr (assoc 360 (entget ent)))))))
(setq ena (entget (cdr (assoc 360 (entget (cdr (assoc 360 (entget ent))))))))
(setq g 0 lis '())
(repeat (length ena)
(setq itm (nth g ena))
(if (= (car itm) 3)(setq lis (append lis (list (cdr itm)))))
(setq g (+ g 1))
)
(setq g 0 nlis '())
(repeat (length lis)
(setq nlis (append nlis (list (vlax-ldata-get dict (nth g lis)))))
(setq g (+ g 1))
)
(princ)
)

(princ)

 

 

 

Lists have always been my way of organizing information, so I'm attempting to retrieve the string values, of a key, of a dictionary, by entity in a selection set, to store in a list. I've attached a DWG file with the object I'm trying to interact with contained. Thanks in advance!

 

Thanks,

Michael Luckett

0 Likes
Accepted solutions (1)
3,806 Views
5 Replies
Replies (5)
Message 2 of 6

Sea-Haven
Mentor
Mentor

Your dwg does not appear to have any xdata.

0 Likes
Message 3 of 6

CodeDing
Advisor
Advisor

@Anonymous ,

 

I believe this may be what you're looking for..

(defun c:TEST ( / e xD esriD)
(if (not (and (setq e (car (entsel "\nSelect Object: ")))	;entity
	      (setq xD (cdr (assoc 360 (entget e))))		;xDictionary
	      (setq esriD (cdr (assoc -1 (dictsearch xD "ESRI_ATTRIBUTES"))))));esriAttributesDictionary
  (progn (prompt "...no Esri Attributes found.") (exit))
);if
;this will print all ESRI attributes for you to see
(foreach x (entget esriD)
  (if (= 3 (car x)) (princ (strcat "\n" (cdr x))))
);foreach
;here is an example to retrieve dictionary/xrecord of an attribute
(if (setq cpn (dictsearch esriD "CAPITAL_PROJECT_NUMBER"))
  (progn (terpri) (princ cpn))
  (prompt "\n...your attribute was not found.")
);if
;finish
(prompt "\nComplete...")
(princ)
);defun

Best,

~DD

0 Likes
Message 4 of 6

CodeDing
Advisor
Advisor
Accepted solution

@Anonymous ,

 

Assuming that all values for attributes are stored as text (dxf code 1).. then this will return a list of all key/value pairs for all entities in selection set..

(defun c:EA ( / ss kvList e)
;Esri Attributes
;get sel set
(prompt "\nSelect Points: ")
(if (not (setq ss (ssget '((0 . "POINT")))))
  (progn (prompt "\n...no POINT entities found.") (exit))
);if
;key/value list
(setq kvList '())
;loop through ss
(repeat (setq cnt (sslength ss))
  (setq e (ssname ss (setq cnt (1- cnt)))
	kvList (cons (list e (GetKVPairs e)) kvList))
);repeat
;here is final Key/Value list for entities...
(princ kvList)
;finish
(prompt "\nEA Complete...")
(princ)
);defun

(defun GetKVPairs (e / return xD esriD att key val)
;Get Key/Value Pairs
(setq return '())
(if (and (setq xD (cdr (assoc 360 (entget e))))
	 (setq esriD (cdr (assoc -1 (dictsearch xD "ESRI_ATTRIBUTES")))))
  (progn
    (setq att (entget esriD))
    (while (setq att (member (assoc 3 att) att))
      (setq key (cdr (car att))
	    val (cdr (assoc 1 (entget (cdr (car (setq att (cdr att))))))))
      (setq return (cons (cons key val) return))
    );while
    (setq return (reverse return))
  );progn
;else
  (setq return nil)
);if
return
);defun

The final "kvList" is returned in this format...

(
  ( entity1 ((key1 . value1) (key2 . value2) ...))
  ( entity2 ((key1 . value1) (key2 . value2) ...))
  .....
)

Best,

~DD

0 Likes
Message 5 of 6

Anonymous
Not applicable

DD,

 

Thank you! This is perfect for what I'm trying to accomplish. Thanks again!

 

Thanks,

Michael Luckett

0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

Mis read the post Data Dictionary

 

For any one else if you do not know dictionary name 

 

(setq dict (cdr (assoc 3 (entget (cdr (assoc 360 (entget (car (entsel)))))))))

Returns "ESRI_ATTRIBUTES"
0 Likes