Code Red > Visual DCL Programming

How to remember values in dcl windows

(1/4) > >>

Rufusff7:
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: ---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;
}
--- End code ---

LSP part:

--- Code: ---;-----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")))
)

--- End code ---

All files of this program in attachment.



Lee Mac:
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:
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.

It's Alive!:
Basically what I wrote SQLiteLisp for. OpenDCL has an archive feature to persist data. Lots of cool ways to persist data

Rufusff7:
Thanks for your replies.


--- Quote from: Lee Mac on July 25, 2022, 05:33:29 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.

--- End quote ---
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).


--- Quote from: BIGAL 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.

--- End quote ---
I dont know why, but i cant download your file.


--- Quote from: It's Alive! 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

--- End quote ---
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.

Navigation

[0] Message Index

[#] Next page

Go to full version