Remove/Replace *text - Now trying to add attributes?

Remove/Replace *text - Now trying to add attributes?

smaher12
Advocate Advocate
1,078 Views
6 Replies
Message 1 of 7

Remove/Replace *text - Now trying to add attributes?

smaher12
Advocate
Advocate

I have a lisp that will remove or replace specific word(s) from user selected text/mtext strings. Now I am trying to get it to work for user selected attribute text strings and I have come to a road block.

 

(defun C:TEST (/ ss n tobj)
  (vl-load-com)
  (setq ss (ssget "+.:S" '((0 . "*TEXT,ATTDEF") (1 . "*THE*, *AVENUE*, *CIRCLE*, *DRIVE*"))))
  (repeat (setq n (sslength ss))
    
    (vla-put-TextString
      (setq tobj (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
      (vl-string-subst "" "THE " (vla-get-TextString tobj))
    )
    (vla-put-TextString
      tobj
      (vl-string-subst "AVE.," "AVENUE" (vla-get-TextString tobj))
    )
    (vla-put-TextString
      tobj
      (vl-string-subst "CIR.," "CIRCLE" (vla-get-TextString tobj))
    )
    (vla-put-TextString
      tobj
      (vl-string-subst "DR.," "DRIVE" (vla-get-TextString tobj))
    )
    ); repeat
  (princ)
); defun

 

 

0 Likes
Accepted solutions (1)
1,079 Views
6 Replies
Replies (6)
Message 2 of 7

ronjonp
Mentor
Mentor

Do you need "ATTRIB" or "ATTDEF" ? If ATTRIB and single selection ( as you have now ), you'll need to use NENTSEL.

0 Likes
Message 3 of 7

smaher12
Advocate
Advocate

Yeah it looks like I am still lost.

 

(defun C:TEST ()
 (vl-load-com)

(setq ent (car (nentsel "\nSelect Text/Attribute: ")))
      (member (cdr (assoc 0 (entget ent))
       '(("*TEXT" "ATTRIB")(1 . "*THE*, *AVENUE*, *CIRCLE*, *DRIVE*"))
      )
 (repeat (setq n (sslength ent))
    
    (vla-put-TextString
      (setq tobj (vlax-ename->vla-object (ssname ent (setq n (1- n)))))
      (vl-string-subst "" "THE " (vla-get-TextString tobj))
    )
    (vla-put-TextString
      tobj
      (vl-string-subst "AVE.," "AVENUE" (vla-get-TextString tobj))
    )
    (vla-put-TextString
      tobj
      (vl-string-subst "CIR.," "CIRCLE" (vla-get-TextString tobj))
    )
    (vla-put-TextString
      tobj
      (vl-string-subst "DR.," "DRIVE" (vla-get-TextString tobj))
    )
    ); repeat
 )
)
0 Likes
Message 4 of 7

Sea-Haven
Mentor
Mentor

1 Your ssget will need *text,insert to get blocks. Perhaps remove the (1 ……..

2 Put your (setq tobj (vlax-ename->vla-object (ssname ss (setq n (1- n))))) Below the repeat

3 put all the vla-put in a new defun above the code now. Moving from existing code

4 do a check is tobj a "text or Mtext" if yes do new defun.

4a do a check is tobj ObjectName (RO) = "AcDbBlockReference" use  "and" "has-attributes" if no attributes then skip..

4b do a vlax-for att attributes then run defun for every attribute.

5 all done

 

Hope this makes sense.

 

(defun all the puts)

SSget

repeat

if *text do defunputs

if has-atts do get-attributes in loop and do defun

 

 

 

 

 

0 Likes
Message 5 of 7

ronjonp
Mentor
Mentor
Accepted solution

@smaher12 wrote:

Yeah it looks like I am still lost.

 

(defun C:TEST ()
 (vl-load-com)

(setq ent (car (nentsel "\nSelect Text/Attribute: ")))
      (member (cdr (assoc 0 (entget ent))
       '(("*TEXT" "ATTRIB")(1 . "*THE*, *AVENUE*, *CIRCLE*, *DRIVE*"))
      )
 (repeat (setq n (sslength ent))
    
    (vla-put-TextString
      (setq tobj (vlax-ename->vla-object (ssname ent (setq n (1- n)))))
      (vl-string-subst "" "THE " (vla-get-TextString tobj))
    )
    (vla-put-TextString
      tobj
      (vl-string-subst "AVE.," "AVENUE" (vla-get-TextString tobj))
    )
    (vla-put-TextString
      tobj
      (vl-string-subst "CIR.," "CIRCLE" (vla-get-TextString tobj))
    )
    (vla-put-TextString
      tobj
      (vl-string-subst "DR.," "DRIVE" (vla-get-TextString tobj))
    )
    ); repeat
 )
)

Do you really want to select these one at at a time? Your code above will definitely not work now as you can't pass (sslength ent) because (ent) is an ename not a selection set. Here is a quick revision .. give it a try ( untested ).

(defun c:test (/ e o s)
  (if (and (setq e (car (nentsel "\nSelect Text/Attribute: ")))
	   (wcmatch (cdr (assoc 0 (entget e))) "*TEXT,ATTRIB")
	   ;; This check is case sensitive!
	   (wcmatch (setq s (vla-get-textstring (setq o (vlax-ename->vla-object e))))
		    "*THE*,*AVENUE*,*CIRCLE*,*DRIVE*"
	   )
      )
    (vla-put-textstring
      o
      (vl-string-subst
	"DR.,"
	"DRIVE"
	(vl-string-subst
	  "CIR.,"
	  "CIRCLE"
	  (vl-string-subst "AVE.," "AVENUE" (vl-string-subst "" "THE " s))
	)
      )
    )
  )
  (princ)
)(vl-load-com)

 

Message 6 of 7

smaher12
Advocate
Advocate

ronjonp - This works perfect for what I need it for. Clean and simple. Thank you so much!

0 Likes
Message 7 of 7

ronjonp
Mentor
Mentor

@smaher12 wrote:

ronjonp - This works perfect for what I need it for. Clean and simple. Thank you so much!


You're welcome! 🍻

0 Likes