alphanumeric sort in sequence

alphanumeric sort in sequence

beachgirl6172
Contributor Contributor
1,920 Views
24 Replies
Message 1 of 25

alphanumeric sort in sequence

beachgirl6172
Contributor
Contributor

Hi all, is there any lisp for alphanumeric sort in sequence by selection?

example : A21(5), A59(8), A73(29)...renumbering A1(5), A2(59), A3(29)?

Thank you.

 

Untitled.jpg

0 Likes
Accepted solutions (1)
1,921 Views
24 Replies
Replies (24)
Message 3 of 25

komondormrex
Mentor
Mentor

hey there,

check this

(defun c:anum_seq_sort (/ text_sset index text_list)
	(if (setq text_sset (ssget '((0 . "text"))))
		(progn
			(setq index 0)
			(foreach text (vl-sort (mapcar 'vlax-ename->vla-object 
										   (vl-remove-if 'listp (mapcar 'cadr (ssnamex text_sset)))
								   )
								   '(lambda (text_1 text_2) (> (cadr (vlax-get text_1 'insertionpoint))
															   (cadr (vlax-get text_2 'insertionpoint))
															)
									)
						  )
						  (vla-put-textstring 
						  	text 
							(strcat (vl-list->string 
						  				(vl-remove-if 
											'(lambda (asc) (member asc '(48 49 50 51 52 53 54 55 56 57)))
						  					 (vl-string->list (vl-princ-to-string 
																(car (setq text_list 
																		(read 
																			(strcat "(" 
																					 (vla-get-textstring text) 
																					 ")"
																			)
																		)
																	 )
																)
															  )
											 )
										)
								   )
								   (itoa (setq index (1+ index)))
								   (vl-princ-to-string (cadr text_list))
						    )
						  )
			)
		)
	)
	(princ)
)
0 Likes
Message 4 of 25

beachgirl6172
Contributor
Contributor

if i need to start with another number? cannot define what number i want..

0 Likes
Message 5 of 25

beachgirl6172
Contributor
Contributor

thank you. thank you. i already try it before, there's not what i want.

0 Likes
Message 6 of 25

paullimapa
Mentor
Mentor

Questions 

1. Is there always going to be a single alphabet in front? A and never AA

2. Up to how many digits would you have after the alphabet like 2 A99 or even 3 A999

3. Same questions go to the number within the parentheses (99) or (999)


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

beachgirl6172
Contributor
Contributor

Hi,

 

Answer :

1)yes. there's always single alphabet in front.

 

2) the biggest number maybe until 4 digit after the alphabet (A1 - A9999)

 

3) the number within the parentheses (1-999)

 

on this case i only need renumbering the alphanumeric but maintain the number within parentheses. 

 

0 Likes
Message 8 of 25

komondormrex
Mentor
Mentor
Accepted solution

then this one

 

(defun c:anum_seq_sort (/ text_sset text_list index)
	(if (setq text_sset (ssget '((0 . "text"))))
		(progn
			(if (null index_saved) (setq index_saved 1))
			(initget 6)
			(if (null (setq index (getint (strcat "\nStart numbering with <" (itoa index_saved) ">: "))))
				(setq index index_saved)
			)
			(foreach text (vl-sort (mapcar 'vlax-ename->vla-object 
										   (vl-remove-if 'listp (mapcar 'cadr (ssnamex text_sset)))
								   )
								   '(lambda (text_1 text_2) (> (cadr (vlax-get text_1 'insertionpoint))
															   (cadr (vlax-get text_2 'insertionpoint))
															)
									)
						  )
						  (vla-put-textstring 
						  	text 
							(strcat (vl-list->string 
						  				(vl-remove-if 
											'(lambda (asc) (member asc '(48 49 50 51 52 53 54 55 56 57)))
						  					 (vl-string->list (vl-princ-to-string 
																(car (setq text_list 
																		(read 
																			(strcat "(" 
																					 (vla-get-textstring text) 
																					 ")"
																			)
																		)
																	 )
																)
															  )
											 )
										)
								   )
								   (itoa index)
								   (vl-princ-to-string (cadr text_list))
						    )
						  )
						  (setq index (1+ index))
			)
			(setq index_saved index) 
		)
	)
	(princ)
)

 

Message 9 of 25

beachgirl6172
Contributor
Contributor

I appreciate your help very much.. 😀🙏

