Author Topic: Can I manage files loading (arx/.net/lisp/vba) with possibility of cancellation  (Read 2339 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Can I manage files loading (arx/.net/lisp/vba) via events, with possibility of cancellation for load every from it?

In my code I can only get message about files loading (arx/.net/lisp):
Code: [Select]
//Microsoft
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.IO;
//Autodesk
using acad = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
 
namespace MyNetLib
{
    public class Class1 : IExtensionApplication
    {
        DocumentCollection dm = acad.DocumentManager;
        Document dwg;
        Database db;
        Editor ed;
        const string ns = "gpsm";//namespace of commands
 
        /// <summary>
        /// Default constructor
        /// </summary>
        public Class1()
        {
            Drawing = acad.DocumentManager.MdiActiveDocument;
        }
 
        /// <summary>
        /// Drawing
        /// </summary>
        Document Drawing
        {
            get { return dwg; }
            set
            {
                dwg = value;
                if (dwg != null)
                {
                    db = dwg.Database; ed = dwg.Editor;
                }
                else
                {
                    db = null; ed = null;
                }
            }
        }
 
        public void Initialize()
        {
            ed.WriteMessage("\nInitialize 'MyNetLib'...\n");            
            AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(CurrentDomain_AssemblyLoad);
            ((AcadApplication)acad.AcadApplication).ARXLoaded += new _DAcadApplicationEvents_ARXLoadedEventHandler(Class1_ARXLoaded);
            dwg.LispWillStart += new LispWillStartEventHandler(dwg_LispWillStart);
            ed.WriteMessage("\nInitialize 'MyNetLib' finished.\n");
        }

        void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
        {
            ed.WriteMessage(string.Format("\nLoading .Net-library '{0}'\n", args.LoadedAssembly.Location));
        }
 
        void Class1_ARXLoaded(string AppName)
        {
            ed.WriteMessage(string.Format("\nLoaded ARX-library: '{0}'\n", AppName));
        }
 
        void dwg_LispWillStart(object sender, LispWillStartEventArgs e)
        {
            try
            {
                string x = "(load ";
                if (!e.FirstLine.StartsWith(x)) return;
                string fileName = e.FirstLine.Substring(x.TrimEnd(null).Length, e.FirstLine.Length - x.Length - 1).Replace("\"","");
                List<string> paths2;
                string cProfileName = acad.GetSystemVariable("cprofile") as string;
                //Current AutoCAD registry key
                string productKey = Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLinker.ProductKey;
                string keyName = string.Format(@"{0}\Profiles\{1}\General", productKey, cProfileName);
                RegistryKey regKey = Registry.CurrentUser.OpenSubKey(keyName, true);
                string regValue = regKey.GetValue("Acad", string.Empty) as string;
                regValue = regValue.Substring(0, regValue.Length - 1);
                List<string> paths = new List<string>(regValue.Split(';'));
                paths2 = new List<string>();
                paths2.Add(Environment.CurrentDirectory);
                paths2.Add(new FileInfo(acad.DocumentManager.MdiActiveDocument.Name).Directory.FullName);
                paths2.Add(((IAcadApplication)acad.AcadApplication).Path);
                paths = paths2.Concat(paths).Distinct().ToList();
                foreach (string item in paths)
                {
                    if (File.Exists(Path.Combine(item, fileName)))
                    {
                        ed.WriteMessage(string.Format("\nLoading Lisp-file {0}\n", Path.Combine(item, fileName)));
                        return;
                    }
                }
                ed.WriteMessage(string.Format("\nLoading Lisp-file {0}\n", fileName));
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage(string.Format("\nError: '{0}'", ex.Message));
            }            
        }
 
        public void Terminate()
        {
            //throw new NotImplementedException();
        }
    }
}

But I not known how do it for VBA-files (even for loading).

Registration in registry (reg-file):

Code: [Select]
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.2\ACAD-7001:409\Applications\Net]
"LOADER"="D:\\AcadPlagins\\MyNetLib.dll"
"LOADCTRLS"=dword:00000002
"MANAGED"=dword:00000001

Result:



« Last Edit: September 16, 2010, 06:27:08 AM by Andrey »