Author Topic: Help : Scale lisp  (Read 373 times)

0 Members and 1 Guest are viewing this topic.

mhy3sx

  • Newt
  • Posts: 120
Help : Scale lisp
« on: March 21, 2024, 05:19:56 PM »
I use this code to scale images in drawings. This code works with textpage menu and now I try to convert it to work with dcl menu. I can not find the error in the code. Can anyone help?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:myimgscale (/ *error* dch dcl des)
  2.       (defun *error* ( msg )
  3.         (if (and (= 'int (type dch)) (< 0 dch))
  4.           (unload_dialog dch)
  5.         )
  6.         (if (= 'file (type des))
  7.           (close des)
  8.         )
  9.         (if (and (= 'str (type dcl)) (findfile dcl))
  10.           (vl-file-delete dcl)
  11.         )
  12.         (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
  13.           (princ (strcat "\nError: " msg))
  14.         )
  15.         (princ)
  16.       ) ; end defun
  17.          
  18.           (cond
  19.         ( (not
  20.             (setq dcl (vl-filename-mktemp nil nil ".dcl")
  21.                  des (open dcl "w")
  22.             ) ; end setq
  23.           ) ; end not
  24.           (princ "\nUnable to open DCL for writing.")
  25.         )
  26.         ( (progn
  27.             (foreach str '(
  28.                             "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}"
  29.                             ""
  30.                             "txt2 : dialog { spacer; key = \"dcl\";"
  31.                             " : boxed_column { label = \"Set scale\"; height = 1.0;"
  32.                             "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
  33.                             "        key = \"radio_button01\"; label = \"1. --> 1:500\";"
  34.                             "    }" ; radio_button
  35.                             "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  36.                             "        key = \"radio_button02\"; label = \"2. --> 1:2000\";"
  37.                             "    }" ; radio_button
  38.                             "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  39.                             "        key = \"radio_button03\"; label = \"3. --> 1:2500\";"
  40.                             "    }" ; radio_button
  41.                             "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  42.                             "        key = \"radio_button04\"; label = \"4. --> 1:4000\";"
  43.                             "    }" ; radio_button
  44.                             "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  45.                             "        key = \"radio_button05\"; label = \"5. --> 1:5000\";"
  46.                             "    }" ; radio_button
  47.                             "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
  48.                             "        key = \"radio_button06\"; label = \"6. --> 1:10000\";"
  49.                             "    }" ; radio_button
  50.                                                  "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
  51.                             "        key = \"radio_button07\"; label = \"7. --> 1:50000\";"
  52.                             "    }" ; radio_button
  53.                                                  "      }" ;end boxed_column
  54.                           ; "    : row { width = 20;"
  55.                           ; "      : button { key = \"OK\"; label = \"OK\"; is_default = true;"
  56.                           ; "                 is_cancel = true; fixed_width = true; width = 10; }"
  57.                           ; "    }" ; end row
  58.                             "    ok_only;"                                               
  59.                             "  }" ; end dialog
  60.                           ) ;end list
  61.               (write-line str des)
  62.             ) ; end foreach
  63.             (setq des (close des)
  64.                  dch (load_dialog dcl)
  65.             ) ; end setq
  66.             (<= dch 0)
  67.           )
  68.           (princ "\nUnable to load DCL file.")
  69.         )
  70.         (   (not (new_dialog "txt2" dch))
  71.             (princ "\nUnable to display 'txt2' dialog.")
  72.         )
  73.         ( t
  74.   (set_tile "dcl" "Text Options")
  75.   (action_tile "radio_button01" "(command \"_scale\" 2) (setq sngReturn 1))")
  76.   (action_tile "radio_button02" "((lambda (/ ent) (while (not (setq ent (car (entsel))))) (command \"_scale\" ent \"\" (cdr (assoc 11 (entget ent))) 0.5)) (setq sngReturn 2))")
  77.   (action_tile "radio_button03" "((lambda (/ ent) (while (not (setq ent (car (entsel))))) (command \"_scale\" ent \"\" (cdr (assoc 11 (entget ent))) 0.4)) (setq sngReturn 3))")
  78.   (action_tile "radio_button04" "((lambda (/ ent) (while (not (setq ent (car (entsel))))) (command \"_scale\" ent \"\" (cdr (assoc 11 (entget ent))) 0.25)) (setq sngReturn 4))")
  79.   (action_tile "radio_button05" "((lambda (/ ent) (while (not (setq ent (car (entsel))))) (command \"_scale\" ent \"\" (cdr (assoc 11 (entget ent))) 0.20)) (setq sngReturn 5))")
  80.   (action_tile "radio_button06" "((lambda (/ ent) (while (not (setq ent (car (entsel))))) (command \"_scale\" ent \"\" (cdr (assoc 11 (entget ent))) 0.10)) (setq sngReturn 6))")
  81.   (action_tile "radio_button07" "((lambda (/ ent) (while (not (setq ent (car (entsel))))) (command \"_scale\" ent \"\" (cdr (assoc 11 (entget ent))) 0.02)) (setq sngReturn 7))")
  82.   (action_tile "OK" "(progn (done_dialog 1) sngReturn)")
  83. )
  84.  
  85.                 ) ; end cond
  86.       (*error* nil)
  87. ); end defun
  88.  
  89.  
  90.  

Thanks
« Last Edit: March 22, 2024, 07:40:03 PM by mhy3sx »

BIGAL

  • Swamp Rat
  • Posts: 1419
  • 40 + years of using Autocad
Re: Help : Scale lisp
« Reply #1 on: March 21, 2024, 11:59:47 PM »
When ever you say doesn't work we need to know what does not work and what error messages are displayed.
A man who never made a mistake never made anything

kozmos

  • Newt
  • Posts: 114
Re: Help : Scale lisp
« Reply #2 on: March 22, 2024, 01:54:10 AM »
You can not directly use command in action_tile function, need to use (done_dialog number) in action_tile and catch the number after start_dialog, call command accordingly. this will need to turn off dialog interface and run command, then show the dialog again.
As for your codes, there is no need to vanish_dialog, call_command, re-appear_dialog procedure, can simply close the dialog and call command.

optimized codes as following, hope this give you a clue.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:myimgscale (/ *error* dch dcl des)
  2.   (defun *error* (msg)
  3.     (if (and (= 'int (type dch)) (< 0 dch))
  4.       (unload_dialog dch)
  5.     )
  6.     (if (= 'file (type des))
  7.       (close des)
  8.     )
  9.     (if (and (= 'str (type dcl)) (findfile dcl))
  10.       (vl-file-delete dcl)
  11.     )
  12.     (if (and msg
  13.              (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  14.         )
  15.       (princ (strcat "\nError: " msg))
  16.     )
  17.     (princ)
  18.   )                                     ; end defun
  19.  
  20.   (cond
  21.     ((not
  22.        (setq dcl (vl-filename-mktemp nil nil ".dcl")
  23.              des (open dcl "w")
  24.        )                                ; end setq
  25.      )                                  ; end not
  26.      (princ "\nUnable to open DCL for writing.")
  27.     )
  28.     ((progn
  29.        (foreach str
  30.                 '(
  31.                   "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}"
  32.                   ""
  33.                   "txt2 : dialog { spacer; key = \"dcl\";"
  34.                   " : boxed_radio_column { key=\042key\042; label = \"&#38;#38;#932;&#38;#38;#973;&#38;#38;#960;&#38;#38;#959;&#38;#38;#962; &#38;#38;#922;&#38;#38;#949;&#38;#38;#953;&#38;#38;#956;&#38;#38;#941;&#38;#38;#957;&#38;#38;#959;&#38;#38;#965;\"; height = 1.0;"
  35.                   "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
  36.                   "        key = \"radio_button01\"; label = \"1. --> 1:500\";"
  37.                   "    }"               ; radio_button
  38.                   "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  39.                   "        key = \"radio_button02\"; label = \"2. --> 1:2000\";"
  40.                   "    }"               ; radio_button
  41.                   "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  42.                   "        key = \"radio_button03\"; label = \"3. --> 1:2500\";"
  43.                   "    }"               ; radio_button
  44.                   "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  45.                   "        key = \"radio_button04\"; label = \"4. --> 1:4000\";"
  46.                   "    }"               ; radio_button
  47.                   "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  48.                   "        key = \"radio_button05\"; label = \"5. --> 1:5000\";"
  49.                   "    }"               ; radio_button
  50.                   "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
  51.                   "        key = \"radio_button06\"; label = \"6. --> 1:10000\";"
  52.                   "    }"               ; radio_button
  53.                   "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
  54.                   "        key = \"radio_button07\"; label = \"7. --> 1:50000\";"
  55.                   "    }"               ; radio_button
  56.                   "      }"             ;end boxed_column
  57.                                         ; "    : row { width = 20;"
  58.                                         ; "      : button { key = \"OK\"; label = \"OK\"; is_default = true;"
  59.                                         ; "                 is_cancel = true; fixed_width = true; width = 10; }"
  60.                                         ; "    }" ; end row
  61.                   "    ok_only;"
  62.                   "  }"                 ; end dialog
  63.                  )                      ;end list
  64.          (write-line str des)
  65.        )                                ; end foreach
  66.        (setq des (close des)
  67.              dch (load_dialog dcl)
  68.        )                                ; end setq
  69.        (<= dch 0)
  70.      )
  71.      (princ "\nUnable to load DCL file.")
  72.     )
  73.     ((not (new_dialog "txt2" dch))
  74.      (princ "\nUnable to display 'txt2' dialog.")
  75.     )
  76.     (t
  77.      (set_tile "dcl" "Text Options")
  78.      (action_tile "key" "(setq sngReturn $value)")
  79.      ;|
  80.      (action_tile
  81.        "radio_button01"
  82.        "(command \"_scale\" 2) (setq sngReturn 1))"
  83.      )
  84.      (action_tile
  85.        "radio_button02"
  86.        "((lambda (/ ent) (while (not (setq ent (car (entsel))))) (command \"_scale\" ent \"\" (cdr (assoc 11 (entget ent))) 0.5)) (setq sngReturn 2))"
  87.      )
  88.      (action_tile
  89.        "radio_button03"
  90.        "((lambda (/ ent) (while (not (setq ent (car (entsel))))) (command \"_scale\" ent \"\" (cdr (assoc 11 (entget ent))) 0.4)) (setq sngReturn 3))"
  91.      )
  92.      (action_tile
  93.        "radio_button04"
  94.        "((lambda (/ ent) (while (not (setq ent (car (entsel))))) (command \"_scale\" ent \"\" (cdr (assoc 11 (entget ent))) 0.25)) (setq sngReturn 4))"
  95.      )
  96.      (action_tile
  97.        "radio_button05"
  98.        "((lambda (/ ent) (while (not (setq ent (car (entsel))))) (command \"_scale\" ent \"\" (cdr (assoc 11 (entget ent))) 0.20)) (setq sngReturn 5))"
  99.      )
  100.      (action_tile
  101.        "radio_button06"
  102.        "((lambda (/ ent) (while (not (setq ent (car (entsel))))) (command \"_scale\" ent \"\" (cdr (assoc 11 (entget ent))) 0.10)) (setq sngReturn 6))"
  103.      )
  104.      (action_tile
  105.        "radio_button07"
  106.        "((lambda (/ ent) (while (not (setq ent (car (entsel))))) (command \"_scale\" ent \"\" (cdr (assoc 11 (entget ent))) 0.02)) (setq sngReturn 7))"
  107.      )
  108.      |;
  109.      (action_tile "OK" "(done_dialog 1)")
  110.      (start_dialog)
  111.      (if (setq sngReturn (cond ((eq sngReturn "radio_button01") 2.)
  112.                                ((eq sngReturn "radio_button02") 0.50)
  113.                                ((eq sngReturn "radio_button03") 0.40)
  114.                                ((eq sngReturn "radio_button04") 0.25)
  115.                                ((eq sngReturn "radio_button05") 0.20)
  116.                                ((eq sngReturn "radio_button06") 0.10)
  117.                                ((eq sngReturn "radio_button07") 0.02)
  118.                          )
  119.          )
  120.        (while (setq ent (car (entsel)))
  121.          (command "_scale"
  122.                   ent
  123.                   ""
  124.                   (cdr (assoc 11 (entget ent)))
  125.                   sngReturn
  126.          )
  127.        )
  128.      )
  129.     )
  130.   )                                     ; end cond
  131.   (*error* nil)
  132. )                                       ; end defun
  133.  
  134.  
  135.  
KozMos Inc.

mhy3sx

  • Newt
  • Posts: 120
Re: Help : Scale lisp
« Reply #3 on: March 22, 2024, 11:17:09 AM »
Thank you kozmos   

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Help : Scale lisp
« Reply #4 on: March 22, 2024, 12:13:52 PM »
Just curious, what is this for in DCL...

&#38;#38;#38;#932;&#38;#38;#38;#973;&#38;#38;#38;#960;&#38;#38;#38;#959;&#38;#38;#38;#962; &#38;#38;#38;#922;&#38;#38;#38;#949;&#38;#38;#38;#953;&#38;#38;#38;#956;&#38;#38;#38;#941;&#38;#38;#38;#957;&#38;#38;#38;#959;&#38;#38;#38;#965
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2141
  • class keyThumper<T>:ILazy<T>
Re: Help : Scale lisp
« Reply #5 on: March 22, 2024, 06:33:59 PM »
Just curious, what is this for in DCL...

&#38;#38;#38;#38;#932;&#38;#38;#38;#38;#973;&#38;#38;#38;#38;#960;&#38;#38;#38;#38;#959;&#38;#38;#38;#38;#962; &#38;#38;#38;#38;#922;&#38;#38;#38;#38;#949;&#38;#38;#38;#38;#953;&#38;#38;#38;#38;#956;&#38;#38;#38;#38;#941;&#38;#38;#38;#38;#957;&#38;#38;#38;#38;#959;&#38;#38;#38;#38;#965


Looks like a HTML representation of some Greek characters to me . . .
https://www.ee.ucl.ac.uk/~mflanaga/java/HTMLandASCIItableC1.html
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.