Warning message before applying a function

Warning message before applying a function

Anonymous
Not applicable
671 Views
6 Replies
Message 1 of 7

Warning message before applying a function

Anonymous
Not applicable

I have a simple lisp which I want to have a warning dialogue window (Yes to accept /No to exit) to prevent any accidentally running this lisp.

 

(defun c:deltext ( / ss )
(setq ss (ssget "x" (list (cons 0 "text"))))
(if ss
(command ".erase" ss "")
(princ "\nNo text in this drawing!")
)
(princ)
) 

Thanks

0 Likes
Accepted solutions (2)
672 Views
6 Replies
Replies (6)
Message 2 of 7

hmsilva
Mentor
Mentor
Accepted solution

Something like this, perhaps

 

(defun c:deltext (/ ss)
  (if (and (setq ss (ssget "x" (list (cons 0 "text"))))
           (= (ACET-UI-MESSAGE
                "Do you want to delete all texts?"
                "You are about to delete all texts!!!"
                (+ Acet:YESNO Acet:ICONQuestion)
              )
              6
           )
      )
    (command ".erase" ss "")
    (princ "\nNo text in this drawing!")
  )
  (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 3 of 7

pbejse
Mentor
Mentor

@hmsilva wrote:

Something like this, perhaps

 

(defun c:deltext (/ ss)
  ....
  (princ)
)

 

Hope this helps,
Henrique


Me like it 🙂

0 Likes
Message 4 of 7

hmsilva
Mentor
Mentor

@pbejse wrote:
Me like it 🙂

Hi pBe, nice hearing from you! Smiley Happy

 

Henrique

EESignature

0 Likes
Message 5 of 7

Anonymous
Not applicable

Thank you all

0 Likes
Message 6 of 7

Anonymous
Not applicable

and if I want to add this  warning message to attached lisp, what will be the code?

 

(defun c:UnDynamic

    (   /
        _get_item
        _right
        _make_key
        _dynamic->static_block
        _get_locked
        _get_dynamic_inserts
        _main
    )

    (defun _get_item ( collection key / item )
        (vl-catch-all-apply
           '(lambda ( ) (setq item (vla-item collection key)))
        )
        item
    )

    (defun _right ( str n / len )
        (if (< n (setq len (strlen str)))
            (substr str (1+ (- len n)))
            str
        )
    )

    (defun _make_key ( collection prefix len / key )
        (   (lambda ( i pad )
                (while
                    (_get_item collection
                        (setq key
                            (strcat prefix
                                (_right
                                    (strcat pad (itoa (setq i (1+ i))))
                                    len
                                )
                            )
                        )
                    )
                )
                key
            )
            0
            (   (lambda ( pad )
                    (while (< (strlen pad) len)
                        (setq pad (strcat "0" pad))
                    )
                    pad
                )
                ""
            )
        )
    )

    (defun _dynamic->static_block ( blocks insert len )
        (vla-ConvertToStaticBlock
            insert
            (_make_key blocks "STATIC_" len)
        )
    )

    (defun _get_locked ( layers / locked )
        (vlax-for layer layers
            (if (eq :vlax-true (vla-get-lock layer))
                (setq locked (cons layer locked))
            )
        )
        locked
    )

    (defun _get_dynamic_inserts ( blocks / inserts )
        (vlax-for block blocks
            (vlax-for object block
                (if (eq "AcDbBlockReference" (vla-get-objectname object))
                    (if (eq :vlax-true (vla-get-isdynamicblock object))
                        (setq inserts (cons object inserts))
                    )
                )
            )
        )
        inserts
    )

    (defun _main ( document / blocks inserts locked len )
        (if
            (setq inserts
                (_get_dynamic_inserts
                    (setq blocks (vla-get-blocks document))
                )
            )
            (progn
                (foreach layer (setq locked (_get_locked (vla-get-layers document)))
                    (vla-put-lock layer :vlax-false)
                )
                (setq len (strlen (itoa (length inserts))))
                (foreach insert inserts
                    (_dynamic->static_block blocks insert len)
                )
                (foreach layer locked
                    (vla-put-lock layer :vlax-true)
                )
            )
        )
        (princ)
    )

    (_main (vla-get-activedocument (vlax-get-acad-object)))

)

Thanks

0 Likes
Message 7 of 7

hmsilva
Mentor
Mentor
Accepted solution

Change

(_main (vla-get-activedocument (vlax-get-acad-object)))

to

 

(if (= (ACET-UI-MESSAGE
           "Do you want to convert to static all dynamic blocks?"
           "You are about to convert to static all dynamic blocks!!!"
           (+ Acet:YESNO Acet:ICONWARNING)
         )
         6
      )
    (_main (vla-get-activedocument (vlax-get-acad-object)))
  )

 

Hope this helps,
Henrique

EESignature