Author Topic: Simple function to add 1 to collected value  (Read 1741 times)

0 Members and 1 Guest are viewing this topic.

tdeleske

  • Mosquito
  • Posts: 20
Simple function to add 1 to collected value
« on: December 21, 2017, 10:57:49 AM »
Hello, I have some lisp code I have been hacking through, it works great except I am not sure how to build it to add 1 to a user entered numerical value.
I have uploaded the code, currently it asks for placement alignment between two lines, then asks for lower township value then for township upper value.
Since the upper value is always +1 to the lower value I would prefer to not ask the user for the upper value but rather just give it to them and finish the routine after the first value is entered.
The specific function is "TwpBdyLabel"
can I ask for someone to show me what I need to do that?

Regards

Trevor

BKT

  • Newt
  • Posts: 27
Re: Simple function to add 1 to collected value
« Reply #1 on: December 21, 2017, 11:36:51 AM »
Assuming the Township number is always an integer, I think you could do something like this:

Code: [Select]
;;(setq TNumTop (getstring T "\nEnter the upper Township Number:"))
  (setq TNumBot (getstring T "\nEnter the lower Township Number:"))
  (setq TNumTop (itoa (1+ (atoi TNumBot))))

I just commented out the original TNumTop and replaced it.
Disclaimer: Not tested...

tdeleske

  • Mosquito
  • Posts: 20
Re: Simple function to add 1 to collected value
« Reply #2 on: December 21, 2017, 11:42:22 AM »
I tried that and works great!
thank you so much. I kinda thought it may be a small fix.
Kudos sir!

Regards
Trevor

dubb

  • Swamp Rat
  • Posts: 1105
Re: Simple function to add 1 to collected value
« Reply #3 on: December 21, 2017, 11:43:46 AM »
Here is my first crack at it.

Code: [Select]
  ;(setq TwpNumTop (getstring T "\nEnter the upper Township Number:"))
  (setq TwpNumBot (getint "\nEnter the lower Township Number:"))
(setq TwpNumTop (+ 1 TwpNumBot))
  (setq twp2 (strcat "TWP." (itoa TwpNumTop)))
  (setq twp1 (strcat "TWP." (itoa TwpNumBot)))

Code: [Select]
(defun c:TwpBdyLabel()

       
  (defun SETERR (s)
    (if (/= s "Function cancelled")
      (princ (strcat "\nError: " s))
    ) ; of If
    (setq *error* oer
  seterr nil
    )
    (setvar "osmode" os)
   
    (command "-layer" "s" cl "")
    (princ)
  ) ; of SETERR
  (setq oer *error*
*error* seterr
  )
  (setq os (getvar "OSMODE"))
 
  (setq cl (getvar "clayer"))
 
  (command "_.LAYER" "S" "TXT-SEC" "")
  (command "OSNAP" "nea")
  (setq pt01 (getpoint "Pick South Boundary:"))
  (setvar "OSMODE" 128)
  (setq pt02 (getpoint pt01 "\nPick perpendicular Boundary:"))
  (setvar "OSMODE" 0)
 
  (setvar "OSMODE" 0)
  (setq azm (angle pt01 pt02))

    (if (or (> azm 3.14) (< azm 6.28))
    (setq insang (- azm 3.141592))
  )
  (if (or (< azm 3.14) (> azm 6.28))
    (setq insang azm)
  )
  (setq insang (rtd insang))
  (setq insang1 (- 90 insang))
  (if (<= insang 10)
    (setq insang1 (+ insang1 180))
  )   

  (setq TwpNumTop 0)
  (setq TwpNumBot 0)
 
  ;(setq TwpNumTop (getstring T "\nEnter the upper Township Number:"))
  (setq TwpNumBot (getint "\nEnter the lower Township Number:"))
(setq TwpNumTop (+ 1 TwpNumBot))
  (setq twp2 (strcat "TWP." (itoa TwpNumTop)))
  (setq twp1 (strcat "TWP." (itoa TwpNumBot)))

  ;INSERTION POINTS
  (setq pt01_i (polar pt01 (angle pt02 pt01) 13.78))
  (setq pt02_i (polar pt02 (angle pt01 pt02) 13.78))
 
  (setq oldstyle (getvar "textstyle"))
  (command "style" "A100" "" "Anno" "Y" "N" "2.5" "1.00" "0" "N" "N")
  (command "._mText" pt01_i  "j" "TC" "R" insang1 "w" "0"  twp1 "")
  (MTM1) ;apply background mask
  (command "._mText" pt02_i  "j" "BC" "R" insang1 "w" "0"  twp2 "")
  (MTM1) ;apply background mask

(setvar "textstyle" oldstyle)
(setvar "clayer" cl)
 
)

tdeleske

  • Mosquito
  • Posts: 20
Re: Simple function to add 1 to collected value
« Reply #4 on: December 21, 2017, 11:52:34 AM »
Hey Dubb, I tried that and also works great!
thanks for your help!
kudos!

Regards
Trevor