<?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 Initialize AcadEntity array Object with NULL value in C#.Net ? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-initialize-acadentity-array-object-with-null-value-in-c/m-p/3567922#M54068</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;Hallex !! Refered your code in my attempt..&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Aug 2012 11:03:45 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-08-07T11:03:45Z</dc:date>
    <item>
      <title>How to Initialize AcadEntity array Object with NULL value in C#.Net ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-initialize-acadentity-array-object-with-null-value-in-c/m-p/3567736#M54064</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to know how to initialize the AcadEntity type of array variable with an ACADEntity object&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is as below,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AcadEntity[] SelEntList;&lt;/P&gt;&lt;P&gt;AcadEntity MyEnt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SelEntList[0] = MyEnt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting an error as below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Use of unassigned local variable 'MyEnt'&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In case of a string array, I would be doing MyStr[0] = "" and it works but how to do this w.r.t. AcadEntity array ?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2012 05:39:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-initialize-acadentity-array-object-with-null-value-in-c/m-p/3567736#M54064</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-07T05:39:07Z</dc:date>
    </item>
    <item>
      <title>Re : How to Initialize AcadEntity array Object with NULL value in C#.Net ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-initialize-acadentity-array-object-with-null-value-in-c/m-p/3567778#M54065</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You have to intialize your variables after (or while) you declare them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AcadEntity[] SelEntList &lt;SPAN&gt;= new&amp;nbsp;&lt;/SPAN&gt;AcadEntity[arrayLength]; // you have to specify the array size when initilzing it.&lt;/P&gt;&lt;P&gt;AcadEntity MyEnt = null;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;SelEntList[0] = MyEnt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Have a look at the &lt;A target="_blank" href="http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx"&gt;System.Collections.Generic.List&amp;lt;T&amp;gt;&lt;/A&gt; which has some intersting features the array don't have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2012 06:43:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-initialize-acadentity-array-object-with-null-value-in-c/m-p/3567778#M54065</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2012-08-07T06:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to Initialize AcadEntity array Object with NULL value in C#.Net ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-initialize-acadentity-array-object-with-null-value-in-c/m-p/3567906#M54066</link>
      <description>&lt;P&gt;Try this&amp;nbsp;code that completely based on docs example^&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;     static Point2d PolarPoints(Point2d pPt, double dAng, double dDist)
        {
            return new Point2d(pPt.X + dDist * Math.Cos(dAng),
                               pPt.Y + dDist * Math.Sin(dAng));
        }

        // create grid using rectangular array
        [CommandMethod("sqv")]
        public static void TestFillSquares()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            PromptPointOptions ppo = new PromptPointOptions("\nPick a lower left corner: ");
            PromptPointResult res = ed.GetPoint(ppo);
            if (res.Status != PromptStatus.OK) return;
            Point3d p1 = res.Value;
            PromptCornerOptions pko = new PromptCornerOptions("\nPick opposite corner: ", p1);
            res = ed.GetCorner(pko);
            if (res.Status != PromptStatus.OK) return;
            Point3d p2 = res.Value;
            //start a transaction
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                // create polyline to make the shape 
                Polyline poly = new Polyline(4);
                poly.AddVertexAt(0, new Point2d(p1.X, p1.Y), 0, 0, 0);
                poly.AddVertexAt(1, new Point2d(p2.X, p1.Y), 0, 0, 0);
                poly.AddVertexAt(2, new Point2d(p2.X, p2.Y), 0, 0, 0);
                poly.AddVertexAt(3, new Point2d(p1.X, p2.Y), 0, 0, 0);
                poly.Closed = true;

                btr.AppendEntity(poly);
                tr.AddNewlyCreatedDBObject(poly, true);
               
                double leg = Math.Abs(p2.X - p1.X);
                double wid = Math.Abs(p2.Y - p1.Y);
                // Create a rectangular array with 5 rows and 8 columns
                int nRows = 5;
                int nColumns = 8;
                double disrows = leg / nColumns;
                double discols = wid / nRows;
                // create polyline to make the shape 
                Polyline npoly = new Polyline(4);
                npoly.AddVertexAt(0, new Point2d(p1.X, p1.Y), 0, 0, 0);
                npoly.AddVertexAt(1, new Point2d(p1.X + disrows, p1.Y), 0, 0, 0);
                npoly.AddVertexAt(2, new Point2d(p1.X + disrows, p1.Y + discols), 0, 0, 0);
                npoly.AddVertexAt(3, new Point2d(p1.X, p1.Y + discols), 0, 0, 0);
                npoly.Closed = true;
                npoly.ColorIndex = 1;
                btr.AppendEntity(npoly);
                tr.AddNewlyCreatedDBObject(npoly, true);



                // Set the row and column offsets along with the base array angle
                double dRowOffset = discols;
                double dColumnOffset = disrows;
                double dArrayAng = 0;

                // Get the angle from X for the current UCS 
                Matrix3d curUCSMatrix = ed.CurrentUserCoordinateSystem;
                CoordinateSystem3d curUCS = curUCSMatrix.CoordinateSystem3d;
                Vector2d acVec2dAng = new Vector2d(curUCS.Xaxis.X,
                                                   curUCS.Xaxis.Y);

                // If the UCS is rotated, adjust the array angle accordingly
                dArrayAng = dArrayAng + acVec2dAng.Angle;

                // Use the upper-left corner of the objects extents for the array base point
                Extents3d acExts = npoly.Bounds.GetValueOrDefault();
                Point2d acPt2dArrayBase = new Point2d(acExts.MinPoint.X,
                                                      acExts.MaxPoint.Y);

                // Track the objects created for each column
                DBObjectCollection acDBObjCollCols = new DBObjectCollection();
                acDBObjCollCols.Add(npoly);

                // Create the number of objects for the first column
                int nColumnsCount = 1;
                while (nColumns &amp;gt; nColumnsCount)
                {
                    Entity acEntClone = npoly.Clone() as Entity;
                    acDBObjCollCols.Add(acEntClone);

                    // Caclucate the new point for the copied object (move)
                    Point2d acPt2dTo = PolarPoints(acPt2dArrayBase,
                                                   dArrayAng,
                                                   dColumnOffset * nColumnsCount);

                    Vector2d acVec2d = acPt2dArrayBase.GetVectorTo(acPt2dTo);
                    Vector3d acVec3d = new Vector3d(acVec2d.X, acVec2d.Y, 0);
                    acEntClone.TransformBy(Matrix3d.Displacement(acVec3d));

                    btr.AppendEntity(acEntClone);
                    tr.AddNewlyCreatedDBObject(acEntClone, true);

                    nColumnsCount = nColumnsCount + 1;
                }

                // Set a value in radians for 90 degrees
                double dAng = Math.PI / 2;

                // Track the objects created for each row and column
                DBObjectCollection acDBObjCollLvls = new DBObjectCollection();

                foreach (DBObject acObj in acDBObjCollCols)
                {
                    acDBObjCollLvls.Add(acObj);
                }

                // Create the number of objects for each row
                foreach (Entity acEnt in acDBObjCollCols)
                {
                    int nRowsCount = 1;

                    while (nRows &amp;gt; nRowsCount)
                    {
                        Entity acEntClone = acEnt.Clone() as Entity;
                        acDBObjCollLvls.Add(acEntClone);

                        // Caclucate the new point for the copied object (move)
                        Point2d acPt2dTo = PolarPoints(acPt2dArrayBase,
                                                       dArrayAng + dAng,
                                                       dRowOffset * nRowsCount);

                        Vector2d acVec2d = acPt2dArrayBase.GetVectorTo(acPt2dTo);
                        Vector3d acVec3d = new Vector3d(acVec2d.X, acVec2d.Y, 0);
                        acEntClone.TransformBy(Matrix3d.Displacement(acVec3d));

                        btr.AppendEntity(acEntClone);
                        tr.AddNewlyCreatedDBObject(acEntClone, true);

                        nRowsCount = nRowsCount + 1;
                    }
                }


                tr.Commit();
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800000" face="arial,helvetica,sans-serif"&gt;~'J'~&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2012 11:02:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-initialize-acadentity-array-object-with-null-value-in-c/m-p/3567906#M54066</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-08-07T11:02:27Z</dc:date>
    </item>
    <item>
      <title>Re : How to Initialize AcadEntity array Object with NULL value in C#.Net ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-initialize-acadentity-array-object-with-null-value-in-c/m-p/3567918#M54067</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;_gile&lt;SPAN&gt;! Thats the missing !&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2012 11:02:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-initialize-acadentity-array-object-with-null-value-in-c/m-p/3567918#M54067</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-07T11:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to Initialize AcadEntity array Object with NULL value in C#.Net ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-initialize-acadentity-array-object-with-null-value-in-c/m-p/3567922#M54068</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;Hallex !! Refered your code in my attempt..&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2012 11:03:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-initialize-acadentity-array-object-with-null-value-in-c/m-p/3567922#M54068</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-07T11:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to Initialize AcadEntity array Object with NULL value in C#.Net ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-initialize-acadentity-array-object-with-null-value-in-c/m-p/3567936#M54069</link>
      <description>&lt;P&gt;You're welcome&lt;/P&gt;&lt;P&gt;Happy coding &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008080" face="arial,helvetica,sans-serif"&gt;~'J'~&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2012 11:15:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-initialize-acadentity-array-object-with-null-value-in-c/m-p/3567936#M54069</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-08-07T11:15:28Z</dc:date>
    </item>
  </channel>
</rss>

