Author Topic: Icon can not display  (Read 6622 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
Icon can not display
« on: December 07, 2006, 11:29:17 PM »
Hi Alls,
I'm attempt to "recreating" code from "Terry Miller",to more simple and easy to understand,here that code,what am I do wrong with this code.
LSP File
Code: [Select]
(defun *create_icon* (lst / cnt col x x1 x2 y y1 y2)
  (if
    (= (type lst) 'list)                             
    (progn
      (setq cnt 0)                                   
      (repeat
(/ (length lst) 2)                           
        (setq x (nth cnt lst))                       
(setq y (nth (+ cnt 1) lst))                 
        (if
  (and (= (type x) 'str)(= (type y) 'int))   
          (if
    (= (strcase x "c"))                     
    (progn
      (setq col y)                           
      (setq x1 nil)                         
      (setq y1 nil)                         
      (setq x2 nil)                         
      (setq y2 nil)                         
      )                                      ; progn
    )                                        ; if
         (if
    (and (= (type x) 'int) (= (type y) 'int))
            (if
      (and (= x1 nil) (= y1 nil))           
      (progn
(setq x1 x)                         
(setq y1 y)                         
)                                    ; progn
      (progn
(setq x2 x)                         
(setq y2 y)                         
(vector_image x1 y1 x2 y2 col)
(setq x1 x2)                         
(setq y1 y2)                         
(setq x nil)                         
(setq y nil)                         
               )                                     ; progn
      )                                      ; if
    )                                        ; if
  )                                          ; if
)                                            ; repeat
     (setq cnt (+ cnt 2))
      )                                              ; progn
    )                                                ; if
  )                                                  ; defun

(defun *smile* ( )
  (start_image "smile")
  (*create_icon* lst1)
  (*create_icon* lst2)
  (*create_icon* lst3)
  (end_image)
  )                         ; defun


(defun c:ci (/ dcl_id ans)
  (setq dcl_id (load_dialog "Create Icon.DCL"))
  (if
    (not (new_dialog "ci" dcl_id))
    (exit)
    )                                                      ; if
  (setq lst1 (list "C" 2 2 12 2 19 "C" 2 3 9 3 22 4 23 4 8 "C" 2 5 6 5 25 6
    26 6 5 7 5 7 26 8 27 8 4 9 3 9 28 10 28 10 3 11 3 11 28 12 29 12 2 13 2
    13 29 14 29 14 2 15 2 15 29 16 29 16 2 17 2 17 29 18 29 18 2 19 2 19 29
    20 28 20 3 21 3 21 28 22 28 22 3 23 4 23 27 24 26 24 5 25 5 25 26 26 25
    26 6 "C" 2 27 8 27 23 28 22 28 9 "C" 2 29 19 29 12))
  (setq lst2 (list "C" 250 12 30 19 30 20 29 22 29 24 27 25 27 27 25 27 24
    29 22 29 20 30 19 30 12 29 11 29 9 27 7 27 6 25 4 24 4 22 2 20 2 19 1 12
    1 11 2 9 2 7 4 6 4 4 6 4 7 2 9 2 11 1 12 1 19 2 20 2 22 4 24 4 25 6 27 7
    27 9 29 11 29 "C" 250 6 18 8 20 9 20 10 21 12 21 13 22 18 22 19 21 21 21
    22 20 23 20 25 18 "C" 250 11 12 11 10 12 9 12 13 13 12 13 10 "C" 250 18
    12 18 10 19 9 19 13 20 12 20 10))
  (setq lst3 (list "C" 8 7 28 8 29 "C" 8 14 32 21 32 "C" 8 10 30 11 30 11
    31 24 31 25 30 20 30 "C" 8 27 29 23 29 24 28 28 28 29 27 26 27 27 26 29
    26 29 23 28 24 28 25 "C" 8 30 20 30 25 31 24 31 11 30 11 30 10 "C" 8 32
    21 32 14 "C" 8 28 7 29 8))
  (*smile*) 
  (setq ans (start_dialog))
  (unload_dialog dcl_id)
  (princ)
  )                                                        ; defun
and here DCL File
Code: [Select]
ci : dialog {label = "SAMPLE CREATE ICON";                         
   spacer;
   : row {
   : column {
   : image {key = "smile";
            width = 5.42;
            height = 2.51;
            fixed_width = true;
            fixed_height = true;
            aspect_ratio = 1;
            color = -15;
            alignment = centered;}}}     
    spacer;
   : ok_button{is_cancel = true;}}





Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Icon can not display
« Reply #1 on: December 07, 2006, 11:50:41 PM »
Hi Alls,
 ... what am I do wrong with this code.


Adesu,
What is the problem that you see ?

/// kwb
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: Icon can not display
« Reply #2 on: December 08, 2006, 12:20:08 AM »
More to the point, what are you trying to do in the first place?

Adesu

  • Guest
Re: Icon can not display
« Reply #3 on: December 08, 2006, 12:30:33 AM »
Hi Kerry,
That problem is icon "smile" can not display in the dialog box ( there is not icon).

Hi Alls,
 ... what am I do wrong with this code.


Adesu,
What is the problem that you see ?

/// kwb


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Icon can not display
« Reply #4 on: December 08, 2006, 01:01:17 AM »
what happens when you change the lst data to something simple, like a line ?


what happens when you run it animated from the IDE ?

have you tried to step through the code.

the width an height of the display are different , yet the aspect ratio is st to 1  ... is this correct ?


Haven't tried to download the code, but it seems just from reading the code that only one list is used, why are there 3 ?
 .... ahhh I see now !!  Why are there 3 lists ?

« Last Edit: December 08, 2006, 01:02:43 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Icon can not display
« Reply #5 on: December 08, 2006, 11:30:47 AM »
A deferent approach, list of vectors grouped by color
'( (color (vectors)) (color (vectors)) (color (vectors)) )

I did not do a real test!


Code: [Select]
(defun group_on4 (inplst / outlst tmp grp idx sub)
  (while inplst
    (setq outlst
           (cons
             (list (car inplst) (cadr inplst) (caddr inplst) (cadddr inplst))
             outlst
           )
    )
    (setq inplst (cddddr inplst))
  )
  outlst
)

(defun c:test ()
  (setq vectorlst
         (list
           (list 2
                 (list 2  12 2  19 3  9  3  22 4  23 4  8  5  6  5  25 6  26 6
                       5  7  5  7  26 8  27 8  4  9  3  9  28 10 28 10 3  11 3
                       11 28 12 29 12 2  13 2  13 29 14 29 14 2  15 2  15 29 16
                       29 16 2  17 2  17 29 18 29 18 2  19 2  19 29 20 28 20 3
                       21 3  21 28 22 28 22 3  23 4  23 27 24 26 24 5  25 5  25
                       26 26 25 26 6  27 8  27 23 28 22 28 9  29 19 29 12
                      )
           )

           (list 250
                 (list 7   28  8   29  14  32  21  32  10  30  11  30  11  31
                       24  31  25  30  20  30  27  29  23  29  24  28  28  28
                       29  27  26  27  27  26  29  26  29  23  28  24  28  25
                       30  20  30  25  31  24  31  11  30  11  30  10  32  21
                       32  14  28  7  ; 29  8
                      )           )

           (list 8
                 (list 7   28  8   29  14  32  21  32  10  30  11  30  11  31
                       24  31  25  30  20  30  27  29  23  29  24  28  28  28
                       29  27  26  27  27  26  29  26  29  23  28  24  28  25
                       30  20  30  25  31  24  31  11  30  11  30  10  32  21
                       32  14  28  7  ; 29  8
                      )
           )
         )
  )

  (start_image "smile")
 
  (mapcar
    '(lambda (x)
       (mapcar '(lambda (v) (apply 'vector_image (append v (list (car x))))) (group_on4 (cadr x)))
     )
    vectorlst
  )
  (end_image)
)
   
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Adesu

  • Guest
