<?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 determine whether an object is Array(Rectangular)? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12433213#M6365</link>
    <description>&lt;P&gt;Thanks for the answer! Very elegant solution, exactly what I was looking for. The only downside is that it only works with NET40+, it won't work in lower versions of AutoCAD.&lt;/P&gt;</description>
    <pubDate>Mon, 11 Dec 2023 14:15:33 GMT</pubDate>
    <dc:creator>583408432</dc:creator>
    <dc:date>2023-12-11T14:15:33Z</dc:date>
    <item>
      <title>How to determine whether an object is Array(Rectangular)?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12429998#M6359</link>
      <description>&lt;P&gt;I use the following code:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;editor.WriteMessage($"\nType: {ent.GetType().FullName}");&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;just return:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Type: Autodesk.AutoCAD.DatabaseServices.BlockReference&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to get the specific type, like below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="583408432_0-1702107295738.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1302811iD7E37A87CFB1F930/image-size/medium?v=v2&amp;amp;px=400" role="button" title="583408432_0-1702107295738.png" alt="583408432_0-1702107295738.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2023 07:35:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12429998#M6359</guid>
      <dc:creator>583408432</dc:creator>
      <dc:date>2023-12-09T07:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether an object is Array(Rectangular)?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12430704#M6360</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1055462"&gt;@583408432&lt;/a&gt;&amp;nbsp;,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;jeff hornsby posted some code in vb.net at the swamp in 2012.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have converted it to C#&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Parts of this may lead you in the direction you want to go.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using System;
using System.Collections.Generic;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

using CadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using OpenMode = Autodesk.AutoCAD.DatabaseServices.OpenMode;

// translated from https://www.theswamp.org/index.php?topic=37921.msg464332#msg464332

[assembly: CommandClass(typeof(Class1))]
public partial class Class1
{
   [CommandMethod("ReplaceItems")]
   public void ReplaceItems()
   {
      Document doc = CadApp.DocumentManager.MdiActiveDocument;
      Database db = doc.Database;
      Editor ed = doc.Editor;

      CadApp.ShowAlertDialog("Replace items in Associative Array\n original code by JeffH @ theSwamp\n mod to C# by kdub_nz");

      var peo1 = new PromptEntityOptions(Environment.NewLine + "Select an Associative Array: ");
      PromptEntityResult per1 = ed.GetEntity(peo1);
      if (per1.Status != PromptStatus.OK)
      {
         return;
      }
      if (!AssocArray.IsAssociativeArray(per1.ObjectId))
      {
         ed.WriteMessage(Environment.NewLine + "Not an Associative Array, please try again...");
         return;
      }

      var fullSubentityPaths = new List&amp;lt;FullSubentityPath&amp;gt;();
      if (AcHelper.SelectNestedEntities(Environment.NewLine + "Select array items: ", ref fullSubentityPaths) != PromptStatus.OK)
      {
         return;
      }

      CadApp.ShowAlertDialog(fullSubentityPaths.Count.ToString());

      var peo2 = new PromptEntityOptions(Environment.NewLine + "Select entity for substitution: ");
      PromptEntityResult per2 = ed.GetEntity(peo2);
      if (per2.Status != PromptStatus.OK)
      {
         return;
      }
      PromptPointResult ppr = ed.GetPoint(Environment.NewLine + "Select base point: ");
      if (ppr.Status != PromptStatus.OK)
      {
         return;
      }
      try
      {
         using (Transaction tr = db.TransactionManager.StartTransaction())
         {
            AssocArray array = AssocArray.GetAssociativeArray(per1.ObjectId);
            ItemLocator[] ItemLocators = AssocArray.getItemLocators(fullSubentityPaths.ToArray());
            var substEntities = new ObjectIdCollection();
            substEntities.Add(per2.ObjectId);
            var basePoint = new VertexRef(ppr.Value);
            array.ReplaceItems(ItemLocators, substEntities, basePoint);
            AssocManager.EvaluateTopLevelNetwork(db, default, 0);
            tr.Commit();
         }
      }
      catch (Autodesk.AutoCAD.Runtime.Exception ex)
      {
         CadApp.ShowAlertDialog(ex.Message + ex.StackTrace);
      }
   }

