Author Topic: help with alert box  (Read 387 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Bull Frog
  • Posts: 359
help with alert box
« on: July 27, 2022, 03:37:23 AM »
Hi i am using this lisp code to set the scale in the drawing. All my lisp codes are connected with lisp so i don't whant to change it

Code - Auto/Visual Lisp: [Select]
  1. ( DEFUN C:SETSC ()
  2.   (setvar "OSMODE" 13)
  3.     (SETQ CURSC (getvar "useri1" ))
  4.     (princ " drawing scale is 1:")(princ cursc)
  5.     (setq newsc (getint "\nNew scale is  1:"))
  6.     (setvar "useri1" newsc)
  7.       (setq a1 (getvar "useri1"))
  8. )
  9.  

Sometimes i forget to set the scale in the beginning so some lisp codes is not running properly. To fix this problem, i want to add a scale check in the beginning of any code.


Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2.   (if (setq s (getvar 'useri1))
  3.     (princ (strcat "\n The drawing scale is 1:" (itoa s)))
  4.     (if (not (atoms-family 0 '("setsc")))
  5.       (alert "Scale not set. Aborting ... ")
  6.       (progn
  7.         (c:setsc)
  8.         (setq s (getvar 'useri1))
  9.       )
  10.     )
  11.   )
  12. )

I write this code but the     (alert "Scale not set. Aborting ... ") is not a pop up box but write it in the command line ,and some times is difficult to see it. Can any on help me to become a pop up  alert box ?

Thanks

kdub

  • Mesozoic keyThumper
  • SuperMod
  • Swamp Rat
  • Posts: 1463
  • class keyThumper<T>:ILazy<T>
Re: help with alert box
« Reply #1 on: July 27, 2022, 05:17:41 AM »
Perhaps . . does this give you the result you want ??

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ s)
  2.   (if (setq s (getvar 'useri1))
  3.     (progn
  4.       (princ (strcat "\n The drawing scale is 1:" (itoa s)))
  5.       (if (not (atoms-family 0 '("c:setsc")))
  6.         (alert "Scale not set. Aborting ... ")
  7.         (progn
  8.           (c:setsc)
  9.           (setq s (getvar 'useri1))
  10.         )
  11.       )
  12.     )
  13.   )
  14.   (princ)
  15. )

I don't see how you are setting the scale in any form , just setting a userVariable.

. . . the problem with that is that anyone has access to the variables and the value can be changed by any program.

added:  also, what are the chances you will require a value of (say ) 7.5 . the integer will not make that ossible
Regards,
« Last Edit: July 27, 2022, 05:25:45 AM by kdub »
called Kerry in my other life

Sometimes the question is more important than the answer.

I don't really work crazy hours . . I just live at UTC + 12.00
#ridesober

PM

  • Bull Frog
  • Posts: 359
Re: help with alert box
« Reply #2 on: July 27, 2022, 01:03:29 PM »
Hi  kdub. Thanks for the replay. I did this change


Code - Auto/Visual Lisp: [Select]
  1.        (defun c:test (/ s)
  2.       (if (setq s (getvar 'useri1))
  3.      (progn
  4.           ;(princ (strcat "\n The drawing scale is 1:" (itoa s)))
  5.         (alert (strcat "\n The drawing scale is 1:" (itoa s)))
  6.           (if (not (atoms-family 0 '("c:setsc")))
  7.             (alert "Scale is set. Aborting ... ")
  8.             (progn
  9.               (c:setsc)
  10.               (setq s (getvar 'useri1))
  11.             )
  12.           )
  13.         )
  14.       )
  15.       (princ)
  16.     )
  17.  

This code is not working as i expected. I want If scale is 0 then (c:setsc) and set a scale, if  scale is another number like (50,100,200,250,500 etc) then skip the check . Now  if scale is 0 or other number  all the times  go to (c:setsc). I don't want this.

Any ideas?

Thanks

BIGAL

  • Swamp Rat
  • Posts: 1037
  • 40 + years of using Autocad
Re: help with alert box
« Reply #3 on: July 27, 2022, 09:01:16 PM »
You can compare user1 to a list (100 200 250 500 ...) If = item in list then skip
A man who never made a mistake never made anything

kdub

  • Mesozoic keyThumper
  • SuperMod
  • Swamp Rat
  • Posts: 1463
  • class keyThumper<T>:ILazy<T>
Re: help with alert box
« Reply #4 on: July 27, 2022, 09:37:47 PM »
PM, perhaps ...
Code - Auto/Visual Lisp: [Select]
  1. (DEFUN C:SETSC ()
  2.   (setvar "OSMODE" 13)
  3.   (princ (strcat "\nThe drawing scale is 1:" (itoa (getvar 'useri1)))  )
  4.   (setvar "useri1" (getint "\nSET New scale 1:"))  
  5.   (princ)
  6. )
  7.  

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2.   (if (zerop (getvar 'useri1))
  3.     (if (not (atoms-family 0 '("c:setsc")))
  4.       (alert "Unable to find 'c:setsc'. Aborting ... ")
  5.       ;;else
  6.       (c:setsc)
  7.     )
  8.   )
  9.   ;;(princ (strcat "\n The drawing scale is 1:" (itoa (getvar "useri1"))))
  10.   (alert (strcat "\n The drawing scale is 1:" (itoa (getvar "useri1"))))
  11.   (princ)
  12. )

If value is 0 , invoke c:SETSC (from c:TEST )
If you want to force a change, just invoke c:SETSC from the commandLine.

I assume you are setting the scale from another routine which reads the variable.

Regards


called Kerry in my other life

Sometimes the question is more important than the answer.

I don't really work crazy hours . . I just live at UTC + 12.00
#ridesober

PM

  • Bull Frog
  • Posts: 359
Re: help with alert box
« Reply #5 on: July 28, 2022, 02:20:57 AM »
Thanks for the help kdub , BIGAL

Regards

Lee Mac

  • Seagull
  • Posts: 12696
  • London, England
Re: help with alert box
« Reply #6 on: July 28, 2022, 08:22:15 AM »
Note that this -
Code - Auto/Visual Lisp: [Select]
  1. (if (not (atoms-family 0 '("c:setsc")))

Will never be validated, since even if the symbol "c:setsc" is not found (i.e. not defined), the atoms-family function will return the list (nil), which is non-null.

Though rather than using car to check whether the first element of the list is non-null, the expression could be more optimally written as:
Code - Auto/Visual Lisp: [Select]
  1. (if (not c:setsc)

VovKa

  • Swamp Rat
  • Posts: 1474
  • Ukraine
Re: help with alert box
« Reply #7 on: July 28, 2022, 02:53:46 PM »
I write this code but the     (alert "Scale not set. Aborting ... ") is not a pop up box but write it in the command line ,and some times is difficult to see it. Can any on help me to become a pop up  alert box ?
Code: [Select]
(setvar "QAFLAGS" (logand (getvar "QAFLAGS") -5))

PM

  • Bull Frog
  • Posts: 359
Re: help with alert box
« Reply #8 on: July 28, 2022, 03:55:18 PM »
I did some change but the alert box is not working. All the text show in the command line  :idea:

Code - Auto/Visual Lisp: [Select]
  1. (if (zerop (getvar 'useri1))
  2.        (if (not (atoms-family 0 '("c:setsc")))
  3.        ;(if (not c:setsc)
  4.           (alert "The drawing scale is not set !!!!")
  5.           ;;else
  6.           (c:setsc)
  7.         ) ; end if
  8.       (alert (strcat "\nThe drawing scale is 1:" (itoa (getvar "useri1"))))  
  9. ) ; end if
  10.  

Any other ideas?
Thanks

kdub

  • Mesozoic keyThumper
  • SuperMod
  • Swamp Rat
  • Posts: 1463
  • class keyThumper<T>:ILazy<T>
Re: help with alert box
« Reply #9 on: July 28, 2022, 05:41:31 PM »
PM
as Lee mentioned, swap these statements :

Code: [Select]
       (if (not c:setsc)
       in place  of

Code: [Select]
       (if (not (atoms-family 0 '("c:setsc")))       

called Kerry in my other life

Sometimes the question is more important than the answer.

I don't really work crazy hours . . I just live at UTC + 12.00
#ridesober

ronjonp

  • Needs a day job
  • Posts: 7437
Re: help with alert box
« Reply #10 on: July 28, 2022, 05:41:44 PM »
You could flip your logic too:
Code - Auto/Visual Lisp: [Select]
  1. (if (= 0 (getvar 'useri1))
  2.   (if c:setsc
  3.     (c:setsc)
  4.     (alert "The drawing scale is not set !!!!")
  5.   )
  6.   (alert (strcat "\nThe drawing scale is 1:" (itoa (getvar "useri1"))))
  7. )

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

kdub

  • Mesozoic keyThumper
  • SuperMod
  • Swamp Rat
  • Posts: 1463
  • class keyThumper<T>:ILazy<T>
Re: help with alert box
« Reply #11 on: July 28, 2022, 05:44:42 PM »
I write this code but the     (alert "Scale not set. Aborting ... ") is not a pop up box but write it in the command line ,and some times is difficult to see it. Can any on help me to become a pop up  alert box ?
Code: [Select]
(setvar "QAFLAGS" (logand (getvar "QAFLAGS") -5))

Nice safety procedure VovKa !!

called Kerry in my other life

Sometimes the question is more important than the answer.

I don't really work crazy hours . . I just live at UTC + 12.00
#ridesober

PM

  • Bull Frog
  • Posts: 359
Re: help with alert box
« Reply #12 on: July 30, 2022, 01:41:41 AM »
Thank you all for the help