<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to run a command automatically when AutoCAD is launched in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-run-a-command-automatically-when-autocad-is-launched/m-p/9080840#M21015</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;see if you can load the dll through bundle mechanism, then you can make use of&amp;nbsp;StartupCommand attribute as explained in blog&amp;nbsp;&lt;A href="https://adndevblog.typepad.com/autocad/2012/04/autoloader-the-startupcommand-parameter.html" target="_blank"&gt;https://adndevblog.typepad.com/autocad/2012/04/autoloader-the-startupcommand-parameter.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Oct 2019 09:43:48 GMT</pubDate>
    <dc:creator>Virupaksha_aithal</dc:creator>
    <dc:date>2019-10-11T09:43:48Z</dc:date>
    <item>
      <title>How to run a command automatically when AutoCAD is launched</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-run-a-command-automatically-when-autocad-is-launched/m-p/9080764#M21014</link>
      <description>&lt;P&gt;Hi, I'm trying to do a layer check before the user save the dwg file. If there is any layer not int the standard layer list, then the save operation is cancelled and a message box popped with the message saying "Non standard layer exists, please delete it before save the file!". Basically, I've achieved the target with register a DocumentLockModeChangedEventHandler as followings:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; public class BeforeSave
    {
        static List&amp;lt;string&amp;gt; LayerNameList = new List&amp;lt;string&amp;gt;()
        {
            "0","DOOR_FIRE", "DOOR_FIRE_TEXT", "WALL", "COLUMN","WALL_MASO","WALL-MOVE","DOTE","_Defpoints","_TK","_TQ","_Xref"};

        [CommandMethod("check")]
        public void LayerCheck()
        {
            AcadApp.DocumentManager.DocumentLockModeChanged += new DocumentLockModeChangedEventHandler(callBack_DocumentLockModeChanged);
        }

        private static void callBack_DocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e)
        {
            if (e.GlobalCommandName == "QSAVE" || e.GlobalCommandName == "SAVEAS" || e.GlobalCommandName == "#QSAVE" || e.GlobalCommandName == "#SAVEAS")
            {
                Document acDoc = AcadApp.DocumentManager.MdiActiveDocument;
                Database acCurDb = acDoc.Database;

                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    LayerTable acLayerTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) as LayerTable;
                    string a = string.Empty;
                    foreach (ObjectId acObjId in acLayerTbl)
                    {
                        LayerTableRecord acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForRead) as LayerTableRecord;

                        string currentLayerName = acLyrTblRec.Name;

                        if (!LayerNameList.Contains(currentLayerName))
                        {
                            AcadApp.ShowAlertDialog( $"\"{currentLayerName}\" is not standard layer, please delete it before save the file!");
                            e.Veto();
                            return;
                        }
                    }

                }
            }
        }
    }&lt;/PRE&gt;&lt;P&gt;The script works fine. But the problem is that I should input "check" as a command so that the event works. I'm wondering if there is a way to execute the "check" command automatically when CAD is launched or the first drawing is opened or created.&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 09:04:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-run-a-command-automatically-when-autocad-is-launched/m-p/9080764#M21014</guid>
      <dc:creator>Miralkong</dc:creator>
      <dc:date>2019-10-11T09:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a command automatically when AutoCAD is launched</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-run-a-command-automatically-when-autocad-is-launched/m-p/9080840#M21015</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;see if you can load the dll through bundle mechanism, then you can make use of&amp;nbsp;StartupCommand attribute as explained in blog&amp;nbsp;&lt;A href="https://adndevblog.typepad.com/autocad/2012/04/autoloader-the-startupcommand-parameter.html" target="_blank"&gt;https://adndevblog.typepad.com/autocad/2012/04/autoloader-the-startupcommand-parameter.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 09:43:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-run-a-command-automatically-when-autocad-is-launched/m-p/9080840#M21015</guid>
      <dc:creator>Virupaksha_aithal</dc:creator>
      <dc:date>2019-10-11T09:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a command automatically when AutoCAD is launched</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-run-a-command-automatically-when-autocad-is-launched/m-p/9082465#M21016</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;SPAN&gt;Virupaksha Aithal&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;It works perfectly. Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Sat, 12 Oct 2019 03:19:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-run-a-command-automatically-when-autocad-is-launched/m-p/9082465#M21016</guid>
      <dc:creator>Miralkong</dc:creator>
      <dc:date>2019-10-12T03:19:04Z</dc:date>
    </item>
  </channel>
</rss>

