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

0 Members and 1 Guest are viewing this topic.

Rufusff7

  • Mosquito
  • Posts: 3
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: 12696
  • 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: 1037
  • 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

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7320
  • 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: 3
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: 12696
  • 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: 3
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.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7320
  • 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

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7320
  • 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.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7320
  • 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