Jump to content

Display alert massage only one time


Halsy

Recommended Posts

Hi friends I need lisp code for display alert massage one first time use of function. When user use that command then that alert massage don't shown on screen

 

 

Edited by Halsy
Link to comment
Share on other sites

(defun c:scpanel (/ p1 p2 p3 p4 p5 p6 p7 left right oldsnap)
(alert " Please use Maximum number of 400 SC 400")
(setq p1 (getpoint "\ pick a corner point: "))
(setq oldsnap (getvar ' osmode))
(setvar ' osmode 0)
(setq left (getreal "\ Enter Leftside of panel: ")
         right (getreal "\ Enter Rightside of panel: ")

(setq p2 (polar p1 (* pi 1.5) left)
          p3 (polar p2 0 100)
          p4 (polar p3 ( / pi 2) (- left 100))
          p5 (polar p1 0 right)
          p6 (polar p4 0 (- right 100))
      )
(command "pline" p1 p2 p3 p4 p6 p5 p1 "c")(setq s(entlast))
(command ".text" p4 65 0 (strcat  (rtos left 2 0 ) " SC " (rtos right 2 0 ) ))(setq s1(entlast))
(setvar ' osmode oldsnap)
(repeat 2
(setq ang (getangle "\nEnter Rotation angle: "))
(setq ang1 (* 180.0 (/ ang pi)))
(command "rotate" s s1 "" p1 ang1 "")
)
(princ)
)

Link to comment
Share on other sites

Try 

(defun c:scpanel (/ p1 p2 p3 p4 p5 p6 p7 left right oldsnap)
(if ±×alert×± 
  (alert " Please use Maximum number of 400 SC 400")
  (setq ±×alert×± 1)
)
(setq p1 (getpoint "\ pick a corner point: "))
(setq oldsnap (getvar ' osmode))
(setvar ' osmode 0)
(setq left (getreal "\ Enter Leftside of panel: ")
         right (getreal "\ Enter Rightside of panel: ")
) 
(setq p2 (polar p1 (* pi 1.5) left)
          p3 (polar p2 0 100)
          p4 (polar p3 ( / pi 2) (- left 100))
          p5 (polar p1 0 right)
          p6 (polar p4 0 (- right 100))
      )
(command "pline" p1 p2 p3 p4 p6 p5 p1 "c")(setq s(entlast))
(command ".text" p4 65 0 (strcat  (rtos left 2 0 ) " SC " (rtos right 2 0 ) ))(setq s1(entlast))
(setvar ' osmode oldsnap)
(repeat 2
(setq ang (getangle "\nEnter Rotation angle: "))
(setq ang1 (* 180.0 (/ ang pi)))
(command "rotate" s s1 "" p1 ang1 "")
)
(princ)
)

 

Link to comment
Share on other sites

Try swapping:

(if ±×alert×± 
  (alert " Please use Maximum number of 400 SC 400")
  (setq ±×alert×± 1)
)

 

to

 

(if (= myalert nil)
  (progn
    (setq myalert 1)
    (alert " Please use Maximum number of 400 SC 400")
  )
)

 

Edited by Steven P
A correction
Link to comment
Share on other sites

adding to this, the alert will show first time you use the command each session for each drawing, you might also look at saving the values of myalert into a registery key similar to this

 

(if (eq (vl-registry-read "HKEY_CURRENT_USER\\Software\\TOMMY\\TIMMY") "1")(ALERT "THE KEY EXISTS AND IS SET TO 1") (Alert "THE KEY DOES NOT EXIST"))

 

which will show the alert only once until you reset the registry key

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-registry-key-value-and-process-it/td-p/3733306 )

Link to comment
Share on other sites

2 hours ago, Halsy said:

when i use scpanel command then alert is not come on the screen but 2 time of use it come on the screen 

i need only one time when command runs for 1st time

@Halsy

Try something like this: 

(or (getenv "NameYouWantToUse") (progn (alert "Hello World!") (setenv "NameYouWantToUse" "Ran")))

 

  • Like 1
Link to comment
Share on other sites

  

On 9/17/2021 at 5:48 PM, Halsy said:

Hi friends I need lisp code for display alert massage one first time use of function. When user use that command then that alert massage don't shown on screen

 

 

If you want to display the message for the first time of that certain lisp call and for each ACAD session, then apparently you'll have to use a reactor:

 

(defun c:scpanel (/ p1 p2 p3 p4 p5 p6 p7 left right oldsnap)
  ; (alert " Please use Maximum number of 400 SC 400")
  (setq p1 (getpoint "\ pick a corner point: "))
  (setq oldsnap (getvar ' osmode))
  (setvar ' osmode 0)
  (setq left (getreal "\ Enter Leftside of panel: ")
    right (getreal "\ Enter Rightside of panel: ")
  ) 
  (setq p2 (polar p1 (* pi 1.5) left)
    p3 (polar p2 0 100)
    p4 (polar p3 ( / pi 2) (- left 100))
    p5 (polar p1 0 right)
    p6 (polar p4 0 (- right 100))
  )
  (command "pline" p1 p2 p3 p4 p6 p5 p1 "c")(setq s(entlast))
  (command ".text" p4 65 0 (strcat  (rtos left 2 0 ) " SC " (rtos right 2 0 ) ))(setq s1(entlast))
  (setvar ' osmode oldsnap)
  (repeat 2
    (setq ang (getangle "\nEnter Rotation angle: "))
    (setq ang1 (* 180.0 (/ ang pi)))
    (command "rotate" s s1 "" p1 ang1 "")
  )
  (princ)
)


(
  (lambda ( rnm cmd msg )
    ; Alert once code snippet by Grrr
    (setq cmd (strcase cmd))
    (foreach rtr (cdar (vlr-reactors :vlr-lisp-reactor)) (if (= cmd (vlr-data rtr)) (vlr-remove rtr)) )
    (eval (list (quote VLR-Lisp-Reactor) (quote cmd) (list (quote quote) (list (cons :VLR-lispWillStart rnm)))))
    
    (eval 
      (list 'defun rnm (list 'rtr 'arg '/ 'rtn)
        (list	'cond
          (list 
            (list '= cmd (list 'car 'arg))
            (list 'alert msg)
            (list 'vlr-remove 'rtr)
            (list 'setq rnm nil)
          )
        )
        (list 'princ)
      )
    ); eval 
    
  ); lambda 
  'SCpanel:AlertOnce:CB ; Reactor's callback function name
  "(C:SCPANEL)" ; The lisp command call to trace
  " Please use Maximum number of 400 SC 400" ; The alert message 
)

 

See the lambda code snippet below of your code and adjust the arguments for your needs. ;)

 

Edited by Grrr
Link to comment
Share on other sites

On 9/17/2021 at 11:39 AM, Halsy said:

when i use scpanel command then alert is not come on the screen but 2 time of use it come on the screen 

i need only one time when command runs for 1st time

@Halsy

Food for thought:

(defun c:scpanel (/ ang ang1 left oldsnap p1 p2 p3 p4 p5 p6 right s s1)
  ;; Run once daily
;;;  (or (= (rtos (getvar 'cdate) 2 0) (getenv "NameYouWantToUse"))
;;;      (progn (alert "Hello World!") (setenv "NameYouWantToUse" (rtos (getvar 'cdate) 2 0)))
;;;  )
  ;; Check your input rather than alerting once daily your rules
  (cond	((and (setq p1 (getpoint "\nPick a corner point: "))
	      (< (setq left (getreal "\nEnter Leftside of panel: ")) 400)
	      (< (setq right (getreal "\nEnter Rightside of panel: ")) 400)
	 )
	 (setq oldsnap (getvar 'osmode))
	 (setvar 'osmode 0)
	 (setq p2 (polar p1 (* pi 1.5) left)
	       p3 (polar p2 0 100)
	       p4 (polar p3 (/ pi 2) (- left 100))
	       p5 (polar p1 0 right)
	       p6 (polar p4 0 (- right 100))
	 )
	 (command "pline" p1 p2 p3 p4 p6 p5 p1 "c")
	 (setq s (entlast))
	 (command ".text" p4 65 0 (strcat (rtos left 2 0) " SC " (rtos right 2 0)))
	 (setq s1 (entlast))
	 (setvar 'osmode oldsnap)
	 (repeat 2
	   (setq ang (getangle "\nEnter Rotation angle: "))
	   (setq ang1 (* 180.0 (/ ang pi)))
	   (command "rotate" s s1 "" p1 ang1 "")
	 )
	)
	((alert "Please use Maximum number of 400"))
  )
  (princ)
)

 

Edited by ronjonp
Link to comment
Share on other sites

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...