acad.lsp is read twice for both opening application and opening first document
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
acad.lsp is read twice for both opening application and opening first document and it shouldn't!!! I should not read acad.slp again when I am working at the document level, when working at the document level it should only read the acaddoc.lsp. Why is this happening?
I have created an AutoCAD plugin to register when the user opens the AutoCAD application. This plugin is loaded automatically when the application is opened by reading the acad.lsp which tells the application to load the plugin and execute a command:
acad.lsp
(command "trustedpaths" "C:/Users/rita.aguiar/Documents") ;this is the path of the dll (command "_netload" "C:/Users/rita.aguiar/Documents/AppEvent.dll") ;this loads the .dll (command "OpenEvent") ;this executes the first command in the plugin
When this "OpenEvent" command is executed, it writes on a txt document that the application was opened:
plugin
[CommandMethod("OpenEvent")] public void OpenEvent() {
// writes on a txt that the AutoCAD application was opened
StreamWriter file = new StreamWriter("C://Users//" + Environment.UserName + "//AppData//Roaming//Autodesk//AutoCAD 2019//R23.0//enu//support//" + Environment.UserName + ".txt", append: true); file.WriteLine(Environment.UserName + "," + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + AppName + ",iniciar"); file.Close(); }
Afterwards, when the user decides to open a document or create a new one, this "OpenEvent" command is triggered again!!!! ;( and the plugin writes the same line of text again in the txt document.
I only want to register that the application was opened once. When a new document is created or opened it should not read the acad.lsp which works at the level of the application. Instead, it should only read the acaddoc.lsp that I created to load a second command named "AddAppEvent" which will set event handlers to register commands.
acaddoc.lsp
(command "trustedpaths" "C:/Users/rita.aguiar/Documents") ;this is the path of the dll
(command "_netload" "C:/Users/rita.aguiar/Documents/AppEvent.dll") ;this loads the .dll
(command "AddAppEvent") ;this executes the second command of the plugin which will set event handlers to register the commands ended by the user
when the command AddAppEvent is executed:
[CommandMethod("AddAppEvent")] public void AddAppEvent() { Document CurrentDoc = CAD.Core.Application.DocumentManager.MdiActiveDocument; CurrentDoc.CommandEnded += new CommandEventHandler(m_doc_CommandEnded); CurrentDoc.CommandEnded += new CommandEventHandler(m_doc_SaveCommandEnded); }
This only happens for the first ever document opened when the application is launched!!!! Why is this happening?
Could it be that the .dll is the same for both acad and acaddoc? And that I should instead separate and have 2 dlls? I don't think so!! Because when opening/creating the second, third, ... documents it will not read the acad.lsp again as it does not write again that the application was opened.
Any help would be appretiated!