LISP routine for mirroring text around a specific piece of text

LISP routine for mirroring text around a specific piece of text

Anonymous
Not applicable
1,903 Views
9 Replies
Message 1 of 10

LISP routine for mirroring text around a specific piece of text

Anonymous
Not applicable

Hello-

 

Basically I need a LISP routine that will mirror content in an attribute block (if this is possible). We have a 'wire label' block that has an attribute in it called TAG# and there was a goof when creating the wire tags and they are 180 degrees from what they should be. So my wire label is currently BBBB/AAAA and I need it to be AAAA/BBBB. Is it possible to create a lisp that would mirror the current text around the '/' that is in my wire label? Looking for a simple solution that I can just drop and go rather than going through and re-doing hundreds of IO drawing wire labels.

 

Thanks in advance.

0 Likes
Accepted solutions (1)
1,904 Views
9 Replies
Replies (9)
Message 2 of 10

devitg
Advisor
Advisor

please upload a sample dwg , not image 

0 Likes
Message 3 of 10

paullimapa
Mentor
Mentor

It sounds like you want to swap the positions of the two Attributes inside the Block.

Upload the Block with the Attributes along with pictures of how it looks like now vs what you want it to look like so we can all investigate.

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 10

Anonymous
Not applicable

See attachment.

 

As you can see between the two tags I need the content to switch from one side of slash to the other within one attribute. We have worked a little with swap text in single line text or mtext, but it wont recognize or pull the content from any type of attribute.

0 Likes
Message 5 of 10

hak_vz
Advisor
Advisor

I hope this solves your problem.

 

 

(defun keyValue (key el)(cdr (assoc key el)))

(defun flip (e /  ent type attname edit mirror len t1 t2 newtext)
 (while (and (setq e (entnext e))
	     (setq ent (entget e))
	     (/= "SEQEND" (keyValue 0 ent))
	   )
    (setq  type (keyValue 0 ent))
	(setq attname (keyValue 2 ent))
    (if (and(= type "ATTRIB")(= attname "TAG#")) (setq  edit e))
  )

		(setq ent (entget edit) text(keyValue 1 ent ))
		(setq mirror(vl-string-position (ascii "/") text) len (strlen text))
		(setq t1 (substr text 1 mirror) t2 (substr text (+ mirror 2) len))
		(setq newtext (strcat t2 "/" t1))
		(setq ent (subst (cons 1 newtext) (assoc 1 ent) ent)) 
		(setq ent (entmod ent))
	
)

(defun c:flip-it (/ e) 
	(setq e (car (entsel "\nSelect block to flip tag# >")))
	(flip e)
	(command "regen" "")
	(princ)
)

 

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 6 of 10

hak_vz
Advisor
Advisor

If your drawings doesn't contain any additional block that could be changed by mistake you may use 

 

(defun c:flip-it-all (/ e )
	(setq ss (ssget "X" '((0 . "INSERT"))) i 0)
	(repeat (sslength ss)
		(setq e (ssname ss i) i (+ i 1))
		(flip e)
	)
	(flip e)
	(command "_regenall" "")
	(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 10

Satish_Rajdev
Advocate
Advocate
Accepted solution

I've made code according to your requirement and it works perfectly on your drawing.

 

Please check and review.

 

(defun c:test (/ proc a b i)
  (defun proc (s / p q)
    (if	(setq q (member (ascii "/") (setq p (vl-string->list s))))
      (progn
	(setq p (reverse (cdr (member 47 (reverse p)))))
	(strcat (vl-list->string (cdr q)) "/" (vl-list->string p))
      )
    )
  )
  (if (setq a (ssget '((0 . "insert") (66 . 1))))
    (repeat (setq i (sslength a))
      (setq b (vlax-ename->vla-object (ssname a (setq i (1- i)))))
      (mapcar '(lambda (x)
		 (if (eq (strcase (vla-get-tagstring x)) "TAG#")
		   (vla-put-textstring x (proc (vla-get-textstring x)))
		 )
	       )
	      (vlax-invoke b 'getattributes)
      )
    )
  )
  (princ)
)

Best Regards,
Satish Rajdev


REY Technologies | Linked IN | YouTube Channel


 

Message 8 of 10

Anonymous
Not applicable

Much appreciated to all of you. Thanks again!

0 Likes
Message 9 of 10

Satish_Rajdev
Advocate
Advocate
You're welcome 🙂

Best Regards,
Satish Rajdev


REY Technologies | Linked IN | YouTube Channel


 

0 Likes
Message 10 of 10

pbejse
Mentor
Mentor

cbaden wrote:

 

..So my wire label is currently BBBB/AAAA and I need it to be AAAA/BBBB...


Another

 

(Defun c:demo (/ ss i)
  (if
    (setq ss (ssget '((0 . "INSERT") (66 . 1))))
	(repeat (setq i (sslength ss))
	  (vl-some
	    '(lambda (itm / str p)
		  (setq str (Vla-get-textstring itm))
		  (if (and (Eq (vla-get-tagstring itm) "TAG#")
				 (setq p (vl-string-position 47 str))
			 )
		    (not (Vla-put-textstring
				 itm
				 (strcat (substr str (+ 2 p)) "/" (substr str 1 p))
			    )
		    )
		  )
		)
	    (vlax-invoke
		 (vlax-ename->vla-object (ssname ss (setq i (1- i))))
		 'GetAttributes
	    )
	  )
	)
  )
  (princ)
)
0 Likes