Is there a way to run some code as soon as a .dll file is loaded without having to using lisp (command "Function_Name")?
Thank You.
Solved! Go to Solution.
Solved by Keith.Brown. Go to Solution.
I am a beginning dotnet autocad programmer and use visual basic but I use this to run code when my dll is loaded. I just grabbed it from the autodesk visual studio wizard.
Implements IExtensionApplication Public Sub Initialize() Implements IExtensionApplication.Initialize ' Add one time initialization here ' One common scenario is to setup a callback function here that ' unmanaged code can call. ' To do this: ' 1. Export a function from unmanaged code that takes a function ' pointer and stores the passed in value in a global variable. ' 2. Call this exported function in this function passing delegate. ' 3. When unmanaged code needs the services of this managed module ' you simply call acrxLoadApp() and by the time acrxLoadApp ' returns global function pointer is initialized to point to ' the C# delegate. ' For more info see: ' http:'msdn2.microsoft.com/en-US/library/5zwkzwf4(VS.80).aspx ' http:'msdn2.microsoft.com/en-us/library/44ey4b32(VS.80).aspx ' http:'msdn2.microsoft.com/en-US/library/7esfatk4.aspx ' as well as some of the existing AutoCAD managed apps. ' Initialize your plug-in application here Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor ed.WriteMessage("Plugin Loaded successfully...") End Sub Public Sub Terminate() Implements IExtensionApplication.Terminate ' Do plug-in application clean up here End Sub
Awesome, Works great.
Thank You.
I would have made the same suggestion, but with one caveat. You need to be careful exactly what you try to do in the initialize routine, as AutoCAD my not be ready for certain things at that time, especially if you are demand loading on AutoCAD startup.
Hello,
Hope someone can help me.
I want to check the license key (from user settings) in Initialize function, but when I set true/false for the global variable in this method, in commands I'm always getting false value. Why?
private bool isLicensed; public bool Licensed { get { return isLicensed; } set { isLicensed = value; } } void IExtensionApplication.Initialize() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("Sprawdzanie licencji ... "); if (licenseKey == userKey) { Licensed = true; } else { GPLicense gpl = new GPLicense(); gpl.Show(); Licensed = gpl.isValidate; } } private bool CheckLicense() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; if (!Licensed) { ed.WriteMessage("Brak licencji!"); GPLicense gpl = new GPLicense(); gpl.Show(); Licensed = gpl.isValidate; return Licensed; } else return true; } [CommandMethod("GC")] public void CleanLayer() { if (!CheckLicense()) return; GC.CleanLayer(); }
Your command method and the properties of your class are instance members.
AutoCAD will create a seperate instance of your class for each document you use your command in.
Unless your data is document-specific, you should not be using non-static command methods or instance properties, you should either store that data in a separate class for which there is only one instance, without any non-static command methods (e.g., a singleton), or you should make everything static (the command methods and the properties they access).