Seek a lisp for increment the SEC no.

Seek a lisp for increment the SEC no.

skchui6159
Advocate Advocate
331 Views
2 Replies
Message 1 of 3

Seek a lisp for increment the SEC no.

skchui6159
Advocate
Advocate

skchui6159_1-1741518902602.png

 

Can a lisp to increase/decrease the section no. only?

For example (the increment nos. is a variable( integer).

increase 1, 

the sec should SEC 9, SEC 10 but (1:25) not change

decrease 1

the sec should 7, SEC 8 but (1:25) not change

0 Likes
Accepted solutions (1)
332 Views
2 Replies
Replies (2)
Message 2 of 3

komondormrex
Mentor
Mentor
Accepted solution

@skchui6159 

check the following code. 

 

;*****************************************************************************************************************
;
;	'add_value_texts' custom command adds value to certain numbers within text strings
;	komondormrex, mar, 2025
;	totally lm free
;
;*****************************************************************************************************************

(defun string_to_list (string delimiter_string / out_list)
    (setq char_list (vl-string->list string))
  (defun parse_string (char_list delimiter_string / substring)
    (setq char_list_remainder char_list)
    (if (vl-some '(lambda (ascii_code)
              (setq substring (cons ascii_code substring)
                  char_list_remainder (cdr char_list_remainder)
            )
              (member ascii_code (vl-string->list delimiter_string))
              )
              char_list
      )
      (progn
        (setq delimiter_char (chr (car substring)))
          (if (/= "" (setq substring (vl-list->string (reverse (cdr substring)))))
          (setq out_list (append out_list (list substring delimiter_char)))
          (setq out_list (append out_list (list delimiter_char)))
        )
        (parse_string (setq char_list char_list_remainder) delimiter_string)
      )
      (if (/= "" (setq substring (vl-list->string (reverse substring))))
        (setq out_list (append out_list (list substring)))
      )
     )
     out_list
  )
  (parse_string char_list delimiter_string)
)

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

(defun c:add_value_texts (/ addition text_sset new_text_list do_add old_text_group)
  (if (null addition_saved) (setq addition_saved 1)) 
  (if (null (setq addition (getint (strcat "\nEnter addition +-number <" (itoa addition_saved) ">: "))))
	(setq addition addition_saved)
	(setq addition_saved addition)
  )
  (if (setq text_sset (ssget '((0 . "*text") (1 . "*#*"))))
    (foreach text (vl-remove-if 'listp (mapcar 'cadr (ssnamex text_sset)))
      (setq new_text_list nil do_add nil old_text_group (assoc 1 (entget text)))
      (foreach sub_string (string_to_list (cdr (setq old_text_group (assoc 1 (entget text)))) " ,;\\")
        (if (and (wcmatch (strcase sub_string) "*SEC*,*TO*")
                 (null do_add)
            )
            (setq do_add t)
        )
        (if (and (vl-every '(lambda (asc) (member asc (vl-string->list "0123456789")))
                   	    (vl-string->list sub_string)
                 )
                 do_add
            )
            (setq new_text_list (append new_text_list (list (itoa (+ (atoi sub_string) addition))))
            	  do_add nil
            )
            (setq new_text_list (append new_text_list (list sub_string)))
        )
      )
      (entmod (subst (cons 1 (apply 'strcat new_text_list)) old_text_group (entget text)))
    )
  )
  (princ)
)

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

 

 

 

Message 3 of 3

skchui6159
Advocate
Advocate

Exactly Great! Thank you very much for your help!😁👍

0 Likes