Hi,
I am wanting to use autolisp to access the text in a MTEXT entity. assoc(1) gives me the first bit of text, but not the rest.
Is there a way to use assoc to access each of a number of matches or do I need to write my own routine to find all the 1's?
- Or is there some other command I can use?
With thanks
@hdixon wrote:Hi,
I am wanting to use autolisp to access the text in a MTEXT entity. assoc(1) gives me the first bit of text, but not the rest.
Is there a way to use assoc to access each of a number of matches or do I need to write my own routine to find all the 1's?
- Or is there some other command I can use?
With thanks
(vla-get-textstring (vlax-ename->vla-object (car (entsel))))
That will give you the entire String value of an Mtext
Sample code
(defun c:Demo ( / mtexts i) (vl-load-com) (if (setq mtexts (ssget '((0 . "MTEXT")))) (repeat (setq i (sslength mtexts)) (print (vla-get-textstring (vlax-ename->vla-object (ssname mtexts (Setq i (1- i)))))))) (princ))
Holler if you need help
Hi,
There's none built-in functions but you'll find many 'massoc' routines which return a list of all entries for the specified key in an association list.
Here's mine:
(defun gc:massoc (code alst) (if (setq alst (member (assoc code alst) alst)) (cons (cdar alst) (gc:massoc code (cdr alst))) ) )
@_gile wrote:Hi,
There's none built-in functions but you'll find many 'massoc' routines which return a list of all entries for the specified key in an association list.
Here's mine:
(defun gc:massoc (code alst) (if (setq alst (member (assoc code alst) alst)) (cons (cdar alst) (gc:massoc code (cdr alst))) ) )
Nice recursion code _gile,
OP:
in this case its DXF 3 and not 1
Another, to include 1 & 3
(Defun another (code alst)(vl-load-com) (mapcar 'cdr (vl-remove-if-not (function (lambda (k) (member (car k) alst)) ) ;_ end of lambda code ) ;_ end of vl-remove-if-not ) ;_ end of mapcar ) ;_ end of Defun
(ANOTHER data '(1 3))
HTH
Hi,
Thankyou all for your suggestions. As often happens I have been moved to a different crisis, but expect to be back on this in about a fortnight.
Thanks again for the ideas and suggestions.
@hdixon wrote:Hi,
I am wanting to use autolisp to access the text in a MTEXT entity. assoc(1) gives me the first bit of text, but not the rest.
Is there a way to use assoc to access each of a number of matches or do I need to write my own routine to find all the 1's?
- Or is there some other command I can use?
With thanks
This will not just get the assorted sub-string values from the (assoc 3) and (assoc 1) entries for a selected Mtext entity, but put them back together into a single text string:
(apply
'strcat
(mapcar 'cdr
(vl-remove-if-not
'(lambda (x)
(member (car x) '(3 1))
); lambda
(entget (car (entsel))); [or feed in variable with entity data list if you have it already]
); -remove-
); mapcar
); apply
However, you can get the same result with a lot less code from pbejse's (vla-get-textstring...) approach.