   //------------------------------------
   public partial class AcHelper
   {
      public static PromptStatus SelectNestedEntities(string prompt, ref ObjectIdCollection ids, ref List&amp;lt;FullSubentityPath&amp;gt; mypaths)
      {
         Document doc = CadApp.DocumentManager.MdiActiveDocument;
         Database db = doc.Database;
         Editor ed = doc.Editor;
         using (Transaction tr = db.TransactionManager.StartTransaction())
         {
            ids = new ObjectIdCollection();
            var pathsList = new List&amp;lt;FullSubentityPath&amp;gt;();
            var pneo = new PromptNestedEntityOptions(prompt);
            pneo.AllowNone = true;
            // Loop until cancelled or completed
            while (true)
            {
               PromptNestedEntityResult rs = ed.GetNestedEntity(pneo);
               // Return whether the function was cancelled
               if (rs.Status != PromptStatus.OK)
               {
                  mypaths = pathsList; // '.ToArray()
                  UnhighlightSubEntities(mypaths.ToArray());
                  return rs.Status != PromptStatus.None ? rs.Status : PromptStatus.OK;
               }
               ids.Add(rs.ObjectId);
               var path = HighlightSubEntity(rs);
               if (path != FullSubentityPath.Null)
               {
                  pathsList.Add(path);
               }
            }
         }
      }


      public static PromptStatus SelectNestedEntities(string prompt, ref List&amp;lt;FullSubentityPath&amp;gt; mypaths)
      {
         var ids = new ObjectIdCollection();
         return SelectNestedEntities(prompt, ref ids, ref mypaths);
      }


      private static FullSubentityPath HighlightSubEntity(PromptNestedEntityResult rs)
      {
         // Extract relevant information from the prompt object
         ObjectId selId = rs.ObjectId;
         var objIds = new List&amp;lt;ObjectId&amp;gt;(rs.GetContainers());
         // Reverse the "containers" list
         objIds.Reverse();
         // Now append the selected entity
         objIds.Add(selId);
         // Retrieve the sub-entity path for this entity
         var subEnt = new SubentityId(SubentityType.Null, IntPtr.Zero);
         var path = new FullSubentityPath(objIds.ToArray(), subEnt);
         // Open the outermost container, relying on the open transaction...
         Entity ent = objIds[0].GetObject(OpenMode.ForRead) as Entity;
         // ... and highlight the nested entity
         if (ent is null)
         {
            return FullSubentityPath.Null;
         }
         ent.Highlight(path, false);
         // Return the sub-entity path for later unhighlighting
         return path;
      }


      private static void UnhighlightSubEntities(FullSubentityPath[] mypaths)
      {
         foreach (FullSubentityPath path in mypaths)
         {
            if (path == FullSubentityPath.Null)
            {
               continue;
            }
            ObjectId[] ids = path.GetObjectIds();
            Entity ent = ids[0].GetObject(OpenMode.ForRead) as Entity;
            if (ent is not null)
            {
               ent.Unhighlight(path, false);
            }
         }
      }
   }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2023 21:43:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12430704#M6360</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2023-12-09T21:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether an object is Array(Rectangular)?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12430770#M6361</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Here's a way to determine the type of associative array via the DXF data.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;    public enum AssocArrayType { None, Rectangular, Path, Polar }

    public static class Extension
    {
        public static AssocArrayType GetAssocArrayType(BlockReference br)
        {
            if (AssocArray.IsAssociativeArray(br.ObjectId))
                return AssocArrayType.None;
            var dependencyId = AssocDependency.GetFirstDependencyOnObject(br);
            var dependency = (AssocDependency)dependencyId.GetObject(OpenMode.ForRead);
            var dxfData = dependency.OwningAction.EntGet().AsArray();
            if (dxfData.Any(tv =&amp;gt; tv == new TypedValue(1, "AxesAngle")))
                return AssocArrayType.Rectangular;
            if (dxfData.Any(tv =&amp;gt; tv == new TypedValue(1, "FillAngle")))
                return AssocArrayType.Polar;
            if (dxfData.Any(tv =&amp;gt; tv == new TypedValue(1, "FillPath")))
                return AssocArrayType.Path;
            else
                return AssocArrayType.None;
        }

