Help to filter text, mtext and attribute

Help to filter text, mtext and attribute

msarqui
Collaborator Collaborator
693 Views
3 Replies
Message 1 of 4

Help to filter text, mtext and attribute

msarqui
Collaborator
Collaborator

Hi guys,

 

I am trying to make a filter but something is wrong. Could you help me please?

 

 

(defun C:FT (/ ent)
(while
(setq ent (nentsel "\n  **  Select Text, Mtext, Attribut or <exit>:  **"))
(progn
	(cond
		((eq (cdr (assoc 0 (entget (car ent)))) "TEXT")
			  (command "_textedit" ent)	
		);eq
		((eq (cdr (assoc 0 (entget (car ent)))) "MTEXT")
		  	  (command "_mtedit" ent)	
		);eq
		((eq (and (cdr (assoc 0 (entget (car ent)))) "ATTRIB")
			  (= "A" (cdr (assoc 2 ent)))   ;<------I think the problem is here. I am trying to filter an attribute tag A
		     );and
			  (command "_attipedit" ent)	
		);eq
		((eq (and (cdr (assoc 0 (entget (car ent)))) "ATTRIB")
		          (= "G02" (cdr (assoc 2 ent)))   ;<-------And here. I am trying to filter an attribute tag G02
		     );and
			  (command "_attedit" ent)	
		);eq
	);cond
);progn
);while
);defun

 

Thanks

Marcelo

 

0 Likes
Accepted solutions (2)
694 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

I think you have some function names reversed, and you're trying to extract information from an entity name that needs to come from its entity data list.  Try changing this part:

....

  ((eq (and (cdr (assoc 0 (entget (car ent)))) "ATTRIB")
      (= "A" (cdr (assoc 2 ent)))
      );and
     (command "_attipedit" ent)
   );eq
   ((eq (and (cdr (assoc 0 (entget (car ent)))) "ATTRIB")
      (= "G02" (cdr (assoc 2 ent)))
      );and
     (command "_attedit" ent)
   );eq

....

to this [I'm using (=) instead of (eq) -- either should work]:

....

  ( (and

      (= (cdr (assoc 0 (entget (car ent)))) "ATTRIB")
      (= "A" (cdr (assoc 2 (entget (car ent)))))
    );and
    (command "_attipedit" ent) 
  ); tag A condition
  ( (and

      (= (cdr (assoc 0 (entget (car ent)))) "ATTRIB")
      (= "G02" (cdr (assoc 2 (entget (car ent)))))
    );and
    (command "_attedit" ent)
  ); tag G02 condition

....

 

I would suggest saving (entget (car (ent))) as a variable prior to the above, to shorten it.

Kent Cooper, AIA
0 Likes
Message 3 of 4

hmsilva
Mentor
Mentor
Accepted solution

Hi Marcelo,

the

_$ (setq ent (nentsel "\n  **  Select Text, Mtext, Attribut or <exit>:  **"))
(<Entity name: 7ffffb2a050> (2021.98 1624.74 0.0))
_$ (command "_attedit" ent);<===
; error: Function cancelled

will raise an error, we need to call 'initdia' first...

I would do something like this:

 

(defun C:FT (/ ent nsel typ)
    (while
        (and (setq nsel (nentsel "\n  **  Select Text, Mtext, Attribut or <exit>:  **"))
             (setq ent (entget (car nsel)))
             (setq typ (cdr (assoc 0 ent)))
        )
           (cond
               ((eq typ "TEXT")
                (command "_.textedit" nsel)
               ) ;eq
               ((eq typ "MTEXT")
                (command "_.mtedit" nsel)
               ) ;eq
               ((and (eq typ "ATTRIB")
                     (eq (cdr (assoc 2 ent)) "A")
                ) ;and
                (command "_.attipedit" nsel)
               ) ;eq
               ((and (eq typ "ATTRIB")
                     (eq (cdr (assoc 2 ent)) "G02")
                ) ;and
                (initdia)
                (command "_.attedit" nsel)
               ) ;eq
               (T
                (princ "\nYou've selected a wrong entity type...try again... ")
               ) ;T
           ) ;cond
    ) ;while
    (princ)
) ;defun

 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 4 of 4

msarqui
Collaborator
Collaborator

Kent and Henrique,

 

Both are working 🙂

Thanks for your help!

 

Marcelo

0 Likes