<?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: Routine Running Twice? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/routine-running-twice/m-p/12233248#M7381</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN class=""&gt;&lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394" target="_self"&gt;&lt;SPAN class=""&gt;hippe013&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Yes this does seem like the issue. I will find an alternative method.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you. &lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Sep 2023 22:58:21 GMT</pubDate>
    <dc:creator>lmorse</dc:creator>
    <dc:date>2023-09-11T22:58:21Z</dc:date>
    <item>
      <title>Routine Running Twice?</title>
      <link>https://forums.autodesk.com/t5/net-forum/routine-running-twice/m-p/12231263#M7379</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written the following code, it reads co-ordinates from an Access Database and plots the points in a drawing. My issue is that the command appears to run twice (I get the console messages twice and duplicate points). It happens if I run debug and if I run the app directly without debug. Can anyone see an issue with my code? Or is the issue somewhere else?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;using System.Data.OleDb;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Colors;



namespace ReadDatabase
{
    public class DBReader
    {
        [CommandMethod("ReadSurveyDatabase")]
        public void ReadSurveyDatabase()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            
            ed.WriteMessage("\n-------------------UTILITY TO READ FROM SURVEY DATABASE---------------------------");
            // Connection string and SQL query    
            string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"W:\\Technical Services\\DataBase\\Grosvenor Survey_be.accdb\"";
            string strSQL = "SELECT * FROM tMASTER_BOREHOLE_LIST";
            
