TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: encepta on January 23, 2023, 07:11:53 PM
-
I can't figure out how to access the text contents of a PMarker using the dxf code. I've read the DXF code list to try and find out more but 1. (what they say should return the primary text value) only returns nil.
I can access it directly by calling the element of the list using nth, but that limits this script, i.e. the text position in the entity list changes when using different .dwg or method of generating PMarker.
here is how i can access the other elements, i.e. ename, coords, text size:
(setq ename (cdr (assoc -1 entObj))
coords (cdr (assoc 10 entObj))
textSize (cdr (assoc 40 entObj))
)
I want the text contents though.
i.e. textString (cdr (assoc ?? entObj))
I've attached a picture of my properties in autocad and entity object properties output.
Is this possible? You can see in the output that there are two values for (1 . ) and (1 . thetextstringiwant). I have a feeling that when I call 1. it returns the first (empty) string rather than the second one. Any help is much appreciated!
-
here is a utility to retrieve multiple values
;;;=========================================================================
;;; massoc
;;;
;;; get multiple items from an association list (instead of just 1st one)
;;;
;;; From: Tony Tanzillo (tony.tanzillo@worldnet.att.net)
;;; Subject: Re: extracting multiple assoc from list
;;; Newsgroups: autodesk.autocad.customization
;;; Date: 1999/09/29
;;;
;;; revised by Dan, 2017
;;; to add option for key to be a list of assoc codes, '(10 11), or just a single
;;;=========================================================================
(defun massoc (key alist / x nlist)
(if (not (= 'LIST (type key)))
(setq key (list key))
)
(foreach y key
(foreach x alist
(if (eq y (car x))
(setq nlist (cons (cdr x) nlist))
)
)
)
(reverse nlist)
) ;end defun
-
(cdr (assoc 1
-
(cdr (assoc 1
I explicitly said in the OP that (cdr (assoc 1 entObj)) returns NIL.
-
here is a utility to retrieve multiple values
;;;=========================================================================
;;; massoc
;;;
;;; get multiple items from an association list (instead of just 1st one)
;;;
;;; From: Tony Tanzillo (tony.tanzillo@worldnet.att.net)
;;; Subject: Re: extracting multiple assoc from list
;;; Newsgroups: autodesk.autocad.customization
;;; Date: 1999/09/29
;;;
;;; revised by Dan, 2017
;;; to add option for key to be a list of assoc codes, '(10 11), or just a single
;;;=========================================================================
(defun massoc (key alist / x nlist)
(if (not (= 'LIST (type key)))
(setq key (list key))
)
(foreach y key
(foreach x alist
(if (eq y (car x))
(setq nlist (cons (cdr x) nlist))
)
)
)
(reverse nlist)
) ;end defun
Hey Dan,
Thanks for the function. This worked great.
Cheers,
Henry
-
Alternatively you could use -