Jump to content

Recommended Posts

Posted

This code is to search each string of text and look for and increase a figure number by one, but only if its equal to or greater than 47...I think the IF with an IF is getting me.. any help would be appreciated. thanks in advance 

 

 

 

(vl-load-com)

(setq allt (ssget "X" '((0 . "text"))))

(setq I -1)
  (while (setq fignum (ssname allt (setq I (1+ I))))
    (setq Turbos1 (cdr (assoc 1 (entget fignum))))
    (setq tst (wcmatch Turbos1 "*FIG 2-??*"))
    
     (if (= tst T)
          (progn
    (setq ter (vl-string-search "-" turbos1))
    (setq terr (+ ter 2))
    (setq terrF (+ ter 1))
    (setq terr3 (+ terr 2))
    (setq front (strcase (substr Turbos1 1 terrF)))
    (setq wire (strcase (substr Turbos1 terr 2)))
    (setq back (strcase (substr Turbos1 terr3)))
    (setq div (atoi wire))
    ))
         

    
    (if (>= div 47)
     (progn
        (setq gage (+ div 1))
        (setq newfig (rtos gage 2 0))
        (setq newfigu (strcat front newfig back))
           (setq elist (entget fignum))
        (setq elist (subst (cons 1 newfigu)(assoc 1 elist) elist))
        (entmod elist)
        (entupd fignum)
           ))
    )

Posted

Can you show an example of your texts and which number you want to increase ? 

 

Posted
1 hour ago, Tharwat said:

Can you show an example of your texts and which number you want to increase ? 

 


(FIG 2-34)


FIG 2-56

 

SEE FIG 2-43

 

im trying to just increase the 2-“56” portion only if it’s above 47. The text could have brackets or text in fron or behind the “2-58”

Posted

I have just tried your code quickly and it appears to work for me, though it was just a quick test. Anything FIG 2-47 or greater gets incremented by 1. Note that I used the code below, which might not be your complete code of course - all I did was add a defun at the start and localised the variables

 

So I will ask you a question back, what is the problem with what you are doing? and are there any error messages as you run your routine - helps narrow down why it is not working.

 

 

 

(defun c:testthis ( / allt fignum Turbos1 I tst ter terr terrF terr3 front wire back div gage newfig newfigu elist )
  (vl-load-com)
  (setq allt (ssget "X" '((0 . "text"))))
  (setq I -1)
  (while (setq fignum (ssname allt (setq I (1+ I))))
    (setq Turbos1 (cdr (assoc 1 (entget fignum))))
    (setq tst (wcmatch Turbos1 "*FIG 2-??*"))

    (if (= tst T) ;if no.1
      (progn
        (setq ter (vl-string-search "-" turbos1))
        (setq terr (+ ter 2))
        (setq terrF (+ ter 1))
        (setq terr3 (+ terr 2))
        (setq front (strcase (substr Turbos1 1 terrF)))
        (setq wire (strcase (substr Turbos1 terr 2)))
        (setq back (strcase (substr Turbos1 terr3)))
        (setq div (atoi wire))
    )) ;end Progn, end if no.1
         
    (if (>= div 47) ;if no.2
      (progn
        (setq gage (+ div 1))
        (setq newfig (rtos gage 2 0))
        (setq newfigu (strcat front newfig back))
        (setq elist (entget fignum))
        (setq elist (subst (cons 1 newfigu)(assoc 1 elist) elist))
        (entmod elist)
        (entupd fignum)
    )) ;end progn, end if no.2
  ) ; end while
)

 

  • Like 1
Posted

Give this a shot and let me know.

(defun c:Test ( / int sel ent get str brk pos inc)
  ;;------------------------------------------------------------;;
  ;;	Author: Tharwat Al Choufi - Date: 07.Apr.2022		;;
  ;;	website: https://autolispprograms.wordpress.com		;;
  ;;------------------------------------------------------------;;
  (and (setq int -1 sel (ssget "_X" '((0 . "TEXT") (1 . "(FIG 2-##),(FIG 2-###),FIG 2-##,FIG 2-###"))))
       (while (setq int (1+ int) ent (ssname sel int))
         (and (setq get (entget ent))
              (setq str (cdr (assoc 1 get))
                    brk (wcmatch str "*)")
                    pos (vl-string-search "-" str)
                    )
              (or (< (setq inc (atoi (substr (if brk (vl-string-trim ")" str) str) (+ pos 2)))) 47)
                  (and (setq inc (1+ inc))
                       (entmod (subst (cons 1 (strcat (substr str 1 (1+ pos)) (itoa inc) (if brk ")" ""))) (assoc 1 get) get))
                       )
                  )
              )
         )
       )
  (princ)
  ) (vl-load-com)
                       
                       

 

  • Like 1
  • Thanks 1
Posted
54 minutes ago, Tharwat said:

Give this a shot and let me know.

(defun c:Test ( / int sel ent get str brk pos inc)
  ;;------------------------------------------------------------;;
  ;;	Author: Tharwat Al Choufi - Date: 07.Apr.2022		;;
  ;;	website: https://autolispprograms.wordpress.com		;;
  ;;------------------------------------------------------------;;
  (and (setq int -1 sel (ssget "_X" '((0 . "TEXT") (1 . "(FIG 2-##),(FIG 2-###),FIG 2-##,FIG 2-###"))))
       (while (setq int (1+ int) ent (ssname sel int))
         (and (setq get (entget ent))
              (setq str (cdr (assoc 1 get))
                    brk (wcmatch str "*)")
                    pos (vl-string-search "-" str)
                    )
              (or (< (setq inc (atoi (substr (if brk (vl-string-trim ")" str) str) (+ pos 2)))) 47)
                  (and (setq inc (1+ inc))
                       (entmod (subst (cons 1 (strcat (substr str 1 (1+ pos)) (itoa inc) (if brk ")" ""))) (assoc 1 get) get))
                       )
                  )
              )
         )
       )
  (princ)
  ) (vl-load-com)
                       
                       

 


Tharwat!! This works, thank you very much. 
 

for some strange reason I cannot get it to work in a macro toolbar button like all the rest but that’s ok, it works in a batch script and that’s ultimately what I need. Thanks again!!

Posted
4 hours ago, Steven P said:

I have just tried your code quickly and it appears to work for me, though it was just a quick test. Anything FIG 2-47 or greater gets incremented by 1. Note that I used the code below, which might not be your complete code of course - all I did was add a defun at the start and localised the variables

 

So I will ask you a question back, what is the problem with what you are doing? and are there any error messages as you run your routine - helps narrow down why it is not working.

 

 

 

(defun c:testthis ( / allt fignum Turbos1 I tst ter terr terrF terr3 front wire back div gage newfig newfigu elist )
  (vl-load-com)
  (setq allt (ssget "X" '((0 . "text"))))
  (setq I -1)
  (while (setq fignum (ssname allt (setq I (1+ I))))
    (setq Turbos1 (cdr (assoc 1 (entget fignum))))
    (setq tst (wcmatch Turbos1 "*FIG 2-??*"))

    (if (= tst T) ;if no.1
      (progn
        (setq ter (vl-string-search "-" turbos1))
        (setq terr (+ ter 2))
        (setq terrF (+ ter 1))
        (setq terr3 (+ terr 2))
        (setq front (strcase (substr Turbos1 1 terrF)))
        (setq wire (strcase (substr Turbos1 terr 2)))
        (setq back (strcase (substr Turbos1 terr3)))
        (setq div (atoi wire))
    )) ;end Progn, end if no.1
         
    (if (>= div 47) ;if no.2
      (progn
        (setq gage (+ div 1))
        (setq newfig (rtos gage 2 0))
        (setq newfigu (strcat front newfig back))
        (setq elist (entget fignum))
        (setq elist (subst (cons 1 newfigu)(assoc 1 elist) elist))
        (entmod elist)
        (entupd fignum)
    )) ;end progn, end if no.2
  ) ; end while
)

 

Thanks for your time to help resolve my issue.. Tharwats code is working for me .. but I was getting a blank “inspect” error.. so it was no help tracking down my mistakes.. 

 

thanks again

  • Like 1
Posted

No problem - I might grab this code too, might come in useful later

 

If I did that I would make a couple of small changes perhaps. Splitting it into 2 routines, the first one for the user to enter the 'prefix' (in this case 'FIG 2-'), the start number (in this case, 47) and perhaps the increment (+1), and then passing that to the other routine would make it more flexible, and doing it that way, text based, it would also work in a batch for me.

 

  • Like 1
Posted
51 minutes ago, Chad said:


Tharwat!! This works, thank you very much. 
 

for some strange reason I cannot get it to work in a macro toolbar button like all the rest but that’s ok, it works in a batch script and that’s ultimately what I need. Thanks again!!

You're welcome anytime. :) 

  • Thanks 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...