Re: Icon can not display
« Reply #6 on: December 10, 2006, 07:02:38 PM »
Hi CAB,
That code you are  just create is great,thanks for your share,it's only dot with yellow color,that code I would learn ,how that code work.
Thanks.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Icon can not display
« Reply #7 on: December 10, 2006, 10:04:14 PM »
Lets start with the first mapcar, it feeds the vector list to the inner mapcar like this
Code: [Select]
      (mapcar
        '(lambda (x)
           This gets x which is this
           the first time through (2  (2 12 2 19  .....))
           then this the second time (250 (7 28 8 29 14 ........))
           then finally this (8 (7 28 8 29 14 32 .............))
        vectorlst
      )

    This is the inner mapcar that takes the x  and processes it like this
    This  (group_on4 (cadr x))  takes this (2 12 2 19  .....) and returns this ((2 12 2 19)(3 9 3 22)(4 23 4 8 )(5 6 5 25))
    so v equals this on the first time (2 12 2 19) and second time (3 9 3 22) and so on
    this (append v (list (car x))) creates this (2 12 2 19 2) the first time & this (3 9 3 22 2) the second time & so on
    the apply passes a list of arguments to, and executes a specified function so it acts like
    this the first time (vector_image 2 12 2 19 2) and this the second time (vector_image 3 9 3 22 2) and so on

   
