Author Topic: image_tile and vector_image  (Read 143 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Bull Frog
  • Posts: 267
image_tile and vector_image
« on: March 23, 2017, 05:22:41 pm »
Hi guys, its me again.

Today I tried to practice with image_tile - since I have almost no experience with it.
To get started I figured out some simple dialog, that uses Lee Mac's Bitmaps - the rotation button:



It uses 1 disabled edit_box and 1 disabled toggle - to display information.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:test ( / *error* dcl des dch dcf e o cen ang ll ur )
  2.  
  3.  (defun *error* ( msg )
  4.    (and (< 0 dch) (unload_dialog dch))
  5.    (and (eq 'FILE (type des)) (close des))
  6.    (and (eq 'STR (type dcl)) (findfile dcl) (vl-file-delete dcl))
  7.    (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\nError: " msg)) ))
  8.    (princ)
  9.  ); defun *error*
  10.  
  11.  (cond
  12.    (
  13.      (not
  14.        (and (setq dcl (vl-filename-mktemp nil nil ".dcl")) (setq des (open dcl "w"))
  15.          (mapcar (function (lambda (x) (princ (strcat "\n" x) des)))
  16.            '(
  17.              "RotateObject : dialog"
  18.              "{ label = \"Rotate Object\";"
  19.              "  : column"
  20.              "  { : image_button { key = \"img\" ; width = 5.5 ; aspect_ratio = 1.0; alignment = centered; fixed_width = true; fixed_height = true; } " ; 32x32 image
  21.              "    : edit_box { label = \"Angle\"; key = \"eb\"; alignment = centered; edit_width = 12; fixed_width = true; is_enabled = false; value = \"0\"; }" ; info
  22.              "    : row"
  23.              "    { : button { label = \"Pick object >>\"; key = \"pick\"; alignment = centered; width = 5; fixed_width = true; }"
  24.              "      : toggle { key = \"p\"; is_enabled = false; value = 0; }" ; info
  25.              "    }"
  26.              "  }"
  27.              "  spacer;"
  28.              "  ok_cancel;"
  29.              "  : text { label = \"\"; key = \"err\"; }"
  30.              "}"
  31.            )
  32.          ); mapcar
  33.          (not (setq des (close des))) (< 0 (setq dch (load_dialog dcl)))
  34.        ); and
  35.      ); not
  36.      (princ "\nUnable to write or load the DCL file.")
  37.    )
  38.    (
  39.      (progn
  40.        (setq ang 0)
  41.        (while (not (member dcf '(0 1)))
  42.          (cond
  43.            ( (not (new_dialog "RotateObject" dch)) (princ "\nUnable to display the dialog") (setq dcf 0) )
  44.            (T
  45.              (LM:DisplayBitmap "img"
  46.                '(-15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 009 163 165 177 166 166 166 177 165 153 009 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15
  47.                  -15 -15 -15 -15 -15 -15 -15 -15 254 153 167 156 165 173 163 153 253 153 163 163 165 177 165 253 -15 -15 -15 -15 -15 -15 -15 -15
  48.                  -15 -15 -15 -15 -15 -15 -15 253 167 177 155 163 153 163 163 163 153 153 153 153 153 153 173 167 165 009 -15 -15 -15 -15 -15 -15
  49.                  -15 -15 -15 -15 -15 254 252 177 165 163 163 163 163 163 163 163 163 163 163 153 153 153 253 153 165 167 253 -15 -15 -15 -15 -15
  50.                  -15 -15 -15 -15 254 155 177 173 163 163 163 163 163 163 163 163 163 163 163 163 163 163 153 153 161 163 177 153 -15 -15 -15 -15
  51.                  -15 -15 -15 254 155 177 173 163 163 163 163 163 163 163 153 153 153 153 153 153 163 163 163 163 153 153 163 177 253 -15 -15 -15
  52.                  -15 -15 254 252 177 173 163 163 163 163 163 163 163 165 177 166 166 166 177 165 163 153 163 163 163 153 153 163 167 009 -15 -15
  53.                  -15 -15 253 177 165 163 173 163 163 163 163 165 156 159 167 251 251 251 149 169 166 165 163 163 163 163 153 153 165 165 -15 -15
  54.                  -15 254 165 177 163 173 173 173 163 163 177 177 008 253 009 009 009 253 252 008 139 169 175 163 163 163 163 153 153 177 253 -15
  55.                  -15 253 169 165 163 173 173 173 163 167 167 253 254 -15 -15 -15 -15 -15 254 009 252 251 169 175 163 163 163 163 153 173 165 -15
  56.                  254 008 166 165 154 154 154 175 154 177 009 -15 -15 -15 -15 -15 -15 -15 -15 -15 254 252 251 179 165 163 163 163 163 153 156 009
  57.                  009 167 154 175 154 154 154 175 156 253 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 254 252 149 156 163 163 163 163 153 165 153
  58.                  253 169 175 175 164 154 175 154 167 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 253 251 169 165 163 163 163 153 173 165
  59.                  252 166 175 154 164 164 175 156 153 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 254 252 159 177 163 163 163 153 163 177
  60.                  008 166 175 164 164 164 165 166 009 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 253 251 166 163 163 163 163 153 166
  61.                  008 166 175 164 164 164 165 166 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 009 251 166 173 173 163 163 153 166
  62.                  008 168 175 164 164 164 165 166 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 009 251 166 165 175 165 163 163 166
  63.                  008 158 175 164 164 164 175 166 254 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 163 -15 -15 009 251 166 165 154 154 165 173 177
  64.                  008 179 164 164 166 166 175 156 253 -15 -15 -15 -15 -15 -15 -15 -15 -15 254 253 166 153 -15 009 167 156 175 154 154 175 165 165
  65.                  252 159 166 154 166 166 154 154 165 -15 -15 -15 -15 -15 -15 -15 -15 -15 009 155 166 166 253 253 159 154 175 154 154 175 154 163
  66.                  253 251 166 175 166 166 164 175 156 009 -15 -15 -15 -15 -15 -15 -15 -15 253 177 156 175 166 167 166 175 154 154 154 165 166 009
  67.                  009 251 179 164 164 166 166 154 164 165 -15 -15 -15 -15 -15 -15 -15 254 253 159 154 175 175 166 154 175 154 154 175 175 167 -15
  68.                  254 252 159 166 154 166 166 164 175 166 153 -15 -15 -15 -15 -15 -15 254 252 158 154 154 154 175 175 154 154 154 175 156 153 -15
  69.                  -15 253 251 179 156 154 166 175 166 177 254 -15 -15 -15 -15 -15 -15 254 252 168 175 154 154 175 175 154 154 175 154 167 254 -15
  70.                  -15 254 252 149 166 154 175 166 169 254 -15 -15 -15 -15 -15 -15 -15 254 008 168 175 164 154 154 154 154 175 175 156 253 -15 -15
  71.                  -15 -15 009 008 159 166 166 169 009 -15 -15 -15 -15 -15 -15 -15 -15 009 251 168 175 164 164 154 154 175 175 166 155 -15 -15 -15
  72.                  -15 -15 254 253 008 149 177 009 -15 -15 -15 -15 -15 -15 -15 -15 -15 253 149 168 175 164 164 164 154 154 165 154 167 -15 -15 -15
  73.                  -15 -15 -15 254 253 253 009 -15 -15 -15 -15 -15 -15 -15 -15 -15 254 253 169 166 154 166 164 164 164 154 154 165 164 155 -15 -15
  74.                  -15 -15 -15 -15 -15 254 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 254 252 158 166 154 154 175 175 175 175 175 165 165 156 163 -15
  75.                  -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 254 252 168 168 168 168 168 168 166 166 166 166 166 166 166 153
  76.                  -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 254 252 251 251 251 251 251 251 251 251 251 008 008 252 009 -15
  77.                  -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 -15 254 009 009 009 009 009 009 009 009 254 254 254 254 254 -15
  78.                ); list
  79.              ); mapcar
  80.              (and ang (set_tile "eb" (rtos ang 2 0)))
  81.              (and e (set_tile "p" "1"))
  82.              (action_tile "img" ; this did not worked, because I used : image, instead of : image_button!
  83.                (vl-prin1-to-string '(progn (setq ang (rem (+ ang 15) 375)) (set_tile "eb" (rtos ang 2 0))))
  84.              ); action_tile
  85.              (action_tile "pick" "(done_dialog 2)")
  86.              (action_tile "accept"
  87.                (vl-prin1-to-string
  88.                  '(cond
  89.                    ( (not o) (set_tile "err" "Object not specified!") )
  90.                    ( (done_dialog 1) )
  91.                  ); cond
  92.                ); vl-prin1-to-string
  93.              ); action_tile
  94.              (setq dcf (start_dialog))
  95.            )
  96.          ); cond
  97.          (and (= 2 dcf)
  98.            (setq e (car (entsel "\nSelect object to rotate: ")))
  99.            (setq o (vlax-ename->vla-object e))
  100.            (if (not (vlax-write-enabled-p o)) (setq e nil o nil))
  101.          ); and
  102.        ); while
  103.        (/= 1 dcf)
  104.      ); progn
  105.      (princ "\nUser cancelled the dialog.")
  106.    )
  107.    (T
  108.      (and
  109.        (progn (vl-catch-all-apply 'vla-getBoundingBox (list o 'll 'ur)) (apply 'and '(ll ur)))
  110.        (setq cen (apply 'mapcar (cons '(lambda (a b) (/ (+ a b) 2.)) (mapcar 'vlax-safearray->list (list ll ur)))))
  111.        (vl-catch-all-apply 'vla-Rotate (list o (vlax-3d-point cen) (cond ((zerop ang) ang) ((* PI (/ (float ang) 180))))))
  112.      ); and
  113.    )
  114.  ); cond
  115.  (*error* nil) (princ)
  116. ); defun
  117.  
  118.  
  119. ;;--------------------=={ Display Bitmap }==------------------;;
  120. ;;                                                            ;;
  121. ;;  Renders the supplied ACI colour list representation of a  ;;
  122. ;;  Bitmap image on the DCL image tile or image_button tile   ;;
  123. ;;  with the given key.                                       ;;
  124. ;;------------------------------------------------------------;;
  125. ;;  Author: Lee Mac, Copyright 2012 - www.lee-mac.com       ;;
  126. ;;------------------------------------------------------------;;
  127. ;;  Arguments:                                                ;;
  128. ;;  key - key of DCL image tile or image_button tile          ;;
  129. ;;  lst - ACI colour list                                     ;;
  130. ;;------------------------------------------------------------;;
  131. ;;  Returns:  nil                                             ;;
  132. ;;------------------------------------------------------------;;
  133.  
  134. (defun LM:DisplayBitmap ( key lst / i j s x y )
  135.  (setq s (fix (sqrt (length lst))))
  136.  (repeat (setq i s)
  137.    (setq j 1)
  138.    (repeat s
  139.      (setq x (cons j x)
  140.        y (cons i y)
  141.        j (1+ j)
  142.      )
  143.    )
  144.    (setq i (1- i))
  145.  )
  146.  (start_image key)
  147.  (fill_image 0 0 (dimx_tile key) (dimy_tile key) -15)
  148.  (mapcar 'vector_image x y x y lst)
  149. )

Trouble is:
  • I have no idea how to use vector_image with that list, to display the image.
  • The action_tile doesn't work for the image - why? - the idea was to increment the angle by 15 units
:thinking:
« Last Edit: April 06, 2017, 01:03:32 pm by Grrr1337 »

Lee Mac

  • Seagull
  • Posts: 11626
  • AutoCAD 2015 Windows 7 London, England
Re: image_tile and vector_image
« Reply #1 on: March 23, 2017, 08:15:44 pm »
  • I have no idea how to use vector_image with that list, to display the image.

Please explore the contents of the zip file attached in the DCL Bitmaps thread - several examples have been included.

Grrr1337

  • Bull Frog
  • Posts: 267
Re: image_tile and vector_image
« Reply #2 on: March 23, 2017, 08:38:11 pm »
Please explore the contents of the zip file attached in the DCL Bitmaps thread - several examples have been included.

Thank you Lee!
I've found this gem of yours:

Code - Auto/Visual Lisp: [Select]
  1. ;;--------------------=={ Display Bitmap }==------------------;;
  2. ;;                                                            ;;
  3. ;;  Renders the supplied ACI colour list representation of a  ;;
  4. ;;  Bitmap image on the DCL image tile or image_button tile   ;;
  5. ;;  with the given key.                                       ;;
  6. ;;------------------------------------------------------------;;
  7. ;;  Author: Lee Mac, Copyright 2012 - www.lee-mac.com       ;;
  8. ;;------------------------------------------------------------;;
  9. ;;  Arguments:                                                ;;
  10. ;;  key - key of DCL image tile or image_button tile          ;;
  11. ;;  lst - ACI colour list                                     ;;
  12. ;;------------------------------------------------------------;;
  13. ;;  Returns:  nil                                             ;;
  14. ;;------------------------------------------------------------;;
  15.  
  16. (defun LM:DisplayBitmap ( key lst / i j s x y )
  17.  (setq s (fix (sqrt (length lst))))
  18.  (repeat (setq i s)
  19.    (setq j 1)
  20.    (repeat s
  21.      (setq x (cons j x)
  22.        y (cons i y)
  23.        j (1+ j)
  24.      )
  25.    )
  26.    (setq i (1- i))
  27.  )
  28.  (start_image key)
  29.  (fill_image 0 0 (dimx_tile key) (dimy_tile key) -15)
  30.  (mapcar 'vector_image x y x y lst)
  31. )

I tend to ignore information - when too much of it is provided, I become distracted. :)
Before creating this thread I was trying to learn (atleast something) from your JustifyBasePoint program - but the content was too confusing for me. :D

Now just one issue left - the action_tile - whats wrong with it?

BTW Now that the image is displayed, I've modified the above code.
« Last Edit: March 23, 2017, 08:42:14 pm by Grrr1337 »

Lee Mac

  • Seagull
  • Posts: 11626
  • AutoCAD 2015 Windows 7 London, England
Re: image_tile and vector_image
« Reply #3 on: March 24, 2017, 08:53:09 am »
Now just one issue left - the action_tile - whats wrong with it?

The image tile will need to be an image_button tile in order to be assigned an action.

Grrr1337

  • Bull Frog
  • Posts: 267
Re: image_tile and vector_image
« Reply #4 on: March 24, 2017, 09:43:40 am »
The image tile will need to be an image_button tile in order to be assigned an action.

Man, I feel so stupid  :oops:

Also I was about to ask how the tile's size should be determined, depending on the AxB image bit size, until I browsed in: DCL-Bitmaps\Tile Definitions\ImageTiles.dcl

This is the final result (I also modified the original code) :


You are a great tutor, Lee!
Everytime I try to learn some new aspect of the lisp world - I see that you've been there already, perfecting it.
Like this LM:DisplayBitmap looks so easy and comfortable to use, that IMO it deserves a place within the standad tile functions (like action_tile/set_tile) ! :-)