Help with routine for texts - Autolisp

Help with routine for texts - Autolisp

scottividal
Contributor Contributor
863 Views
4 Replies
Message 1 of 5

Help with routine for texts - Autolisp

scottividal
Contributor
Contributor

Hello everyone,
I have started to create my own routines recently, and I cannot make any improvement with it since some days ago. So if anyone could help me I would be very thankful.

I need my routine to select all of the texts on a layer called "LAYER1", and to apply one command that I have created. The problem is that my command accepts variables like string, and it takes one by one (for now...).
My command it´s the next:

 

 

(defun C:TEST()

  
  	(setq VIG_TEX_OLD (getstring "Click en el texto a cambiar: "))
  
  	(setq INDICE_VIG_TEX_OLD (vl-string-position (ascii ":") VIG_TEX_OLD))

	(if (= INDICE_VIG_TEX_OLD 5)						
		(setq NOMBRE (substr VIG_TEX_OLD 3 3)				
		      DIMENSION (substr VIG_TEX_OLD 8 7))		
		(setq NOMBRE (substr VIG_TEX_OLD 3 4)				
		      DIMENSION (substr VIG_TEX_OLD 9 7)))		
	  									  
  	(setq VIGAS_TEXTO_NUEVO (strcat "V" NOMBRE "-" DIMENSION))		
	
 	(setq VIG_TEX_OLD NIL)	 						
   	(setq INDICE_VIG_TEX_OLD NIL)	 					
  	(setq NOMBRE NIL)	 						
	(setq DIMENSION NIL)	 						

  
  	(print VIGAS_TEXTO_NUEVO)
  
)

 

ASV
0 Likes
Accepted solutions (1)
864 Views
4 Replies
Replies (4)
Message 2 of 5

dbhunia
Advisor
Advisor

Hi,

 

As you asked.....

 


@scottividal wrote:

Hello everyone,
.......................

I need my routine to select all of the texts on a layer called "LAYER1", and to apply one command that I have created. The problem is that my command accepts variables like string, and it takes one by one (for now...).
My command it´s the next:

.....................


 

Try this....

 

 

(defun C:TEST()
(setq selectionset (ssget "_A" '((0 . "TEXT") (8 . "LAYER1"))));Select all the texts on a layer "LAYER1"
(repeat (setq N (sslength selectionset)); Go through each text on a layer "LAYER1"
	(setq Data (ssname selectionset (setq N (- N 1))))
	(setq EntityData (entget Data))
	(setq VIG_TEX_OLD (cdr (assoc 1 EntityData)))
  
  	;(setq VIG_TEX_OLD (getstring "Click en el texto a cambiar: "))
  	(setq INDICE_VIG_TEX_OLD (vl-string-position (ascii ":") VIG_TEX_OLD))
	(if (= INDICE_VIG_TEX_OLD 5)						
		(setq NOMBRE (substr VIG_TEX_OLD 3 3)				
		      DIMENSION (substr VIG_TEX_OLD 8 7))		
		(setq NOMBRE (substr VIG_TEX_OLD 3 4)				
		      DIMENSION (substr VIG_TEX_OLD 9 7)))		
  									  
  	(setq VIGAS_TEXTO_NUEVO (strcat "V" NOMBRE "-" DIMENSION))		
 	(setq VIG_TEX_OLD NIL)	 						
   	(setq INDICE_VIG_TEX_OLD NIL)	 					
  	(setq NOMBRE NIL)	 						
	(setq DIMENSION NIL)	 						
 
  	(print VIGAS_TEXTO_NUEVO)
)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 3 of 5

scottividal
Contributor
Contributor

Hi,


Thanks for you fast answer. The code works very good, but... I forgot mention that I need to the modificated string replace the text of layer "LAYER 1".

 

For example:

Take of LAYER1: V-101: 25x35
Return to LAYER1: V101-25x35.

How I cando this?

ASV
0 Likes
Message 4 of 5

dbhunia
Advisor
Advisor
Accepted solution

Hi,

 

Try this....

 

(defun C:TEST()
(setq selectionset (ssget "_A" '((0 . "TEXT") (8 . "LAYER1"))));Select all the texts on a layer "LAYER1"
(repeat (setq N (sslength selectionset)); Go through each text on a layer "LAYER1"
	(setq Data (ssname selectionset (setq N (- N 1))))
	(setq EntityData (entget Data))
	(setq VIG_TEX_OLD (cdr (assoc 1 EntityData)))
  
  	;(setq VIG_TEX_OLD (getstring "Click en el texto a cambiar: "))
  	(setq INDICE_VIG_TEX_OLD (vl-string-position (ascii ":") VIG_TEX_OLD))
	(if (= INDICE_VIG_TEX_OLD 5)						
		(setq NOMBRE (substr VIG_TEX_OLD 3 3)				
		      DIMENSION (substr VIG_TEX_OLD 8 7))		
		(setq NOMBRE (substr VIG_TEX_OLD 3 4)				
		      DIMENSION (substr VIG_TEX_OLD 9 7)))		
  									  
  	(setq VIGAS_TEXTO_NUEVO (strcat "V" NOMBRE "-" DIMENSION))		
 	(setq VIG_TEX_OLD NIL)	 						
   	(setq INDICE_VIG_TEX_OLD NIL)	 					
  	(setq NOMBRE NIL)	 						
	(setq DIMENSION NIL)	 						
 
  	;(print VIGAS_TEXTO_NUEVO)
        (setq ff1(assoc 1 EntityData))
	(setq xx1 (cons 1 VIGAS_TEXTO_NUEVO))
	(entmod(subst xx1 ff1 EntityData))
)
(princ) )

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 5

scottividal
Contributor
Contributor

It´s works perfect!!!

Thanks a lot Sr.!

ASV
0 Likes