Code: [Select]
           (mapcar '(lambda (v)
               (apply 'vector_image (append v (list (car x)))))
             (group_on4 (cadr x))
           )


Here is the working demo
Code: [Select]
(defun c:ci (/ ans dcl_id v vectorlst x group_on4)

  ;;  Group a list into sub list with 4 items in it
  ;;  '(2  12 2 19 3 9 3 22 4 23 4 8 5 6 5 25) becomes
  ;;  '((2 12 2 19)(3 9 3 22)(4 23 4 8)(5 6 5 25))
  (defun group_on4 (inplst / outlst tmp grp idx sub)
    (while inplst
      (setq outlst
             (cons
               (list (car inplst) (cadr inplst) (caddr inplst) (cadddr inplst))
               outlst
             )
      )
      (setq inplst (cddddr inplst))
    )
    outlst
  )

  (setq vectorlst
         (list
           (list 2
                 (list 2  12 2  19 3  9  3  22 4  23 4  8  5  6  5  25 6  26 6
                       5  7  5  7  26 8  27 8  4  9  3  9  28 10 28 10 3  11 3
                       11 28 12 29 12 2  13 2  13 29 14 29 14 2  15 2  15 29 16
                       29 16 2  17 2  17 29 18 29 18 2  19 2  19 29 20 28 20 3
                       21 3  21 28 22 28 22 3  23 4  23 27 24 26 24 5  25 5  25
                       26 26 25 26 6  27 8  27 23 28 22 28 9  29 19 29 12
                      )
           )

           (list 250
                 (list 7   28  8   29  14  32  21  32  10  30  11  30  11  31
                       24  31  25  30  20  30  27  29  23  29  24  28  28  28
                       29  27  26  27  27  26  29  26  29  23  28  24  28  25
                       30  20  30  25  31  24  31  11  30  11  30  10  32  21
                       32  14  28  7 ; 29  8
                      )
           )

           (list 8
                 (list 7   28  8   29  14  32  21  32  10  30  11  30  11  31
                       24  31  25  30  20  30  27  29  23  29  24  28  28  28
                       29  27  26  27  27  26  29  26  29  23  28  24  28  25
                       30  20  30  25  31  24  31  11  30  11  30  10  32  21
                       32  14  28  7 ; 29  8
                      )
           )
         )
  )
  (setq dcl_id (load_dialog "Create Icon.DCL"))
  (if (new_dialog "ci" dcl_id)
    (progn
      (start_image "smile")
      (mapcar
        '(lambda (x)
           (mapcar '(lambda (v) (apply 'vector_image (append v (list (car x)))))
                   (group_on4 (cadr x))
           )
         )
        vectorlst
      )
      (end_image)
     
      (setq ans (start_dialog))
      (unload_dialog dcl_id)
    )
  )
  (princ)
)

