jr.roberto.santos Posted December 23, 2021 Posted December 23, 2021 Greetings everyone, I'm trying a way to select an MTEXT and Replace a block attribute. The block name is HDV1_CONVERT (Attributes: TAG1F, DESC1, DESC2, DESC3…) Best Regards Quote
Steven P Posted December 23, 2021 Posted December 23, 2021 My AutoCAD is off just now so I can't check, but have you tried Lee Macs Copy text LISP? Quote
Tharwat Posted December 23, 2021 Posted December 23, 2021 I assumed that you are after replacing all text strings in the selected attributed block HDV1_CONVER to selected string from Mtext so here is a draft to see if this meet your aim of the program. (defun c:Test (/ int sel str ent get) ;; Tharwat - 23.Dec.2021 ;; (and (setq sel (car (entsel "\nPick Mtext : "))) (or (= (cdr (assoc 0 (entget sel))) "MTEXT") (alert "invalid object selected. Try again") ) (setq str (cdr (assoc 1 (entget sel)))) (princ (strcat "\nSelect Blocks to replace < HDV1_CONVERT > to replace < " str " > with all attributes with :" ) ) (setq int -1 sel (ssget "_:L" '((0 . "INSERT") (66 . 1) (2 . "HDV1_CONVERT")) ) ) (while (setq int (1+ int) ent (ssname sel int) ) (while (and (setq ent (entnext ent)) (not (eq (cdr (assoc 0 (setq get (entget ent)))) "SEQEND")) ) (and (= (cdr (assoc 0 get)) "ATTRIB") (entmod (subst (cons 1 str) (assoc 1 get) get)) ) ) ) ) (princ) ) 2 Quote
jr.roberto.santos Posted December 23, 2021 Author Posted December 23, 2021 Tharwat Thank you very much for your collaboration, for the code to be perfect, I just need to filter the attributes. Example: DESC2 and DESC3 Please, see attachment with example DWG. Best Regards Sample_Drawing.dwg Quote
Tharwat Posted December 23, 2021 Posted December 23, 2021 (edited) Give this a shot and let me know. (defun c:Test (/ int sel str ent get) ;; Tharwat - 23.Dec.2021 ;; (and (setq sel (car (entsel "\nPick Text or Mtext : "))) (or (wcmatch (cdr (assoc 0 (entget sel))) "MTEXT,TEXT") (alert "invalid object selected. Try again") ) (setq str (cdr (assoc 1 (entget sel)))) (princ (strcat "\nSelect Blocks to replace < HDV1_CONVERT > to replace < " str " > with all attributes with :" ) ) (setq int -1 sel (ssget "_:L" '((0 . "INSERT") (66 . 1) (2 . "HDV1_CONVERT")) ) ) (while (setq int (1+ int) ent (ssname sel int) ) (while (and (setq ent (entnext ent)) (not (eq (cdr (assoc 0 (setq get (entget ent)))) "SEQEND")) ) (and (wcmatch (cdr (assoc 2 get)) "DESC2,DESC3") (entmod (subst (cons 1 str) (assoc 1 get) get)) ) ) ) ) (princ) ) Edited December 24, 2021 by Tharwat You can select Text or Mtext now 1 Quote
Tharwat Posted December 24, 2021 Posted December 24, 2021 You can play with TAG names as I did in the second routine to target different tags based on your different requirements if needed. Quote
jr.roberto.santos Posted December 24, 2021 Author Posted December 24, 2021 As a beginner, I must also thank you. Tharwat thanks so much for the help, the response was instantaneous! Best Regards J. Roberto Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.