            ed.WriteMessage("\n    -Connecting to database.");
            // Create a connection    
            using (OleDbConnection connection = new OleDbConnection(connectionString))
            {
                // Create a command and set its connection    
                OleDbCommand command = new OleDbCommand(strSQL, connection);
                // Open the connection and execute the select command.

                bool success;
                
                ed.WriteMessage("\n    -Checking and creating layers.");
                success = LayerCheck();

                if(success != true)
                {
                    Application.ShowAlertDialog("Layer Check Failed.");                    
                }

                try
                {
                    // Open connecton    
                    connection.Open();
                    // Execute command    
                    using (OleDbDataReader reader = command.ExecuteReader())
                    {
                        
                        ed.WriteMessage("\n    -Reading database.");
                        using (Transaction transact = db.TransactionManager.StartTransaction())
                        {
                            BlockTable bt;
                            bt = transact.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                            BlockTableRecord btr;
                            btr = transact.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                            double easting = 0.0;
                            double northing = 0.0;
                            double RL = 0.0;
                            
                            while (reader.Read())
                            {
                                if (reader["AS_DRILLED_SURVEY_E"].ToString() != "")
                                {
                                    easting = double.Parse(reader["AS_DRILLED_SURVEY_E"].ToString());
                                }
                                else if(reader["AGD84_AMG_X"].ToString() != "")
                                {
                                    easting = double.Parse(reader["AGD84_AMG_X"].ToString());
                                }
                                else
                                {
                                    easting = 0.0;
                                }

                                if (reader["AS_DRILLED_SURVEY_N"].ToString() != "")
                                {
                                    northing = double.Parse(reader["AS_DRILLED_SURVEY_N"].ToString());
                                }
                                else if (reader["AGD84_AMG_Y"].ToString() != "")
                                {
                                    northing = double.Parse(reader["AGD84_AMG_Y"].ToString());
                                }                                
                                else
                                {
                                    northing = 0.0;
                                }
                                if (reader["AS_DRILLED_SURVEY_RL"].ToString() != "")
                                {
                                    RL = double.Parse(reader["AS_DRILLED_SURVEY_RL"].ToString());
                                }
                                else if (reader["RL"].ToString() != "")
                                {
                                    RL = double.Parse(reader["RL"].ToString());
                                }
                                else
                                {
                                    RL = 0.0;
                                }

                                string boreholeName = reader["HoleID"].ToString();
                                //ed.WriteMessage("\n{0}:  {1}  {2}  {3}", boreholeName, easting.ToString(), northing.ToString(), RL.ToString());
                                
                                try
                                {
                                    Point3d boreholePoint = new Point3d(easting, northing, RL);
                                    Point3d mtextInsertPoint = new Point3d(easting + 0.1, northing + 0.1, RL);
                                    if ((easting &amp;gt; 0.0) &amp;amp; (northing &amp;gt; 0.0) &amp;amp; boreholeName != "")
                                        //if ((easting &amp;gt; 0.0) &amp;amp; (northing &amp;gt; 0.0) &amp;amp; (RL &amp;gt; 0.0) &amp;amp; boreholeName != "")
                                        {
                                        //ed.WriteMessage("\nDrawing Borehole Object: ");
                                        using (MText mtx = new MText())
                                        {
                                            mtx.Contents = boreholeName;
                                            mtx.Location = mtextInsertPoint;
                                            mtx.TextHeight = 3;

                                            btr.AppendEntity(mtx);
                                            transact.AddNewlyCreatedDBObject(mtx, true);
                                        }
                                        using (DBPoint point = new DBPoint(boreholePoint))
                                        {
                                            point.ColorIndex = 1;
                                            btr.AppendEntity(point);
                                            transact.AddNewlyCreatedDBObject(point, true);
                                        }
                                    }
                                    

                                }
                                catch (System.Exception ex)
                                {

                                    Application.ShowAlertDialog("Error Encountered: " + ex.Message);
                                    transact.Abort();
                                    break;
                                }
                            }
                            ed.WriteMessage("\n    -Completed.");
                            // Set the style for all point objects in the drawing
                            db.Pdmode = 34;
                            db.Pdsize = 0.3;
                            transact.Commit();
                            doc.SendStringToExecute(". zoom e ", false, false, false);
                            
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    Application.ShowAlertDialog("Error: " + ex.Message);

                }
                // The connection is automatically closed becasuse of using block.    
            }
            return;
        }

        public static bool LayerCheck()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;

            using (Transaction transact = db.TransactionManager.StartTransaction())
            {
                // DEFAULT LAYER DEFINITIONS
                string[] LayerNames = new string[12];
                LayerNames[0] = "XXX - GROSVENOR GAS DRAINAGE FLIGHT PATH";
                LayerNames[1] = "XXX - GROSVENOR GOAF GAS DRAINAGE HOLES - LAYER MUST BE TURNED ON";
                LayerNames[2] = "XXX - GROSVENOR GOAF GAS DRAINAGE HOLES GROUTED - LAYER MUST BE TURNED ON";
                LayerNames[3] = "XXX - GROSVENOR GOAF NITROGEN HOLES - LAYER MUST BE TURNED ON";
                LayerNames[4] = "XXX - GROSVENOR HOLES - LAYER MUST BE TURNED ON";
                LayerNames[5] = "XXX - GROSVENOR MONITORING HOLES - LAYER MUST BE TURNED ON";
                LayerNames[6] = "XXX - GROSVENOR MONITORING HOLES GROUTED - LAYER MUST BE TURNED ON";
                LayerNames[7] = "XXX - LEGACY BOREHOLES - LAYER MUST BE TURNED ON";
                LayerNames[8] = "XXX - LEGACY BOREHOLES GROUTED - LAYER MUST BE TURNED ON";
                LayerNames[9] = "XXX - MINEX SIGNIFICANTLY DIFFERENT MAY 2017 - LAYER MUST BE TURNED ON";
                LayerNames[10] = "XXX - OPEN SERVICE HOLES - LAYER MUST BE TURNED ON";
                LayerNames[11] = "XXX - OPEN SERVICE HOLES FLIGHT PATH";
                //LayerNames[13] = "";

                short[] layerColour = new short[12];
                layerColour[0] = 1;
                layerColour[1] = 5;
                layerColour[2] = 253;
                layerColour[3] = 1;
                layerColour[4] = 5;
                layerColour[5] = 253;
                layerColour[6] = 5;
                layerColour[7] = 8;
                layerColour[8] = 4;
                layerColour[9] = 253;
                layerColour[10] = 1;
                layerColour[11] = 6;
                //layerColour[0] = 1;

                try
                {
                    // Check through the layers and make sure they exist
                    LayerTable layTable = transact.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;

                    for (int i = 0; i &amp;lt;= LayerNames.Length -1; i++)
                    {
                        if (LayerNames[i].ToString() != "" &amp;amp; LayerNames[i].ToString() != null)
                        {
                            if (layTable.Has(LayerNames[i].ToString()) == false)
                            {
                                LayerTableRecord layTableRecord = new LayerTableRecord();
                                layTableRecord.Name = LayerNames[i].ToString();
                                layTableRecord.Color = Color.FromColorIndex(ColorMethod.ByAci, layerColour[i]);
                                layTable.UpgradeOpen();
                                layTable.Add(layTableRecord);
                                transact.AddNewlyCreatedDBObject(layTableRecord, true);
                            }
                        }                        
                    }
                    transact.Commit();
                    return true;
                }
                catch (System.Exception ex)
                {
                    ed.WriteMessage("Error: " + ex.Message);
                    transact.Abort();
                    return false;
                }
                   
            }
        }
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 11 Sep 2023 07:10:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/routine-running-twice/m-p/12231263#M7379</guid>
      <dc:creator>lmorse</dc:creator>
      <dc:date>2023-09-11T07:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Routine Running Twice?</title>
      <link>https://forums.autodesk.com/t5/net-forum/routine-running-twice/m-p/12233114#M7380</link>
      <description>&lt;P&gt;It appears that the problem is with your zoom extents. The space after the 'e' is the offender.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;doc.SendStringToExecute(". zoom e ", false, false, false);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See the following link where&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;explains different ways to do the zoom extents.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/net/do-zoom-extents-in-c-net-autocad/td-p/7735556" target="_blank"&gt;https://forums.autodesk.com/t5/net/do-zoom-extents-in-c-net-autocad/td-p/7735556&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 21:24:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/routine-running-twice/m-p/12233114#M7380</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2023-09-11T21:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: Routine Running Twice?</title>
      <link>https://forums.autodesk.com/t5/net-forum/routine-running-twice/m-p/12233248#M7381</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN class=""&gt;&lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1633394" target="_self"&gt;&lt;SPAN class=""&gt;hippe013&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Yes this does seem like the issue. I will find an alternative method.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you. &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 22:58:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/routine-running-twice/m-p/12233248#M7381</guid>
      <dc:creator>lmorse</dc:creator>
      <dc:date>2023-09-11T22:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: Routine Running Twice?</title>
      <link>https://forums.autodesk.com/t5/net-forum/routine-running-twice/m-p/12233367#M7382</link>
      <description>&lt;P&gt;Since your code is in a command method running in the document context there really isn't any need to use SendStringToExecute. It was intended for use by applications running in the application context, and executes asynchronously. That means the ZOOM Extents command will not execute until after your command method has ended.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From a CommandMethod running in the document context you should use the Editor's Command() method to run AutoCAD commands.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 00:25:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/routine-running-twice/m-p/12233367#M7382</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2023-09-12T00:25:10Z</dc:date>
    </item>
  </channel>
</rss>

