Author Topic: How to remember values in dcl windows  (Read 5017 times)

0 Members and 1 Guest are viewing this topic.

Rufusff7

  • Mosquito
  • Posts: 6
How to remember values in dcl windows
« on: July 22, 2022, 05:01:10 AM »
Hello.

I just started learning autolisp and this is my first program. It creates 3D model of drain box with dimensions you type in pop-up window. Can you help me to modify it? My goal is:

1) First launch of program - DCL window with default values in it.
2) Second and next launches of program - DCL window with values you entered previously.

DCL:
Code: [Select]
r1:boxed_row{
                    width=60;
                   
                    :boxed_column{
                                   
                                   : text {label = "Enter dimensions:"; key = "w_t1";}
: edit_box {label = "A (Width)"; key = "W_A"; edit_width=10; value = "0";}
: edit_box {label = "B (Lenght)"; key = "W_B"; edit_width=10; value = "0";}
: edit_box {label = "C (Height)"; key = "W_C"; edit_width=10; value = "0";}

: edit_box {label = "H1 (Front)"; key = "W_H1"; edit_width=10; value = "50";}
: edit_box {label = "H2 (Back)"; key = "W_H2"; edit_width=10; value = "30";}

: edit_box {label = "CH (Chamfer)"; key = "W_CH"; edit_width=10; value = "25";}

: edit_box {label = "D (Diameter outlet)"; key = "W_D"; edit_width=10; value = "51";}

: edit_box {label = "E (>CH)"; key = "W_E"; edit_width=10; value = "75";}
: edit_box {label = "D1 (Diameter of bar)"; key = "W_D1"; edit_width=10; value = "16";}
: edit_box {label = "F1"; key = "W_F1"; edit_width=10; value = "50";}
: edit_box {label = "F2"; key = "W_F2"; edit_width=10; value = "50";}
: edit_box {label = "G"; key = "W_G"; edit_width=10; value = "150";}
: edit_box {label = "H (>D1)"; key = "W_H"; edit_width=10; value = "30";}
}
:boxed_column {:image{width=120; height=35; aspect_ratio=3; color=-2; key="dbimage"; is_enabled=false;}
}
}
d1:dialog{label="Drain Pallet";
           r1;
         
           ok_cancel;
}

LSP part:
Code: [Select]
;-----Read_Dimensions_From_DCL-----

(defun savevars()
;-----Box-----
(setq A (atoi (get_tile "W_A")))
(setq B (atoi (get_tile "W_B")))
(setq C (atoi (get_tile "W_C")))
;-----Slope-----
(setq H1 (atoi (get_tile "W_H1")))
(setq H2 (atoi (get_tile "W_H2")))
;-----Chamfer----- 
(setq CH (atoi (get_tile "W_CH")))
;-----Drain_Tube--------- 
(setq D (atoi (get_tile "W_D")))
;-----Handrails----- 
(setq E (atoi (get_tile "W_E")))
(setq D1 (atoi (get_tile "W_D1")))
(setq F1 (atoi (get_tile "W_F1")))
(setq F2 (atoi (get_tile "W_F2")))
(setq G (atoi (get_tile "W_G")))
(setq H (atoi (get_tile "W_H")))
)

All files of this program in attachment.




Lee Mac

  • Seagull
  • Posts: 12752
  • London, England
Re: How to remember values in dcl windows
« Reply #1 on: July 25, 2022, 05:33:29 PM »
Firstly, you need to decide on a method of storing the values, depending on the scope & persistence you're looking to obtain.

For example, if you were to assign the values obtained through the dialog interface to global variables (or perhaps a single global variable containing a list of values), the variable would be defined within the document namespace and therefore the values would be accessible from the active drawing and would persist for the duration of active drawing session.

Alternatively, if you want the values to persist beyond the active drawing session, you could opt to write the values to a file (e.g. a text file [.txt/.ini/.csv/.cfg]) and read such file on the next execution of the program (indeed, this is the approach that I follow with many of my programs). Finally, If you're only looking to store one or two values, the Windows registry can be a convenient location, as you can read/write from/to the registry using the in-built getenv/setenv functions.

BIGAL

  • Swamp Rat
  • Posts: 1136
  • 40 + years of using Autocad
Re: How to remember values in dcl windows
« Reply #2 on: July 30, 2022, 11:41:46 PM »
Have a look at this its a library routine you can have from 1 to about 20 lines of input, it uses a list for input there are examples in code. Its dynamic in that the number of items in list is how big the dcl ends up.