And the DCL code
Code: [Select]
dcl_settings : default_dcl_settings { audit_level = 3; }

ci : dialog {label = "SAMPLE CREATE ICON";                         
   spacer ;
   : row {
     : column {
       : image { key = "smile" ; width = 5.42; height = 2.51; color = -15;}
      }
    }     
    spacer;
   : ok_button {is_cancel = true;}
}
« Last Edit: December 10, 2006, 10:09:44 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Adesu

  • Guest
Re: Icon can not display
« Reply #8 on: December 11, 2006, 02:34:18 AM »
Hi CAB,
I'm not yet understand what function is
Code: [Select]
dcl_settings : default_dcl_settings { audit_level = 3; }

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Icon can not display
« Reply #9 on: December 11, 2006, 03:43:50 AM »
Code: [Select]
dcl_settings : default_dcl_settings { audit_level = 3; }
Turns on error checking and will help trouble shoot any errors that you have in your DCL code. Valid settings are….

0 . No checking. Use only if the DCL files have been audited and have not been touched since.

1 . Errors. Finds DCL bugs that may cause AutoCAD to terminate. This level of checking is the default and involves almost no delay. Errors can include using undefined tiles and circular prototype definitions.

2 . Warnings. Finds DCL bugs that result in dialogs with undesired layout or behavior. A modified DCL file should be audited at this level at least once. The warning level catches mistakes, such as missing required attributes and inappropriate attribute values.

3 . Hints. Finds redundant attribute definitions.

/// kwb
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Adesu

  • Guest
Re: Icon can not display
« Reply #10 on: December 11, 2006, 04:11:21 AM »
Hi Kerry,
It's good information for me,good tutorial...thanks...thanks...thanks

********* "HAPPY NEW YEAR AND MARRY CHRISTMAS" *********
« Last Edit: December 11, 2006, 04:13:34 AM by Adesu »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Icon can not display
« Reply #11 on: December 11, 2006, 08:41:35 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

terrycadd

  • Guest
Re: Icon can not display
« Reply #12 on: December 12, 2006, 01:13:02 AM »
I got in on the gatortail end of this! And CAB you do have a good alternative method that I might have used. The initial thread referenced simplifying the function “vector_line” in GetIcon.lsp. Just below the “Smile:” function in “GetIcon.lsp” is “GetPt”. With “GetPt” you set your snap to 1 and trace the endpoints of a polyline by picking every point. Then do a flip screen and copy and paste the X and Y points into your image function. The “C” was the trigger to tell the function either I have moved to a different area or have changed colors. Sort of a pen up / pen down method. The reason I wrote this is because I reviewed other works by others using the standard (vector_image 5 3 7 4 1) method, line after painful line, and I decided to create an easier method to just cut and paste X and Y points.

