TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: BlackBox on May 23, 2012, 01:08:25 PM

Title: 2011+ | Custom System Variables
Post by: BlackBox on May 23, 2012, 01:08:25 PM
I know that in LISP one can simply declare a global variable, or use either Get/SetEnv, or vl-registry-write/read... or in .NET since there is no global variable, one can simply store a 'parameters' Object to Application.DocumentManager.MdiActiveDocument.UserData Hashtable (I think I got the Namespace right?), but how does one create their own custom system variable(s)?

I've read Kean's article (http://through-the-interface.typepad.com/through_the_interface/2011/02/creating-the-smallest-possible-circle-around-2d-autocad-geometry-using-net.html), where toward the end he mentions that in 2011 and newer, you can use a similar .REG file to create your own system variables.

Unfortunately, at present, permissions to HKLM hive is a problem for me. I've put in a request to IT, but it is unlikely to be granted.

I noticed that HKCU hive has a few Variables folders as well, but limited testing has been unsuccessful. Being able to create custom system variable(s) would prove useful for both LISP & .NET initiatives.

TIA
Title: Re: 2011+ | Custom System Variables
Post by: irneb on May 23, 2012, 01:42:45 PM
Doing some searches, it appears that you can't even do this using ObjectARX, never mind DotNet/Lsp. Granted I've only done about 30min of research, so perhaps there's some way of hacking a sysvar into life.

I'd think it "should"be possible, since I can imagine a dictionary holding the sysvars (their names being the key) and having a object to refer to where the var is saved (dwg / reg / volatile). I'm sure adesk didn't simply hard-code all sysvars. ... actually I hope  :ugly:
Title: Re: 2011+ | Custom System Variables
Post by: BlackBox on May 23, 2012, 01:46:27 PM
Perhaps this will better illustrate:

Title: Re: 2011+ | Custom System Variables
Post by: Jeff H on May 23, 2012, 01:48:52 PM
Take a look at Variable class in docs.
 
Tony T has a example floating around and
http://www.theswamp.org/index.php?topic=40774.msg460505#msg460505 (http://www.theswamp.org/index.php?topic=40774.msg460505#msg460505)
Title: Re: 2011+ | Custom System Variables
Post by: BlackBox on May 23, 2012, 01:50:54 PM
What bothers me, is that these Keys are also available under HKCU at the version, and profile levels:
Title: Re: 2011+ | Custom System Variables
Post by: BlackBox on May 23, 2012, 01:59:27 PM
Take a look at Variable class in docs.
 
Tony T has a example floating around and
http://www.theswamp.org/index.php?topic=40774.msg460505#msg460505 (http://www.theswamp.org/index.php?topic=40774.msg460505#msg460505)

I haven't seen Tony's example (yet - I'll look for it after work, oh crap, second job tonight!), but this snippet from Gile should allow me to code a LispFunction Method:

Code - C#: [Select]
  1.  
  2. // snip
  3.                //hive = Registry.LocalMachine;
  4.                RegistryKey hive = Registry.LocalMachine;
  5.                //
  6.                using (RegistryKey ack = hive.OpenSubKey(prodk, true))
  7.                {
  8.                    // Create the sysvar definition key
  9.                    using (RegistryKey vark = ack.OpenSubKey("Variables", true))
  10.                    {
  11.                        if (vark.GetSubKeyNames().Contains("LAYLOCKSEL"))
  12.                        {
  13.                            MessageBox.Show("LAYLOCKSEL is already installed", "LAYLOCKSEL");
  14.                            return;
  15.                        }
  16.                        else
  17.                        {
  18.                            using (RegistryKey rk = vark.CreateSubKey("LAYLOCKSEL"))
  19.                            {
  20.                                rk.SetValue("", 0, RegistryValueKind.String);
  21.                                rk.SetValue("LowerBound", 0, RegistryValueKind.DWord);
  22.                                rk.SetValue("PrimaryType", 5003, RegistryValueKind.DWord);
  23.                                rk.SetValue("StorageType", 1, RegistryValueKind.DWord);
  24.                                rk.SetValue("UpperBound", 1, RegistryValueKind.DWord);
  25.                            }
  26.                        }
  27.                    }
  28.  
  29. // snip
  30.  

I am somewhat shocked though, that (according to what I read quickly), all one must do is include a manifest in order to avoid permissions issues... Bloody brilliant!  :lmao:
Title: Re: 2011+ | Custom System Variables
Post by: BlackBox on May 23, 2012, 02:12:05 PM
I 'spose my next question is, that if the HKLM\*\Variables is for registering system variables, then does anyone know what are the HKCU\*\Variables Keys for (at the Version and Profile level)?  :?
Title: Re: 2011+ | Custom System Variables
Post by: gile on May 23, 2012, 03:20:59 PM
Hi,

I had a private discussion with Kean about custom sysvar ceation, here's his reply:
"Yes, my understanding is that writing to HKLM is currently required for sysvar registration, whether you use an EXE, an MSI with elevated privileges or even a REG file to create it."

IMO,using  these custom sysvar isn't so intersting with LISP as with .NET where it's possible to handle the Variable.Changing and Variable.Changed events.
Title: Re: 2011+ | Custom System Variables
Post by: BlackBox on May 23, 2012, 03:30:57 PM
Hi,

I had a private discussion with Kean about custom sysvar ceation, here's his reply:
"Yes, my understanding is that writing to HKLM is currently required for sysvar registration, whether you use an EXE, an MSI with elevated privileges or even a REG file to create it."

IMO,using  these custom sysvar isn't so intersting with LISP as with .NET where it's possible to handle the Variable.Changing and Variable.Changed events.

Gile, thanks for your reply. I continue to learn much from your (sometimes even old) posts.

My thought is to have some custom system variables for our internal apps, that would be accessible via getvar/setvar, and vlr-sysvar-reactor as applicable. I am personally starting to do a lot of C#.NET development, but sadly, I am one in a handful that is even interested in .NET development at my company. So whatever I do, needs to be accessible via LISP as well.

My intent is to code some LispFunction Methods to allow users to create and store custom system variables of their own as well. The point being to encourage, and simplify the process of, others creating efficiency initiatives.
Title: Re: 2011+ | Custom System Variables
Post by: Andrey Bushman on November 08, 2012, 01:44:52 AM
2 RenderMan
As variant for problem's solving (about HKLM): IT can to change ACL only for this registry key - to add necessary permissions for your windows profile.
Title: Re: 2011+ | Custom System Variables
Post by: Andrey Bushman on November 08, 2012, 01:54:09 AM
Where can I read about 'PrimaryType' parameter? Which values is allowed?
Title: Re: 2011+ | Custom System Variables
Post by: BlackBox on November 08, 2012, 08:52:21 AM
2 RenderMan
As variant for problem's solving (about HKLM): IT can to change ACL only for this registry key - to add necessary permissions for your windows profile.

Thanks for the suggestion, Andrey.

I actually did request the necessary permissions for HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\* segment of the HKLM hive, and that request was denied.
Title: Re: 2011+ | Custom System Variables
Post by: BlackBox on November 08, 2012, 08:53:56 AM
Where can I read about 'PrimaryType' parameter? Which values is allowed?

Perhaps this related post (http://72.77.202.9/index.php?topic=40774.msg460433#msg460433) will help.