You can preset the values the examples may not show that, but where a preset value "200" exists you can replace with say (rtos rebarsz 2 0) where the variable rebarsz is 200. You can not leave the item totally blank so use a, if rebarsz nil set it to 200 etc before running the dcl. It is only around 4 lines of code to run the dcl.

Because it makes a list of the answers its easy to get all the variables using (nth x ans).

Just post again if you dont understand how to run.

Ps there is multi radio buttons and multi toggles also.
A man who never made a mistake never made anything

beck's bolero

  • Retired
  • Needs a day job
  • Posts: 7672
  • AKA Daniel
Re: How to remember values in dcl windows
« Reply #3 on: July 31, 2022, 04:48:54 AM »
Basically what I wrote SQLiteLisp for. OpenDCL has an archive feature to persist data. Lots of cool ways to persist data
Retired

Rufusff7

  • Mosquito
  • Posts: 6
Re: How to remember values in dcl windows
« Reply #4 on: August 04, 2022, 09:26:21 AM »
Thanks for your replies.

For example, if you were to assign the values obtained through the dialog interface to global variables (or perhaps a single global variable containing a list of values), the variable would be defined within the document namespace and therefore the values would be accessible from the active drawing and would persist for the duration of active drawing session.
I want it to work that way. This Lisp will be used by 4 other users, so they should not interfere with each other (what apparently can happen if we will use additional file).

Have a look at this its a library routine you can have from 1 to about 20 lines of input, it uses a list for input there are examples in code. Its dynamic in that the number of items in list is how big the dcl ends up.
I dont know why, but i cant download your file.

Basically what I wrote SQLiteLisp for. OpenDCL has an archive feature to persist data. Lots of cool ways to persist data
I started learning OpenDCL and i will try to use it in my next Lisp. But that one i wanted to finish without any additional soft as a learning process.

Lee Mac

  • Seagull
  • Posts: 12752
  • London, England
Re: How to remember values in dcl windows
« Reply #5 on: August 04, 2022, 12:38:48 PM »
For example, if you were to assign the values obtained through the dialog interface to global variables (or perhaps a single global variable containing a list of values), the variable would be defined within the document namespace and therefore the values would be accessible from the active drawing and would persist for the duration of active drawing session.
I want it to work that way. This Lisp will be used by 4 other users, so they should not interfere with each other (what apparently can happen if we will use additional file).

It depends on where the file is stored - if the file is local to each user, then each user can store their own personal set of dialog values.

Rufusff7

  • Mosquito
  • Posts: 6
Re: How to remember values in dcl windows
« Reply #6 on: August 05, 2022, 04:35:58 AM »
I store it at server, so if i will update something it will be automatically updated for my colleagues.

Variables in my lisp are global (system remember them after i run lisp). But still when DCL window pop-up variables the are still old. Right now i more or less understand how DCL -> LSP connection works. But i have no idea how to connect LSP -> DCL, or LSP <-> DCL.

beck's bolero

  • Retired
  • Needs a day job
  • Posts: 7672
  • AKA Daniel
Re: How to remember values in dcl windows
« Reply #7 on: August 05, 2022, 11:53:53 PM »
FYI, OpenDCL has an archive feature to store lists in a file
Retired

beck's bolero

  • Retired
  • Needs a day job
  • Posts: 7672
  • AKA Daniel
Re: How to remember values in dcl windows
« Reply #8 on: August 06, 2022, 09:01:20 AM »
found them in the opendcl docs, so you can save the state of your dialogs or other data

dcl-BinFile-Read
dcl-BinFile-Write
Retired

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to remember values in dcl windows
« Reply #9 on: August 07, 2022, 06:06:12 AM »
OP is talking about DCL, not OpenDCL.

beck's bolero

  • Retired
  • Needs a day job
  • Posts: 7672
  • AKA Daniel
Re: How to remember values in dcl windows
« Reply #10 on: August 07, 2022, 08:39:49 AM »
OP is talking about DCL, not OpenDCL.

Yeppers, no reason op couldn't use both : )
I guess I just cringe when I see DCL  :lol:
Retired

Rufusff7

  • Mosquito
  • Posts: 6
Re: How to remember values in dcl windows
« Reply #11 on: October 05, 2022, 08:12:02 AM »
Hi, again. I finnaly finished what i wanted, and decided to post it here in case somebody looking how to solve a simillar task. I used Lee Mac's idea with Excel file to store values and set_tile function to create that AutoCAD <-> Excel connection:

Code - Auto/Visual Lisp: [Select]
  1. (defun C:SDBOX (/)
  2.  
  3. ;Read values from excel file and convert numbers to a strings
  4.  
  5. (setq xlApp (vlax-get-or-create-object "excel.application"))
  6. (setq xlWb (vlax-get-property xlApp "workbooks"))
  7. (vlax-invoke-method xlWb "open" "C:/Users/rufus/Desktop/test/test.xls")
  8. (setq xlSheet (vlax-get-property xlApp "activesheet"))
  9. ;-----Box-----
  10. (setq xlRange1 (vlax-get-property xlSheet "Range" "B1"))
  11. (setq A (rtos (vlax-variant-value (vlax-get-property xlRange1 'Value2))))
  12.  
  13. (setq xlRange2 (vlax-get-property xlSheet "Range" "B2"))
  14. (setq B (rtos (vlax-variant-value (vlax-get-property xlRange2 'Value2))))
  15.  
  16. (setq xlRange3 (vlax-get-property xlSheet "Range" "B3"))
  17. (setq C (rtos (vlax-variant-value (vlax-get-property xlRange3 'Value2))))
  18. ;-----Slope-----  
  19. (setq xlRange4 (vlax-get-property xlSheet "Range" "B4"))
  20. (setq A1 (rtos (vlax-variant-value (vlax-get-property xlRange4 'Value2))))
  21.  
  22. (setq xlRange5 (vlax-get-property xlSheet "Range" "B5"))
  23. (setq CHb (rtos (vlax-variant-value (vlax-get-property xlRange5 'Value2))))
  24.  
  25. (setq xlRange6 (vlax-get-property xlSheet "Range" "B6"))
  26. (setq C1f (rtos (vlax-variant-value (vlax-get-property xlRange6 'Value2))))
  27.  
  28. (setq xlRange7 (vlax-get-property xlSheet "Range" "B7"))
  29. (setq C1b (rtos (vlax-variant-value (vlax-get-property xlRange7 'Value2))))
  30. ;-----Chamfer-----    
  31. (setq xlRange8 (vlax-get-property xlSheet "Range" "B8"))
  32. (setq CHt (rtos (vlax-variant-value (vlax-get-property xlRange8 'Value2))))
  33. ;-----Drain_Tube---------    
  34. (setq xlRange9 (vlax-get-property xlSheet "Range" "B9"))
  35. (setq D (rtos (vlax-variant-value (vlax-get-property xlRange9 'Value2))))
  36.  
  37. (setq xlRange10 (vlax-get-property xlSheet "Range" "B10"))
  38. (setq Dr (rtos (vlax-variant-value (vlax-get-property xlRange10 'Value2))))
  39.  
  40. (setq xlRange11 (vlax-get-property xlSheet "Range" "B11"))
  41. (setq B1 (rtos (vlax-variant-value (vlax-get-property xlRange11 'Value2))))  
  42. ;-----Handrails-----    
  43. (setq xlRange12 (vlax-get-property xlSheet "Range" "B12"))
  44. (setq E (rtos (vlax-variant-value (vlax-get-property xlRange12 'Value2))))
  45.  
  46. (setq xlRange13 (vlax-get-property xlSheet "Range" "B13"))
  47. (setq D1 (rtos (vlax-variant-value (vlax-get-property xlRange13 'Value2))))
  48.  
  49. (setq xlRange14 (vlax-get-property xlSheet "Range" "B14"))
  50. (setq Gf (rtos (vlax-variant-value (vlax-get-property xlRange14 'Value2))))
  51.  
  52. (setq xlRange15 (vlax-get-property xlSheet "Range" "B15"))
  53. (setq Hf (rtos (vlax-variant-value (vlax-get-property xlRange15 'Value2))))
  54.  
  55. (setq xlRange16 (vlax-get-property xlSheet "Range" "B16"))
  56. (setq F1 (rtos (vlax-variant-value (vlax-get-property xlRange16 'Value2))))
  57.  
  58. (setq xlRange17 (vlax-get-property xlSheet "Range" "B17"))
  59. (setq F2 (rtos (vlax-variant-value (vlax-get-property xlRange17 'Value2))))
  60.  
  61. (setq xlRange18 (vlax-get-property xlSheet "Range" "B18"))
  62. (setq Gs (rtos (vlax-variant-value (vlax-get-property xlRange18 'Value2))))
  63.  
  64. (setq xlRange19 (vlax-get-property xlSheet "Range" "B19"))
  65. (setq Hs (rtos (vlax-variant-value (vlax-get-property xlRange19 'Value2))))
  66.  
  67. (setq xlRange20 (vlax-get-property xlSheet "Range" "B20"))
  68. (setq Hr (rtos (vlax-variant-value (vlax-get-property xlRange20 'Value2))))
  69.  
  70.  
  71. ;-----Read_Slide_From_DCL-----
  72. (defun updateimage (sldname key)
  73. (setq width(dimx_tile key))
  74. (setq height(dimy_tile key))
  75. (fill_image 0 0 width height 0)
  76. (slide_image (- 0 130) (- 0 25) 1000 500 sldname)
  77. )  
  78. ;Open dcl and convert strings to integers
  79.  
  80.   (setq dcl_id (load_dialog "C:/Users/rufus/Desktop/test/Dbox_Window_Test.dcl"))
  81.   (if (not (new_dialog "d1" dcl_id))
  82.     (exit)
  83.   );if
  84. (setq myslidename "C:/Users/rufus/Desktop/DBox/DBox/Dbox.sld")
  85. (setq mykey "dbimage")
  86. (updateimage myslidename mykey)
  87.  
  88. (set_tile "W_A" A)
  89. (set_tile "W_B" B)
  90. (set_tile "W_C" C)
  91.  
  92. (set_tile "W_A1" A1)
  93. (set_tile "W_CHb" CHb)  
  94. (set_tile "W_C1f" C1f)
  95. (set_tile "W_C1b" C1b)
  96.  
  97. (set_tile "W_CHt" CHt)
  98.  
  99. (set_tile "W_D" D)
  100. (set_tile "W_Dr" Dr)
  101. (set_tile "W_B1" B1)
  102.  
  103. (set_tile "W_E" E)
  104. (set_tile "W_D1" D1)
  105. (set_tile "W_Gf" Gf)
  106. (set_tile "W_Hf" Hf)  
  107. (set_tile "W_F1" F1)
  108. (set_tile "W_F2" F2)
  109. (set_tile "W_Gs" Gs)
  110. (set_tile "W_Hs" Hs)
  111. (set_tile "W_Hr" Hr)  
  112.  
  113.     "cancel"
  114.     "(done_dialog) (setq userclick nil)"
  115.   )
  116.     "accept"
  117.     (strcat
  118.       "(progn (setq A (atoi (get_tile \"W_A\")))"
  119.       "(setq B (atoi (get_tile \"W_B\")))"
  120.       "(setq C (atoi (get_tile \"W_C\")))"
  121.      
  122.       "(setq A1 (atoi (get_tile \"W_A1\")))"
  123.       "(setq CHb (atoi (get_tile \"W_CHb\")))"
  124.       "(setq C1f (atoi (get_tile \"W_C1f\")))"
  125.       "(setq C1b (atoi (get_tile \"W_C1b\")))"
  126.      
  127.       "(setq CHt (atoi (get_tile \"W_CHt\")))"
  128.      
  129.       "(setq D (atoi (get_tile \"W_D\")))"
  130.       "(setq Dr (atoi (get_tile \"W_Dr\")))"
  131.       "(setq B1 (atoi (get_tile \"W_B1\")))"
  132.      
  133.       "(setq E (atoi (get_tile \"W_E\")))"
  134.       "(setq D1 (atoi (get_tile \"W_D1\")))"
  135.       "(setq Gf (atoi (get_tile \"W_Gf\")))"
  136.       "(setq Hf (atoi (get_tile \"W_Hf\")))"
  137.       "(setq F1 (atoi (get_tile \"W_F1\")))"
  138.       "(setq F2 (atoi (get_tile \"W_F2\")))"
  139.       "(setq Gs (atoi (get_tile \"W_Gs\")))"
  140.       "(setq Hs (atoi (get_tile \"W_Hs\")))"
  141.       "(setq Hr (atoi (get_tile \"W_Hr\")))"
  142.       " (done_dialog)(setq userclick T))"
  143.     )
  144.   )
  145.   (unload_dialog dcl_id)
  146.  
  147. ;Write values in to excel file
  148.  
  149. (vlax-put-property xlRange1 'Value2 A)  
  150. (vlax-put-property xlRange2 'Value2 B)  
  151. (vlax-put-property xlRange3 'Value2 C)
  152.  
  153. (vlax-put-property xlRange4 'Value2 A1)
  154. (vlax-put-property xlRange5 'Value2 CHb)  
  155. (vlax-put-property xlRange6 'Value2 C1f)
  156. (vlax-put-property xlRange7 'Value2 C1b)
  157.  
  158. (vlax-put-property xlRange8 'Value2 CHt)
  159.  
  160. (vlax-put-property xlRange9 'Value2 D)  
  161. (vlax-put-property xlRange10 'Value2 Dr)
  162. (vlax-put-property xlRange11 'Value2 B1)
  163.  
  164. (vlax-put-property xlRange12 'Value2 E)
  165. (vlax-put-property xlRange13 'Value2 D1)
  166. (vlax-put-property xlRange14 'Value2 Gf)  
  167. (vlax-put-property xlRange15 'Value2 Hf)      
  168. (vlax-put-property xlRange16 'Value2 F1)  
  169. (vlax-put-property xlRange17 'Value2 F2)  
  170. (vlax-put-property xlRange18 'Value2 Gs)  
  171. (vlax-put-property xlRange19 'Value2 Hs)  
  172. (vlax-put-property xlRange20 'Value2 Hr)
  173.      
  174. ;-----Realease_objects-----  
  175. (vlax-release-object xlRange20)  
  176. (vlax-invoke-method (vlax-get-property xlApp "Activeworkbook") 'Close :vlax-True)
  177.  
  178. ;-----Save_Properties-----
  179. (setq bp (getpoint "\nEnter insertion point"))
  180. (setq ss (ssadd))
  181. (setq osm (getvar "osmode"))
  182. (setq osm3 (getvar "3Dosmode"))
  183. (setvar "osmode" 0)
  184. (setvar "3dosmode" 0)
  185. (command "._view" "s" "dbox1" """")
  186. ;-----3D_Geometry_Function-----
  187. ;-----Creating_Box-----
  188. (setq r2 (mapcar '+ (list A 0 0) bp))
  189. (setq r3 (mapcar '+ (list A B 0) bp))
  190. (setq r4 (mapcar '+ (list 0 B 0) bp))
  191. (command "._pline" bp r2 r3 r4 bp "")
  192. (command "._extrude" (entlast) "" C)
  193. (setq box (entlast))
  194. (command "._view" "_se")
  195. (command "._VSCURRENT" 2 "")
  196. ...
  197.  
  198. ;-----Return_Properties-----
  199. (command "._view" "r" "dbox1")
  200. (setvar "osmode" osm)
  201. (setvar "3Dosmode" osm3)
  202. ;-----Rotate-----
  203. (command "._group" "c" "*" "group_desc" ss "")
  204. (command "._rotate3D" ss "" bp r10)
  205. ) ;End_function
  206.  
  207. ;CODING ENDS HERE
  208.  
  209.  
« Last Edit: October 13, 2022, 04:31:32 PM by Rufusff7 »

Lee Mac

  • Seagull
  • Posts: 12752
  • London, England
Re: How to remember values in dcl windows
« Reply #12 on: October 06, 2022, 04:57:50 PM »
Is there a reason that you used an Excel file over a plain text file?

BIGAL

  • Swamp Rat
  • Posts: 1136
  • 40 + years of using Autocad
Re: How to remember values in dcl windows
« Reply #13 on: October 06, 2022, 10:44:57 PM »
Why not save in dwg ? Can use get to retrieve the values.

Code: [Select]
(vlax-ldata-put "AlanH" "Layoutname" client )
(vlax-ldata-put "AlanH" "Ahscale" ahsc)
A man who never made a mistake never made anything

Rufusff7

  • Mosquito
  • Posts: 6
Re: How to remember values in dcl windows
« Reply #14 on: October 07, 2022, 10:58:24 AM »
Is there a reason that you used an Excel file over a plain text file?
Lack of knowledge i think is the only reason. I found the way how to connect each value to each expression in excel, but for text file i only know how to write values like this: 100, 200, 300... etc. And i have no idea how i can read them after so each value will match each expression.

Quote
Why not save in dwg ? Can use get to retrieve the values.
I didnt know that this is possible. My idea was to have values at the first start of program in DCL window, then to modify them, those modified values must be saved so after i run programm again there will be new values in DCL window. If i understood that function correctly then i can store values in object (3D model i created for example) and then use them at a second run of a programm, but what shoud i do with the first run then, where i can take values?