Author Topic: image_tile and vector_image  (Read 11030 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
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"; list
  46.               ); mapcar
  47.               (and ang (set_tile "eb" (rtos ang 2 0)))
  48.               (and e (set_tile "p" "1"))
  49.               (action_tile "img" ; this did not worked, because I used : image, instead of : image_button!
  50.                 (vl-prin1-to-string '(progn (setq ang (rem (+ ang 15) 375)) (set_tile "eb" (rtos ang 2 0))))
  51.               ); action_tile
  52.               (action_tile "pick" "(done_dialog 2)")
  53.               (action_tile "accept"
  54.                 (vl-prin1-to-string
  55.                   '(cond
  56.                     ( (not o) (set_tile "err" "Object not specified!") )
  57.                     ( (done_dialog 1) )
  58.                   ); cond
  59.                 ); vl-prin1-to-string
  60.               ); action_tile
  61.               (setq dcf (start_dialog))
  62.             )
  63.           ); cond
  64.           (and (= 2 dcf)
  65.             (setq e (car (entsel "\nSelect object to rotate: ")))
  66.             (setq o (vlax-ename->vla-object e))
  67.             (if (not (vlax-write-enabled-p o)) (setq e nil o nil))
  68.           ); and
  69.         ); while
  70.         (/= 1 dcf)
  71.       ); progn
  72.       (princ "\nUser cancelled the dialog.")
  73.     )
  74.     (T
  75.       (and
  76.         (progn (vl-catch-all-apply 'vla-getBoundingBox (list o 'll 'ur)) (apply 'and '(ll ur)))
  77.         (setq cen (apply 'mapcar (cons '(lambda (a b) (/ (+ a b) 2.)) (mapcar 'vlax-safearray->list (list ll ur)))))
  78.         (vl-catch-all-apply 'vla-Rotate (list o (vlax-3d-point cen) (cond ((zerop ang) ang) ((* PI (/ (float ang) 180))))))
  79.       ); and
  80.     )
  81.   ); cond
  82.   (*error* nil) (princ)
  83. ); defun
  84.  
  85.  
  86. ;;--------------------=={ Display Bitmap }==------------------;;
  87. ;;                                                            ;;
  88. ;;  Renders the supplied ACI colour list representation of a  ;;
  89. ;;  Bitmap image on the DCL image tile or image_button tile   ;;
  90. ;;  with the given key.                                       ;;
  91. ;;------------------------------------------------------------;;
  92. ;;  Author: Lee Mac, Copyright © 2012 - www.lee-mac.com       ;;
  93. ;;------------------------------------------------------------;;
  94. ;;  Arguments:                                                ;;
  95. ;;  key - key of DCL image tile or image_button tile          ;;
  96. ;;  lst - ACI colour list                                     ;;
  97. ;;------------------------------------------------------------;;
  98. ;;  Returns:  nil                                             ;;
  99. ;;------------------------------------------------------------;;
  100.  
  101. (defun LM:DisplayBitmap ( key lst / i j s x y )
  102.   (setq s (fix (sqrt (length lst))))
  103.   (repeat (setq i s)
  104.     (setq j 1)
  105.     (repeat s
  106.       (setq x (cons j x)
  107.         y (cons i y)
  108.         j (1+ j)
  109.       )
  110.     )
  111.     (setq i (1- i))
  112.   )
  113.   (start_image key)
  114.   (fill_image 0 0 (dimx_tile key) (dimy_tile key) -15)
  115.   (mapcar 'vector_image x y x y lst)
  116. )

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 »
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12906
  • 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

  • Swamp Rat
  • Posts: 812
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 »
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12906
  • 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

  • Swamp Rat
  • Posts: 812
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) ! :-)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg