Originally Posted by
Tommybluegrass
Has anyone tried to monitor “SECURELOAD” when it changes using a reactor and set it to something else?
Using other system variables seems to work. For some reason SECURELOAD is not recognized.
Below is what I am trying.
Code:
(vl-load-com)
(defun c:CKSL ()
(if *SECURELOADReactor*
(progn
(vlr-remove *SECURELOADReactor*)
(setq *SECURELOADReactor* nil)
(setq SECURELOAD:Callback nil)
(prompt "\nReactor stopped. ")
)
(progn
(setq *SECURELOADReactor*
(vlr-sysvar-reactor ;I have tried also “vlr-editor-reactor”
""
'(
(:vlr-sysvarchanged . SECURELOAD:Callback)
)
)
)
(defun SECURELOAD:Callback (rea var / varName)
(if
(and
(wcmatch (setq varName (strcase (car var))) "SECURELOAD")
(cdr var)
)
(setvar "SECURELOAD" 1); Problem is it just writes to the command line “SECURLOAD” 1. Like it doesn’t see setvar
;;; (alert
;;; (strcat "\n[App Event] : System Var Changed\t\t: " varName)
;;; )
)
)
(prompt "\nReactor started. ")
)
)
(princ)
)
ACAD Text Window (F2) results follow:
Code:
Command: CKSL <-- Manual execute of the reactor
Reactor started.
Command:
Command: 'VLIDE
Command:
Command: SECURELOAD
Enter new value for SECURELOAD <1>: 0 <-- changed the value manually.
; error: AutoCAD variable setting rejected: "SECURELOAD" 1 <-- Results of reactor -->but works if SECURELOAD is replaced with another sysvar like FILEDIA sysvars.
I wonder, is the a bug or Autodesk has prevented this from working.
Any advice or solution?
Firstly, if you're going to copy someone's publicly posted code, as you seem to have done with mine from here, that's perfectly fine, but you'd do well to kindly accredit the source.
Second, one is not permitted to change the SECURELOAD system variable within a SystemVariableChanged event handler... That may be due to this particular system variable being an integral part of the new AutoCAD security mechanism; it would stand to reason that it should not be permitted, but I do not know that for certain.
In order to accomplish this....
In a SystemVariableChanged event handler I'd first check for the target system variable(s), in this case SECURELOAD, check if it has in fact changed, then check if has been disabled (set to 0)... At which point I would unregister my SystemVariableChanged event handler, and register an Idle event handler (do not recall if this has been exposed to LISP), then within the Idle event handler I would unregister said event, and re-register the SystemVariableChanged event, making the applicable change(s)... All of this done to avoid an potential infinite loop.
Here's a quick example from .NET API, as I just happened to be in Visual Studio at the moment:
Code:
// BlackBoxCAD.com, 2014
//
using Autodesk.AutoCAD.Runtime;
using System;
using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
[assembly: ExtensionApplication(typeof(BlackBox.AutoCAD.SecureloadAuto.Events))]
namespace BlackBox.AutoCAD.SecureloadAuto
{
public class Events : IExtensionApplication
{
void IExtensionApplication.Initialize()
{
acApp.SystemVariableChanged += onSystemVariableChanged;
}
void IExtensionApplication.Terminate()
{
}
void onSystemVariableChanged(object sender,
Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs e)
{
if (e.Name.ToUpper() == "SECURELOAD" && e.Changed &&
Convert.ToInt32(acApp.GetSystemVariable("SECURELOAD")) == 0)
{
acApp.SystemVariableChanged -= onSystemVariableChanged;
acApp.Idle += onIdle;
}
}
void onIdle(object sender, EventArgs e)
{
acApp.Idle -= onIdle;
acApp.SetSystemVariable("SECURELOAD", 1);
acApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\n[BlackBox] : SECURELOAD enabled. \n");
acApp.SystemVariableChanged += onSystemVariableChanged;
}
}
}
... Sample command line output:
Code:
Command:
Command: NETLOAD
Command: SECURELOAD
Enter new value for SECURELOAD <1>:
0
Command:
[BlackBox] : SECURELOAD enabled.
SECURELOAD
Enter new value for SECURELOAD <1>: 0
Command:
[BlackBox] : SECURELOAD enabled.
(getvar 'secureload)
1
(setvar 'secureload 0)
0
Command:
[BlackBox] : SECURELOAD enabled.
Cheers