The main difference between the original “vector_line” code and “*create_icon*” was that the function “setq” was spanned over several lines and the variable names are different. There is only one minor but major error in your revised version. Move the line (setq cnt (+ cnt 2)) inside the repeat loop.
http://web2.airmail.net/terrycad/Images/GetIcon.htm
http://web2.airmail.net/terrycad/LISP/GetIcon.lsp
Also look into the mapcar version of creating images:
http://web2.airmail.net/terrycad/LISP/GetVectors.lsp
http://web2.airmail.net/terrycad/LISP/GetVectors.dcl
Code: [Select]
(defun *create_icon* (lst / cnt col x x1 x2 y y1 y2)
  (if (= (type lst) 'LIST)
    (progn
      (setq cnt 0)
      (repeat (/ (length lst) 2)
        (setq x (nth cnt lst))
        (setq y (nth (+ cnt 1) lst))
        (if (and (= (type x) 'STR)(= (type y) 'INT))
          (if (= (strcase x "C"));CAP
            (progn
              (setq col y)
              (setq x1 nil)
              (setq y1 nil)
              (setq x2 nil)
              (setq y2 nil)
            ); progn
          ); if
          (if (and (= (type x) 'INT) (= (type y) 'INT))
            (if (and (= x1 nil) (= y1 nil))
              (progn
                (setq x1 x)
                (setq y1 y)
              ); progn
              (progn
                (setq x2 x)
                (setq y2 y)
                (vector_image x1 y1 x2 y2 col)
                (setq x1 x2)
                (setq y1 y2)
                (setq x nil)
                (setq y nil)
              ); progn
            ); if
          ); if
        ); if
        (setq cnt (+ cnt 2))
      ); repeat
    ); progn
  ); if
); defun

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Icon can not display
« Reply #13 on: December 12, 2006, 08:24:30 AM »
Oh, I see how the vector list works now.
Thanks Terry for the explanation.

Here is a revised code that will handle those list.
Code: [Select]
(defun c:ci (/ vectorlists lst dcl_id)
  (setq vectorlists
         (list
           (list "C" 2   2   12  2   19  "C" 2   3   9   3   22  4   23  4
                 8   "C" 2   5   6   5   25  6   26  6   5   7   5   7   26
                 8   27  8   4   9   3   9   28  10  28  10  3   11  3   11
                 28  12  29  12  2   13  2   13  29  14  29  14  2   15  2
                 15  29  16  29  16  2   17  2   17  29  18  29  18  2   19
                 2   19  29  20  28  20  3   21  3   21  28  22  28  22  3
                 23  4   23  27  24  26  24  5   25  5   25  26  26  25  26
                 6   "C" 2   27  8   27  23  28  22  28  9   "C" 2   29  19
                 29  12
                )
           (list "C" 250 12  30  19  30  20  29  22  29  24  27  25  27  27
                 25  27  24  29  22  29  20  30  19  30  12  29  11  29  9
                 27  7   27  6   25  4   24  4   22  2   20  2   19  1   12
                 1   11  2   9   2   7   4   6   4   4   6   4   7   2   9
                 2   11  1   12  1   19  2   20  2   22  4   24  4   25  6
                 27  7   27  9   29  11  29  "C" 250 6   18  8   20  9   20
                 10  21  12  21  13  22  18  22  19  21  21  21  22  20  23
                 20  25  18  "C" 250 11  12  11  10  12  9   12  13  13  12
                 13  10  "C" 250 18  12  18  10  19  9   19  13  20  12  20
                 10
                )
           (list "C" 8   7   28  8   29  "C" 8   14  32  21  32  "C" 8   10
                 30  11  30  11  31  24  31  25  30  20  30  "C" 8   27  29
                 23  29  24  28  28  28  29  27  26  27  27  26  29  26  29
                 23  28  24  28  25  "C" 8   30  20  30  25  31  24  31  11
                 30  11  30  10  "C" 8   32  21  32  14  "C" 8   28  7   29
                 8
                )
         )
  )

  (setq dcl_id (load_dialog "Create Icon.DCL"))
  (if (new_dialog "ci" dcl_id)
    (progn
      (start_image "smile")
      (mapcar
        '(lambda (lst / idx x1 y1 x2 y2 #color)
           (setq idx 0)
           (while (setq x1 (nth idx lst))
             (setq y1 (nth (1+ idx) lst))
             (cond
               ((= x1 "C") (setq #color y1))
               ((= (nth (+ idx 2) lst) "C"))
               ((setq x2 (nth (+ idx 2) lst)
                      y2 (nth (+ idx 3) lst)
                )
                (vector_image x1 y1 x2 y2 #color)
               )
             )
             (setq idx (+ 2 idx)) ; skip 2
           )
         )
        vectorlists
      )
      (end_image)
      (setq dcl_id (start_dialog))
      (unload_dialog dcl_id)
    )
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Icon can not display
« Reply #14 on: December 12, 2006, 08:36:01 AM »
Terry,
Having read your DCL tutorials, I  must say you have done a great job with them.
 The vector routines are very helpful & take the pain out of creating vector images.
I have used it to create some images for my Dialog boxes. :-)

Thanks for all your hard work.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.