Jump to content

Recommended Posts

Posted

Hi everyone, I have this program that I made some time ago it does what it's expected, but I have this problem I recently added the Dialog box but I can't make the error handler to work. I explain myself.

When I run the program If you don't select any radio button -> nothing happens.

If you select any radio button but you don't put anything on the edit box. -> Still nothing happens.

And also the errtile doesn't appear.

And I supposedly added the error handler.

I hope you can enlighten me and show me where I'm failing and how to correct it.

Thanks in advance.pref v1.2en.lsppref.dcl

 

And Also by the way if you know a tutorial how to put the dcl into the lisp file. And how to add a Logo like those made by master Lee. Well Thanks again.

And hope you all have great hollidays.

Posted

Re add dcl to lisp you can simply write-line every line of the dcl to a file, make sure you allow for \" in the write line. Where quotes are required.

 

This uses a slide for a image display but also shows how to write the dcl in a file note the (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w")) this writes a temporary file and when done dialog deletes it.

; Getvals multi allows multiple line inputs with an image must be a slide image
; By Alan H Oct 2019
; code examples

; (if (not AH:getvalsimg)(load "Multi Getvals img.lsp"))
; (setq ans (AH:getvalsimg "D:\\Acadtemp\\furntable" 40 (list "Enter table size" "Enter length" 5 4 "1200" "Enter width" 5 4 "900" "Table thickness" 5 4 "30" "Enter height" 5 4 "900" "Enter Leg size" 5 4 "100")))


(defun AH:getvalsimg (img_name siz dcllst / x y num fo fname keynum key_lst v_lst)
(setq num (/ (- (length dcllst) 1) 4))
(setq x 0)
(setq y 0)
(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
;(setq fo (open (setq fname "d:\\acadtemp\\alantest.dcl") "w"))
(write-line "getvalsimg : dialog {" fo)
(write-line (strcat "label =  " (chr 34) (nth 0 dcllst) (chr 34) "  ; ") fo)
(write-line " : row {" fo)
(write-line "spacer ;" fo)
(write-line "  : column {" fo)
(write-line "spacer ;" fo)
(write-line "  : icon_image { " fo)
(write-line (strcat "  width =" (rtos siz 2 0) " ;") fo)
(write-line "  aspect_ratio = 1.0 ;" fo)
(write-line  (strcat "key = " (chr 34)  "Ah_img"  (chr 34) " ;") fo)
(write-line "  }" fo)
(write-line "  }" fo)
(write-line " : boxed_column {" fo)
(write-line "  width = 22 ;" fo)
(write-line "spacer_1 ;" fo)
(repeat num
(write-line ": edit_box {" fo)
(setq keynum (strcat "key" (rtos (setq y (+ Y 1)) 2 0)))
(write-line (strcat "    key = " (chr 34) keynum (chr 34) ";") fo)
(write-line (strcat " label = " (chr 34) (nth (+ x 1) dcllst) (chr 34) ";") fo)
(write-line (strcat "     edit_width = " (rtos (nth (+ x 2) dcllst) 2 0) ";") fo)
(write-line (strcat "     edit_limit = " (rtos (nth (+ x 3) dcllst) 2 0) ";") fo)
(write-line "   is_enabled = true ;" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(setq x (+ x 4))
)
(write-line "    }" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(write-line "ok_only;}" fo)
(close fo)

  (setq dcl_id (load_dialog fname))
  (if (not (new_dialog "getvalsimg" dcl_id))
    (exit)
  )
  (setq x 0)
  (setq y 0)
  (setq v_lst '())
  (repeat num
    (setq keynum (strcat "key" (rtos (setq y (+ Y 1)) 2 0)))
    (setq key_lst (cons keynum key_lst))
    (set_tile keynum (nth (setq x (+ x 4)) dcllst))
    (mode_tile keynum 3)
  )

      (start_image "Ah_img")
      (slide_image  0 0 (- (dimx_tile "Ah_img") 1) (- (dimy_tile "Ah_img") 1) img_name)
      (end_image)

  (action_tile "accept" "(mapcar '(lambda (x) (setq v_lst (cons (get_tile x) v_lst))) key_lst)(done_dialog)")
  (start_dialog)
  (unload_dialog dcl_id)
  (vl-file-delete fname)

  (princ v_lst)
)

I have not looked properly at your dcl and code, so no comment at this stage. Maybe later if no one else answers.

  • Like 1
Posted
3 hours ago, BIGAL said:

Re add dcl to lisp you can simply write-line every line of the dcl to a file, make sure you allow for \" in the write line. Where quotes are required.

 

This uses a slide for a image display but also shows how to write the dcl in a file note the (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w")) this writes a temporary file and when done dialog deletes it.


; Getvals multi allows multiple line inputs with an image must be a slide image
; By Alan H Oct 2019
; code examples

; (if (not AH:getvalsimg)(load "Multi Getvals img.lsp"))
; (setq ans (AH:getvalsimg "D:\\Acadtemp\\furntable" 40 (list "Enter table size" "Enter length" 5 4 "1200" "Enter width" 5 4 "900" "Table thickness" 5 4 "30" "Enter height" 5 4 "900" "Enter Leg size" 5 4 "100")))


(defun AH:getvalsimg (img_name siz dcllst / x y num fo fname keynum key_lst v_lst)
(setq num (/ (- (length dcllst) 1) 4))
(setq x 0)
(setq y 0)
(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
;(setq fo (open (setq fname "d:\\acadtemp\\alantest.dcl") "w"))
(write-line "getvalsimg : dialog {" fo)
(write-line (strcat "label =  " (chr 34) (nth 0 dcllst) (chr 34) "  ; ") fo)
(write-line " : row {" fo)
(write-line "spacer ;" fo)
(write-line "  : column {" fo)
(write-line "spacer ;" fo)
(write-line "  : icon_image { " fo)
(write-line (strcat "  width =" (rtos siz 2 0) " ;") fo)
(write-line "  aspect_ratio = 1.0 ;" fo)
(write-line  (strcat "key = " (chr 34)  "Ah_img"  (chr 34) " ;") fo)
(write-line "  }" fo)
(write-line "  }" fo)
(write-line " : boxed_column {" fo)
(write-line "  width = 22 ;" fo)
(write-line "spacer_1 ;" fo)
(repeat num
(write-line ": edit_box {" fo)
(setq keynum (strcat "key" (rtos (setq y (+ Y 1)) 2 0)))
(write-line (strcat "    key = " (chr 34) keynum (chr 34) ";") fo)
(write-line (strcat " label = " (chr 34) (nth (+ x 1) dcllst) (chr 34) ";") fo)
(write-line (strcat "     edit_width = " (rtos (nth (+ x 2) dcllst) 2 0) ";") fo)
(write-line (strcat "     edit_limit = " (rtos (nth (+ x 3) dcllst) 2 0) ";") fo)
(write-line "   is_enabled = true ;" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(setq x (+ x 4))
)
(write-line "    }" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(write-line "ok_only;}" fo)
(close fo)

  (setq dcl_id (load_dialog fname))
  (if (not (new_dialog "getvalsimg" dcl_id))
    (exit)
  )
  (setq x 0)
  (setq y 0)
  (setq v_lst '())
  (repeat num
    (setq keynum (strcat "key" (rtos (setq y (+ Y 1)) 2 0)))
    (setq key_lst (cons keynum key_lst))
    (set_tile keynum (nth (setq x (+ x 4)) dcllst))
    (mode_tile keynum 3)
  )

      (start_image "Ah_img")
      (slide_image  0 0 (- (dimx_tile "Ah_img") 1) (- (dimy_tile "Ah_img") 1) img_name)
      (end_image)

  (action_tile "accept" "(mapcar '(lambda (x) (setq v_lst (cons (get_tile x) v_lst))) key_lst)(done_dialog)")
  (start_dialog)
  (unload_dialog dcl_id)
  (vl-file-delete fname)

  (princ v_lst)
)

I have not looked properly at your dcl and code, so no comment at this stage. Maybe later if no one else answers.

Thanks Alan I'll try to follow your indications and see if I can get to put the dcl in the lsp file. One issue solved, just two more to go.

Posted

maybe like this :


(defun c:pref (/ as ct ln list1 name op prefi sufi text1 dialog)
   (setvar "cmdecho" 0)
   (vl-cmdf "_.undo" "_begin")
   ;(oldvars)
   ;(newvars)

   (setvar "osmode" 0)
   (princ "\nSelect the texts to be modified.")
   (setq list1 (ssget (list (cons 0 "TEXT,MTEXT"))))
   (if list1
      (progn
         (if (and (< 0 (setq dialog (load_dialog "pref.dcl")))
                  (new_dialog "pref" dialog)
             )
            (progn
               (action_tile "rb1" "(setq op \"Prefix\")
                                  (mode_tile \"eb1\" 0)
                                  (mode_tile \"eb2\" 1)
                                  (mode_tile \"eb1\" 2)"
               )
               (action_tile "rb2" "(setq op \"Suffix\")
                                  (mode_tile \"eb2\" 0)
                                  (mode_tile \"eb1\" 1)
                                  (mode_tile \"eb2\" 2)"
               )
               (action_tile "rb3" "(setq op \"Both\")
                                  (mode_tile \"eb1\" 0)
                                  (mode_tile \"eb2\" 0)
                                  (mode_tile \"eb1\" 2)"
               )
               (mode_tile "eb1" 2)            ;;; Focus on eb1
               (action_tile "cancel"
                    "(done_dialog)
                     (setq op nil)"
               )
               ;;; (action_tile "accept" "(setq prefi (get_tile \"eb1\"))(setq sufi (get_tile \"eb2\"))(valid)(done_dialog)")
               (action_tile "accept" "(setq prefi (get_tile \"eb1\"))(setq sufi (get_tile \"eb2\"))(validate)")
            )    ;;; End progn
         )     ;;; End if
         (start_dialog)
         (unload_dialog dialog)
         (setq ct 0
               ln (sslength list1)
         )    ;;; End setq
         (while (< ct ln)
            (setq name (entget (ssname list1 ct))
                  text1 (cdr (setq as (assoc 1 name))))
            (cond
               ((= op "Prefix") (setq text1 (strcat prefi text1)))
               ((= op "Suffix") (setq text1 (strcat text1 sufi)))
               ((= op "Both") (setq text1 (strcat prefi text1 sufi)))
           ((= op nil) )
            )
            (setq name (subst (cons 1 text1) as name))
            (entmod name)
            (setq ct (1+ ct))
         )    ;;; End while
      )        ;;; End progn
      (princ "\nThere are no selected texts")
   )        ;;; End if

   ;(reset)
   (vl-cmdf "_.undo" "_end")
   (princ "\n")
   (princ)
)

(defun validate ()
  (cond
    ;;; prefix only
    ((and (vl-every '(lambda (but val)(= (get_tile but) val)) '("rb1" "rb2" "rb3") '("1" "0" "0"))
          (not (void (get_tile "eb1")))) (done_dialog))
    ;;; suffix only
    ((and (vl-every '(lambda (but val)(= (get_tile but) val)) '("rb1" "rb2" "rb3") '("0" "1" "0"))
          (not (void (get_tile "eb2")))) (done_dialog))
    ;;; both prefix & suffix
    ((and (vl-every '(lambda (but val)(= (get_tile but) val)) '("rb1" "rb2" "rb3") '("0" "0" "1"))
          (not (void (get_tile "eb1")))(not (void (get_tile "eb2")))) (done_dialog))
    ;;; not some of the radio buts was selected
    ((not (vl-some '(lambda (x)(eq "1" (get_tile x))) '("rb1" "rb2" "rb3")))
     (alert "Invalid radio button selection"))
    ;;; prefix rb was selected but not a value in edit box
    ((and (= "1" (get_tile "rb1")) (= "0" (get_tile "rb2"))(void (get_tile "eb1")))
     (alert "Prefix is empty"))
    ;;; prefix rb was selected but not a value in edit box
    ((and (= "0" (get_tile "rb1")) (= "1" (get_tile "rb2")) (void (get_tile "eb2")))
     (alert "Suffix is empty"))
    ;;; whatever
    (t (alert "Data not complete"))
  )
)

; checks if variable is bound and if it is a string it's not empty
(defun void (x)(or (null x)(and (eq 'LIST (type x))(not (vl-consp x)))(and (eq 'STR (type x))(eq "" (vl-string-trim " \t\r\n" x)))))

🐉

  • Like 1
Posted
10 hours ago, rlx said:

maybe like this :

 


(defun c:pref (/ as ct ln list1 name op prefi sufi text1 dialog)
   (setvar "cmdecho" 0)
   (vl-cmdf "_.undo" "_begin")
   ;(oldvars)
   ;(newvars)

   (setvar "osmode" 0)
   (princ "\nSelect the texts to be modified.")
   (setq list1 (ssget (list (cons 0 "TEXT,MTEXT"))))
   (if list1
      (progn
         (if (and (< 0 (setq dialog (load_dialog "pref.dcl")))
                  (new_dialog "pref" dialog)
             )
            (progn
               (action_tile "rb1" "(setq op \"Prefix\")
                                  (mode_tile \"eb1\" 0)
                                  (mode_tile \"eb2\" 1)
                                  (mode_tile \"eb1\" 2)"
               )
               (action_tile "rb2" "(setq op \"Suffix\")
                                  (mode_tile \"eb2\" 0)
                                  (mode_tile \"eb1\" 1)
                                  (mode_tile \"eb2\" 2)"
               )
               (action_tile "rb3" "(setq op \"Both\")
                                  (mode_tile \"eb1\" 0)
                                  (mode_tile \"eb2\" 0)
                                  (mode_tile \"eb1\" 2)"
               )
               (mode_tile "eb1" 2)            ;;; Focus on eb1
               (action_tile "cancel"
                    "(done_dialog)
                     (setq op nil)"
               )
               ;;; (action_tile "accept" "(setq prefi (get_tile \"eb1\"))(setq sufi (get_tile \"eb2\"))(valid)(done_dialog)")
               (action_tile "accept" "(setq prefi (get_tile \"eb1\"))(setq sufi (get_tile \"eb2\"))(validate)")
            )    ;;; End progn
         )     ;;; End if
         (start_dialog)
         (unload_dialog dialog)
         (setq ct 0
               ln (sslength list1)
         )    ;;; End setq
         (while (< ct ln)
            (setq name (entget (ssname list1 ct))
                  text1 (cdr (setq as (assoc 1 name))))
            (cond
               ((= op "Prefix") (setq text1 (strcat prefi text1)))
               ((= op "Suffix") (setq text1 (strcat text1 sufi)))
               ((= op "Both") (setq text1 (strcat prefi text1 sufi)))
           ((= op nil) )
            )
            (setq name (subst (cons 1 text1) as name))
            (entmod name)
            (setq ct (1+ ct))
         )    ;;; End while
      )        ;;; End progn
      (princ "\nThere are no selected texts")
   )        ;;; End if

   ;(reset)
   (vl-cmdf "_.undo" "_end")
   (princ "\n")
   (princ)
)

(defun validate ()
  (cond
    ;;; prefix only
    ((and (vl-every '(lambda (but val)(= (get_tile but) val)) '("rb1" "rb2" "rb3") '("1" "0" "0"))
          (not (void (get_tile "eb1")))) (done_dialog))
    ;;; suffix only
    ((and (vl-every '(lambda (but val)(= (get_tile but) val)) '("rb1" "rb2" "rb3") '("0" "1" "0"))
          (not (void (get_tile "eb2")))) (done_dialog))
    ;;; both prefix & suffix
    ((and (vl-every '(lambda (but val)(= (get_tile but) val)) '("rb1" "rb2" "rb3") '("0" "0" "1"))
          (not (void (get_tile "eb1")))(not (void (get_tile "eb2")))) (done_dialog))
    ;;; not some of the radio buts was selected
    ((not (vl-some '(lambda (x)(eq "1" (get_tile x))) '("rb1" "rb2" "rb3")))
     (alert "Invalid radio button selection"))
    ;;; prefix rb was selected but not a value in edit box
    ((and (= "1" (get_tile "rb1")) (= "0" (get_tile "rb2"))(void (get_tile "eb1")))
     (alert "Prefix is empty"))
    ;;; prefix rb was selected but not a value in edit box
    ((and (= "0" (get_tile "rb1")) (= "1" (get_tile "rb2")) (void (get_tile "eb2")))
     (alert "Suffix is empty"))
    ;;; whatever
    (t (alert "Data not complete"))
  )
)

; checks if variable is bound and if it is a string it's not empty
(defun void (x)(or (null x)(and (eq 'LIST (type x))(not (vl-consp x)))(and (eq 'STR (type x))(eq "" (vl-string-trim " \t\r\n" x)))))

🐉

Thanks a lot, this is how it should have been since the begining. It works perfectly. I'm sorry for the late answer but I was busy.

Posted

And about a logo made by vectors, does anyone have a hint.

Posted

hint.... did you look at Lees code where he used his logo. Should be looking at an image tile if that is any help

Posted
50 minutes ago, Steven P said:

hint.... did you look at Lees code where he used his logo. Should be looking at an image tile if that is any help

Thanks, I still don't know much about it, but that's a good start, thanks. Thank you all for your help.

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