Dialog Box. Save options for other drawings/ sessions..

Dialog Box. Save options for other drawings/ sessions..

C.Utzinger
Collaborator Collaborator
1,144 Views
13 Replies
Message 1 of 14

Dialog Box. Save options for other drawings/ sessions..

C.Utzinger
Collaborator
Collaborator

HI

 

I have this Dialog Box and the UNFINISHED Code for it.

 

What i Need ist to save the chosen option from tog1 tog2 and tog3 for the next session and other drawings.

 

Ist nasty that the sysvar USERI1-5 just are saved for the drawing and not for other ones.

 

An Idea? I was reading about creating a own system variable, but it was to difficult for me.

 

 

SPIComax
 
: dialog
 
{
label = "Comax Beschriftung";

	: boxed_column {
	label = "Wähle eine Beschriftung:";

	: row {
	fixed_width = true;
    	alignment = centered;

		: button {
		key = "button1" ;
		label = "Comax 83cm + 125cm" ;
		height = 3;
		is_default = false;
		}
		
		: button {
		key = "button2" ;
		label = "Comax 83cm" ;
		height = 3;
		is_default = false;
		}

		: button {
		key = "button3" ;
		label = "Comax 125cm" ;
		height = 3;
		is_default = false;
		}

		}
	
	: spacer {height = 0.3;}

	: column {
	fixed_width = true;
    	alignment = left;

		: toggle {
		key = "tog1" ;
		label = "Mit Multiführungslinie*" ;
		}

		: toggle {
		key = "tog2" ;
		label = "Nur Text" ;
		}	
		}

	}

	: spacer {height = 0.5;}
	
	: boxed_column {
	label = "*Achtung MGB Option Multiführungslinie ausschalten!";

		: row {
		
		: paragraph 
		{
		: text_part
		{
		label = "Erst Verfügbar ab MGB 2017 ServicePack 2.0";
		alignment = left;
		}}

		: button {
		key = "MGB";
		label = "MGB Optionen";
		is_default = false;
		}
		}
		
	
		: column {
		: toggle {
		key = "tog3" ;
		label = "Option Aus (Pflichtfeld) --> Bei Falschanwendung Absturzgefahr!" ;
		}
		}


	}

	: spacer {height = 0.1;}
	
	: row {
	fixed_width = false;
	
		: paragraph 
		{
		: text_part
		{
		label = "By: Pepito";
		alignment = left;
		}
		}

		: button
		{
		key = "abbrechen";
		label = "Abbrechen";
		is_default = false;
 		is_cancel = true;
		height = 2;
		alignment = right;
		}


		}

}
(defun C:<Test7 (/ dcl_id btog1 btog2 btog3 tog12var tog3var butt1 butt2 butt3 BMGB)

(setq dcl_id (load_dialog "SPI-Comax.dcl"))
 
     (if (not (new_dialog "SPIComax" dcl_id))
	 (exit )
     ); end of if

(defun Knopfcheck () 
(setq btog1 (atoi(get_tile "tog1")))
(setq btog2 (atoi(get_tile "tog2")))
(setq btog3 (atoi(get_tile "tog3")))
)

(defun uservar () 
	(if (= tog12var 1)(set_tile "tog1" "1"))
	(if (= tog12var 2)(set_tile "tog2" "1"))
	(if (= tog3var 1)(set_tile "tog3" "1")))

(defun Deselect1 ( a / ) (if (= a "1")(set_tile "tog1" "0")))
(defun Deselect2 ( a / ) (if (= a "1")(set_tile "tog2" "0")))

(action_tile "tog1" "(Deselect2 $value)")  
(action_tile "tog2" "(Deselect1 $value)")
(action_tile "tog3" "(setq btog3 1)")

(action_tile "button1"
    "(Knopfcheck)(setq butt1 1)(done_dialog)"
    );end of action_tile

(action_tile "button2"
    "(Knopfcheck)(setq butt2 1)(done_dialog)"
    );end of action_tile

(action_tile "button3"
    "(Knopfcheck)(setq butt3 1)(done_dialog)"
    );end of action_tile

(action_tile "MGB"
    "(setq BMGB 1)(done_dialog)"
    );end of action_tile

(action_tile "abbruch"	
    "(setq BMGB nil btog1 nil btog2 nil btog3 nil butt1 nil butt2 nil butt3 nil) 
     (done_dialog)" 
    );end of action_tile

(start_dialog)
(unload_dialog dcl_id)
 
(princ)

(if (and (= butt1 1)(= btog1 1)(= btog3 1))
			(progn  
			(command "kreis" pause pause)
			(princ "Kreis gezeichnet! ")
			(prin1)))

(if (and (= butt1 1)(= btog2 1))
			(progn  
			(command "_pline" pause pause pause "")
			(princ "Polynilie gezeichnet! ")
			(prin1)))

(if (and (= butt2 1)(= tog12var 1)) 
			(progn  
			(command "_line" pause pause "")
			(princ "Linie gezeichnet! ")
			(prin1)))

(if (= butt3 1) 
			(progn  
			(command "rechteck" pause pause)
			(princ "Rechteck gezeichnet! ")
			(prin1)))

(prin1)

) ; end of defun
0 Likes
Accepted solutions (1)
1,145 Views
13 Replies
Replies (13)
Message 2 of 14

john.uhden
Mentor
Mentor
Accepted solution

I thought we just discussed this with you recently.

 

Near the end of your code add (setenv "UTZ:tog1" btog1) ; presuming I have the right symbol name and that it is a string value.

 

AND, right after you load the DCL you can retrieve the value via (setq btog1 (getenv "UTZ:tog1")) and then (set_tile "tog1" btog1), or to please Mr. Cooper just (set_tile "tog1" (setq btog1 (getenv "UTZ:tog1")))

 

Both the variable and its value must be strings.  Note that I preceded the variable names with "UTZ:" because you don't want to inadvertently overwrite some variable in the environment used by AutoCAD or some other add-on.  IOW, be sure it's unique.  The obvious way is to see what (getenv "varname") returns at the command prompt, though I doubt you will find any beginning with "UTZ:".

John F. Uhden

0 Likes
Message 3 of 14

C.Utzinger
Collaborator
Collaborator

Hi

 

Thank you very much for your answer.

 

I was trying something like that, but of course i did it wrong Smiley LOL...

 

I will try and let you know.

 

 

Kind regards

 

 

Note: Yes we talk about it recenlty in another discussion, but i didn´t understand it,  i asked again und there was no answer. Perhaps my english is to bad...

0 Likes
Message 4 of 14

C.Utzinger
Collaborator
Collaborator

Sorry I have to apologize and correct myself.

 

You did answer me, but I have it on standby, because i'm very very busy.

 

 

Thank you again!

0 Likes
Message 5 of 14

C.Utzinger
Collaborator
Collaborator

HI

 

SO! The function getenv and setenv seem to work.

 

For the setenv i needed to convert to string.

 

Thank you very much!

 

 

(defun C:<Test7 (/ dcl_id  btog1 btog2 btog3 tog12var tog3var butt1 butt2 butt3 BMGB)

(setq dcl_id (load_dialog "SPI-Comax.dcl"))
 
     (if (not (new_dialog "SPIComax" dcl_id))
	 (exit )
     ); end of if

(setq btog1 (getenv "UTZ:tog1"))

(set_tile "tog1" btog1)

(defun Knopfcheck () 
(setq btog1 (atoi(get_tile "tog1")))
(setq btog2 (atoi(get_tile "tog2")))
(setq btog3 (atoi(get_tile "tog3")))
)

(defun uservar () 
	(if (= tog12var 1)(set_tile "tog1" "1"))
	(if (= tog12var 2)(set_tile "tog2" "1"))
	(if (= tog3var 1)(set_tile "tog3" "1")))

(defun Deselect1 ( a / ) (if (= a "1")(set_tile "tog1" "0")))
(defun Deselect2 ( a / ) (if (= a "1")(set_tile "tog2" "0")))

(action_tile "tog1" "(Deselect2 $value)")  
(action_tile "tog2" "(Deselect1 $value)")
(action_tile "tog3" "(setq btog3 1)")

(action_tile "button1"
    "(Knopfcheck)(setq butt1 1)(done_dialog)"
    );end of action_tile

(action_tile "button2"
    "(Knopfcheck)(setq butt2 1)(done_dialog)"
    );end of action_tile

(action_tile "button3"
    "(Knopfcheck)(setq butt3 1)(done_dialog)"
    );end of action_tile

(action_tile "MGB"
    "(setq BMGB 1)(done_dialog)"
    );end of action_tile

(action_tile "abbruch"	
    "(setq BMGB nil btog1 nil btog2 nil btog3 nil butt1 nil butt2 nil butt3 nil) 
     (done_dialog)" 
    );end of action_tile

(start_dialog)
(unload_dialog dcl_id)
 
(princ)

(if (and (= butt1 1)(= btog1 1)(= btog3 1))
			(progn  
			(command "kreis" pause pause)
			(princ "Kreis gezeichnet! ")
			(prin1)))

(if (and (= butt1 1)(= btog2 1))
			(progn  
			(command "_pline" pause pause pause "")
			(princ "Polynilie gezeichnet! ")
			(prin1)))

(if	(= butt2 1) (progn  
			(command "_line" pause pause "")
			(princ "Linie gezeichnet! ")
			(prin1)))

(if	(= butt3 1) (progn  
			(command "rechteck" pause pause)
			(princ "Rechteck gezeichnet! ")
			(prin1)))

(setenv "UTZ:tog1" (itoa btog1))

(prin1)

) ; end of defun

 

0 Likes
Message 6 of 14

john.uhden
Mentor
Mentor

If it works for you, please hit the "Select as Solution" button.  Or if you have already, then thank you.  We always like to know if our help is really helpful.

John F. Uhden

0 Likes
Message 7 of 14

scot-65
Advisor
Advisor
SETENV and GETENV are now obsolete (R2016).
Look into VL-REGISTRY-READ and VL-REGISTRY-WRITE.

vl-registry-read
Returns data stored in the Windows registry for the specified key/value pair

vl-registry-write
Creates a key in the Windows registry

Values are strings.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 8 of 14

john.uhden
Mentor
Mentor
Thanks, Scott, for that info.

As you may be aware, I've been stuck in 2002.

I think Mr. Utzinger needs to know that he must concatenate with, say:

(setq Path
(strcat "HKEY_CURRENT_USER\\" (vlax-product-key)
"\\FixedProfile\\General")
)
followed (later) by
(vl-registry-write Path Key Value)
where Key would be his "UTZ:bog1" or similar.
and Value is the value (bog1) that he wants to write.

right?

Or, if Path is a global...

(defun setenv (Key Value)
(vl-registry-write Path Key Value)
)

and

(defun getenv (Key)
(vl-registry-read Path Key)
)

Right?

John F. Uhden

0 Likes
Message 9 of 14

C.Utzinger
Collaborator
Collaborator

Hi

 

Another question...

 

Is it possible to remember (just for drawing session) the last option from "button1" "button2" "button3" so when I start again the Dialog box I have just to hit ENTER???

 

Thank you...

 

 

(defun C:<Test7 (/ dcl_id btog1 btog2 btog3 butt1 butt2 butt3 BMGB)

(setq dcl_id (load_dialog "SPI-Comax.dcl"))
 
     (if (not (new_dialog "SPIComax" dcl_id))
	 (exit )
     ); end of if

(if (getenv "UTZ:tog1")(set_tile "tog1" (setq btog1 (getenv "UTZ:tog1"))))
(if (getenv "UTZ:tog2")(set_tile "tog2" (setq btog2 (getenv "UTZ:tog2"))))
(if (getenv "UTZ:tog3")(set_tile "tog3" (setq btog3 (getenv "UTZ:tog3"))))

(if (not(= btog1 nil))(setq btog1 (atoi btog1)))
(if (not(= btog2 nil))(setq btog2 (atoi btog2)))
(if (not(= btog3 nil))(setq btog3 (atoi btog3)))

(defun UTZvar ()
	(setenv "UTZ:tog1" (itoa btog1))
	(setenv "UTZ:tog2" (itoa btog2))
	(setenv "UTZ:tog3" (itoa btog3))
	(princ "\nOptionen Gespeichert! \n"))

(defun Knopfcheck () (setq btog1 (atoi(get_tile "tog1")) btog2 (atoi(get_tile "tog2")) btog3 (atoi(get_tile "tog3"))))

(defun Deselect1 ( a / ) (if (= a "1")(set_tile "tog1" "0")))
(defun Deselect2 ( a / ) (if (= a "1")(set_tile "tog2" "0")))

(action_tile "tog1" "(Deselect2 $value)")  
(action_tile "tog2" "(Deselect1 $value)")
(action_tile "tog3" "")

(if (not(= butt1 nil))(set_tile "button1" "1"))
(if (not(= butt2 nil))(set_tile "button2" "1"))
(if (not(= butt3 nil))(set_tile "button3" "1"))

(action_tile "button1"
    "(Knopfcheck)(setq butt1 1)(done_dialog)")

(action_tile "button2"
    "(Knopfcheck)(setq butt2 1)(done_dialog)")

(action_tile "button3"
    "(Knopfcheck)(setq butt3 1)(done_dialog)")

(action_tile "MGB"
    "(setq BMGB 1)(Knopfcheck)(UTZvar)(done_dialog)")

(action_tile "speichern"	
    "(Knopfcheck)(UTZvar)" )

(action_tile "abbruch" "")

(start_dialog)
(unload_dialog dcl_id)
 
(princ)

(if     (= BMGB 1) (progn
			(c:BemSetupLinear)
			(c:<Test7)))
			

(if (and (= butt1 1)(= btog1 1)(= btog3 1))
			(progn  
			(command "kreis" pause pause)
			(princ "Kreis gezeichnet! ")
			(prin1)))

(if (and (= butt1 1)(= btog2 1))
			(progn  
			(command "_pline" pause pause pause "")
			(princ "Polynilie gezeichnet! ")
			(prin1)))

(if	(= butt2 1) (progn  
			(command "_line" pause pause "")
			(princ "Linie gezeichnet! ")
			(prin1)))

(if	(= butt3 1) (progn  
			(command "rechteck" pause pause)
			(princ "Rechteck gezeichnet! ")
			(prin1)))

(setenv "UTZ:tog1" (itoa btog1))
(setenv "UTZ:tog2" (itoa btog2))
(setenv "UTZ:tog3" (itoa btog3))

(prin1)
) ; end of defun
0 Likes
Message 10 of 14

john.uhden
Mentor
Mentor
Yes. Just leave the values under unique symbol names as global, meaning
not local.

F'rinstance...

(setq UTZ:tog1 (get_tile "tog1")) to save it.

And, to retrieve it...
(or
(setq tog1 UTZ:tog1)
(setq tog1 (getenv "UTZ:tog1"))
(setq tog1 "1")
)

John F. Uhden

0 Likes
Message 11 of 14

scot-65
Advisor
Advisor
As John suggested, do not declare the symbol name
in the opening defun. I have many of these that might
come into play and there could be conflicts with these
Gremlins. For this I use the following naming structure:

USER_CommandName

(defun c:ABC ( / a b c )
(setq USER_ABC "This is a session only Gremlin")
(princ)
)

If there are more than one name to remember, create
a LIST and access this list using NTH.
(setq USER_ABC (list
(get_tile "Rad00")
(get_tile "Tog02")
(get_tile "Edi03")
))

As a side note to the above, "remember values from
last time" will require initialization for the DCL:
(or USER_ABC (setq USER_ABC (list "Rad01" "0" "Name")))

Let's expand on where to saving settings...

For user-specific settings and the like, such as
remembering the OSMODE value, write to the registry.

For project specific data, write to a file. INI format is
acceptable however there is no mechanism to read
the INI structured file. Creating one is not that hard.

For file specific data, look into VLAX-LDATA-PUT.
This is the file's dictionary.

For file specific data that one may want to copy-clip
(transfer) to another file, embed the data into an object.
One will have to create a REGAPP (this along with
SETCFG was the only way to store settings back in the
good 'ol days without writing to a separate file).

For session only Gremlins, do not declare the symbol
name in the opening defun. Be careful when naming
these.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 12 of 14

john.uhden
Mentor
Mentor

Very wise advice, Scot, though maybe over many heads at their point in learning.

 

Some guru here years ago (probably Tony T.) told me to never use vlax-ldata-put as it would corrupt the drawing.  I never had a problem using it even between ACAD versions.

 

Anyway, that's why I suggested using the (or ...) approach.

John F. Uhden

0 Likes
Message 13 of 14

C.Utzinger
Collaborator
Collaborator

I'm getting crazy...

 

I have now a version with Radio Buttons and an OK button, there I have no Problem to save and retrieve the options.

 

But with Buttons i could not make it work.

 

Please help again...

0 Likes
Message 14 of 14

john.uhden
Mentor
Mentor
I really haven't confirmed this, but radio buttons and other tiles can have
values, but regular buttons don't. You just press one to perform an
action, and its only value is that it has been pressed.

Now you could set a value based on its being pressed...
(action_tile "Yes" "(setq yes 1)")
(action_tile "No" "(setq yes nil)")

But you can't set a default value prior to any action, except if you want
to (setq yes 1) earlier in your lisp code, so that if "No" is never pressed
then yes remains at 1.

John F. Uhden

0 Likes