        [System.Security.SuppressUnmanagedCodeSecurity]
        [DllImport("acdb24.dll", CallingConvention = CallingConvention.Cdecl,
            EntryPoint = "?acdbGetAdsName@@YA?AW4ErrorStatus@Acad@@AEAY01_JVAcDbObjectId@@@Z")]
        private static extern ErrorStatus acdbGetAdsName(out AdsName ename, ObjectId id);

        [System.Security.SuppressUnmanagedCodeSecurity]
        [DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl,
            EntryPoint = "acdbEntGet")]
        private static extern System.IntPtr acdbEntGet(AdsName ename);

        /// &amp;lt;summary&amp;gt;
        /// Get the DXF definition data (like AutoLISP entget function).
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="id"&amp;gt;Instance to which the method applies.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;The DXF data.&amp;lt;/returns&amp;gt;
        /// &amp;lt;exception cref="Exception"&amp;gt;Thrown in case of invalid objectId.&amp;lt;/exception&amp;gt;
        public static ResultBuffer EntGet(this ObjectId id)
        {
            var errorStatus = acdbGetAdsName(out AdsName ename, id);
            if (errorStatus != ErrorStatus.OK)
                throw new Exception(errorStatus);
            var result = acdbEntGet(ename);
            if (result != System.IntPtr.Zero)
                return ResultBuffer.Create(result, true);
            return null;
        }
    }&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 09 Dec 2023 22:23:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12430770#M6361</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-12-09T22:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether an object is Array(Rectangular)?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12430798#M6362</link>
      <description>&lt;P&gt;And add these to the [message 2] Class1 class&amp;nbsp;&lt;/P&gt;&lt;P&gt;and have a play&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;   [CommandMethod("RectandPolarAssocArr")]
   public void RectandPolarAssocArr()
   {
      Document doc = CadApp.DocumentManager.MdiActiveDocument;
      Database db = doc.Database;
      Editor ed = doc.Editor;

      using (Transaction tr = db.TransactionManager.StartTransaction())
      {
         var rectArrayEntitiesIds = new ObjectIdCollection();
         var polarArrayEntitiesIds = new ObjectIdCollection();
         BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, 
            OpenMode.ForRead);

         BlockTableRecord modelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], 
            OpenMode.ForWrite);
         var circle = new Circle(Point3d.Origin, Vector3d.ZAxis, 5);

         modelSpace.AppendEntity(circle);
         tr.AddNewlyCreatedDBObject(circle, true);
         var line = new Line(Point3d.Origin, new Point3d(5, 0, 0));

         modelSpace.AppendEntity(line);
         tr.AddNewlyCreatedDBObject(line, true);
         rectArrayEntitiesIds.Add(circle.ObjectId);
         polarArrayEntitiesIds.Add(line.ObjectId);
         var rectParams = new AssocArrayRectangularParameters()
         {
            ColumnCount = 10,
            ColumnSpacing = 10,
            RowCount = 10,
            RowSpacing = 10,
            RowElevation = 0,
            LevelCount = 10,
            LevelSpacing = 10,
            XAxisDirection = Vector3d.XAxis,
            YAxisDirection = Vector3d.YAxis,
            BasePoint = new VertexRef(new Point3d(50, 50, 0))
         };
         AssocArray.CreateArray(rectArrayEntitiesIds, rectParams.BasePoint, rectParams);

         var polarParams = new AssocArrayPolarParameters()
         {
            FillAngle = 360,
            AngleBetweenItems = 10,
            ItemCount = 36,
            RowCount = 10,
            RowElevation = 10,
            RowSpacing = 10,
            Radius = 30,
            Direction = AssocArrayPolarParameters.ArcDirection.CounterClockwise,
            StartAngle = 0,
            RotateItems = true
         };
         AssocArray.CreateArray(polarArrayEntitiesIds, new VertexRef(new Point3d(100, 100, 0)), polarParams);

         tr.Commit();
      }
   }


   [CommandMethod("ModifyRectandPolarAssocArr")]
   public void ModifyRectandPolarAssocArr()
   {
      Document doc = CadApp.DocumentManager.MdiActiveDocument;
      Database db = doc.Database;
      Editor ed = doc.Editor;

      using (Transaction tr = db.TransactionManager.StartTransaction())
      {
         var peo = new PromptEntityOptions(Environment.NewLine + "Select a Array: ");
         PromptEntityResult per = ed.GetEntity(peo);
         if (per.Status != PromptStatus.OK)
         {
            return;
         }
         if (!AssocArray.IsAssociativeArray(per.ObjectId))
         {
            return;
         }
         AssocArray array = AssocArray.GetAssociativeArray(per.ObjectId);

         if (array.GetParameters() is AssocArrayPolarParameters)
         {
            AssocArrayPolarParameters arrayPolarParam = 
               (AssocArrayPolarParameters)array.GetParameters();
            arrayPolarParam.ItemCount = arrayPolarParam.ItemCount / 2;
            arrayPolarParam.RowCount = arrayPolarParam.RowCount / 2;
            arrayPolarParam.RowSpacing = arrayPolarParam.RowSpacing / 2;
            arrayPolarParam.Commit();
         }
         else if (array.GetParameters() is AssocArrayRectangularParameters)
         {
            AssocArrayRectangularParameters arrayRecParam = 
               (AssocArrayRectangularParameters)array.GetParameters();
            arrayRecParam.ColumnCount = arrayRecParam.ColumnCount / 2;
            arrayRecParam.RowCount = arrayRecParam.RowCount / 2;
            arrayRecParam.RowSpacing = arrayRecParam.RowSpacing / 2;
            arrayRecParam.Commit();
         }
         else
         {
            return;
         }
         tr.Commit();
      }
   }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2023 23:01:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12430798#M6362</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2023-12-09T23:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether an object is Array(Rectangular)?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12431131#M6363</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/529262"&gt;@kerry_w_brown&lt;/a&gt; Nice! AssocArrayParameters is the way I was looking for and didn't find.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, "&lt;SPAN class="lia-message-read"&gt;to determine whether an object is Array(Rectangular)", we could simply do:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;private static bool IsAssociativeRectangularArray(ObjectId id) =&amp;gt;
    AssocArray.IsAssociativeArray(id) &amp;amp;&amp;amp;
    AssocArray.GetAssociativeArray(id).GetParameters() is AssocArrayRectangularParameters;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2023 07:48:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12431131#M6363</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-12-10T07:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether an object is Array(Rectangular)?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12431159#M6364</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Yes Gilles,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think there is enough there to lead to a variety of solutions.&lt;BR /&gt;Jeff did some great&amp;nbsp; original research which gives us lots of options.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it had been c# instead of vb.net it would have gotten more attention, and that's a pity !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2023 08:07:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12431159#M6364</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2023-12-10T08:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether an object is Array(Rectangular)?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12433213#M6365</link>
      <description>&lt;P&gt;Thanks for the answer! Very elegant solution, exactly what I was looking for. The only downside is that it only works with NET40+, it won't work in lower versions of AutoCAD.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2023 14:15:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12433213#M6365</guid>
      <dc:creator>583408432</dc:creator>
      <dc:date>2023-12-11T14:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether an object is Array(Rectangular)?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12437414#M6366</link>
      <description>&lt;P&gt;The only reason it won't work in the version of .net/C# that you're using is because that language version does not support expression-bodied members, which is what &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;'s code uses.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's a simple matter to rewrite it so that it will work on the version of C# that you are using. Just replace '=&amp;gt; &amp;lt;expr&amp;gt;;' with '{return &amp;lt;expr&amp;gt;;}'.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 00:20:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-whether-an-object-is-array-rectangular/m-p/12437414#M6366</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2023-12-13T00:20:03Z</dc:date>
    </item>
  </channel>
</rss>