0 Likes
Message 10 of 25

komondormrex
Mentor
Mentor

you are much welcome)

0 Likes
Message 11 of 25

beachgirl6172
Contributor
Contributor

this is the result i get.... 

I'm sorry to trouble you.

 

Untitled.jpg

0 Likes
Message 12 of 25

komondormrex
Mentor
Mentor

wow these texts are vertical. will return with correction.

Message 13 of 25

beachgirl6172
Contributor
Contributor

sorry for my poor explanation.

actually my drawing like this.....

Untitled.jpg

0 Likes
Message 14 of 25

komondormrex
Mentor
Mentor

this one implements fence selecting of texts (not on locked layers), thus enumerating will be done along fence pline drawn on active, not locked layer.

 

;**********************************************************************************************************************************************

(defun make_points (coordinates_raw_list / point_list)
  	(if coordinates_raw_list
		(setq point_list (cons
							   (list (car coordinates_raw_list) (cadr coordinates_raw_list))
							   (make_points (cddr coordinates_raw_list))
						 )
		)
	)
  	point_list
)

;**********************************************************************************************************************************************

(defun draw_fence (/ vertex fence vertices_list)
	(while (and (setq vertex (vl-catch-all-apply 'getpoint (if vertex (list vertex "\nPick next fence vertex: ") 
																	  (list "\nPick 1st fence vertex: ")
														   )
							 )
				)
				(null (vl-catch-all-error-p vertex))
		   )
		   (if (< 2 (length (setq vertices_list (append vertices_list (list (car vertex) (cadr vertex))))))
			   (if (null fence)
					(setq fence (vla-addlightweightpolyline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
															(vlax-safearray-fill (vlax-make-safearray vlax-vbdouble 
																									  (cons 1 (length vertices_list))) 
																									  vertices_list
															)
								)
					)
					(vlax-put fence 'coordinates vertices_list)
				)
		   )
	)
	(if (vl-catch-all-error-p vertex) (vla-erase fence) fence)
)

;**********************************************************************************************************************************************

(defun c:anum_seq_sort (/ fence text_gap_selection text_sset text_list index)
	(if (setq fence (draw_fence))
		(progn
			(setq text_gap_selection (getvar 'textgapselection))
			(setvar 'textgapselection 1)
			(if (null index_saved) (setq index_saved 1))
			(initget 6)
			(or (setq index (getint (strcat "\nStart numbering with <" (itoa index_saved) ">: ")))
				(setq index index_saved)
			)
			(foreach text (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr 
																					(ssnamex (ssget "_f" 
																									(make_points (vlax-get fence 'coordinates)) 
																								   '((0 . "text")))
																					)
																			   )
														  )
						  )
						  (vla-put-textstring
						  	text
							(strcat (vl-list->string
						  				(vl-remove-if
											'(lambda (asc) (member asc '(45 48 49 50 51 52 53 54 55 56 57)))
						  					 (vl-string->list (vl-princ-to-string
																(car (setq text_list
																		(read
																			(strcat "("
																					 (vla-get-textstring text)
																					 ")"
																			)
																		)
																	 )
																)
															  )
											 )
										)
								   )
								   (itoa index)
								   (vl-princ-to-string (if (cadr text_list) (cadr text_list) ""))
						    )
						  )
						  (setq index (1+ index))
			)
			(vla-erase fence)
			(setq index_saved index)
		)
	)
	(setvar 'textgapselection text_gap_selection)
	(princ)
)

;**********************************************************************************************************************************************

 

updated

0 Likes
Message 15 of 25

beachgirl6172
Contributor
Contributor

 

i'm not sure whether i done correctly
attached herewith video for your reference
some of the number are not in order

but anyway many thanks for your helping.

0 Likes
Message 16 of 25

beachgirl6172
Contributor
Contributor

 

herewith the picture 😉

 

Untitled.jpg

0 Likes
Message 17 of 25

komondormrex
Mentor
Mentor

i see

0 Likes
Message 18 of 25

komondormrex
Mentor
Mentor

check update in message 14.

0 Likes
Message 19 of 25

beachgirl6172
Contributor
Contributor

hi, @komondormrex 

i get this error command

Untitled.jpg

0 Likes
Message 20 of 25

beachgirl6172
Contributor
Contributor

the fence selection always start with number 1? can i define the number?

0 Likes