<?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: AutoCAD 2014, C# call AddHatch throw exception in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/autocad-2014-c-call-addhatch-throw-exception/m-p/5818358#M38633</link>
    <description>&lt;P&gt;The AcadHatch.AppendInner[Outer]Loop() method takes an OBJECT (Variant in COM world), not an OBJECT ARRAY as input. That is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;object inLoop=new XXXXX[]{xxx, xxx, xxx};&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is different from&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;object[] inLoop=new &lt;SPAN&gt;XXXXX[]{xxx, xxx, xxx};&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, this code works OK:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using CadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using CadDb = Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;

[assembly: CommandClass(typeof(ComHatchTest.Commands))]

namespace ComHatchTest
{
    public class Commands 
    {
        [CommandMethod("MyHatch")]
        public static void DoDocumentCommand()
        {
            Document dwg = CadApp.DocumentManager.MdiActiveDocument;
            Editor ed = dwg.Editor;

            try
            {
                DoHatch();
            }
            catch (Autodesk.AutoCAD.Runtime.Exception aex)
            {
                ed.WriteMessage("\nError: {0}", aex.Message);
                ed.WriteMessage("\n*Cancel*");
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("\nError: {0}", ex.Message);
                ed.WriteMessage("\n*Cancel*");
            }
            finally
            {
                Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
            }
        }

        public static void DoHatch()
        {
            AcadApplication app = CadApp.AcadApplication as AcadApplication;
            AcadDocument doc = app.ActiveDocument;

            AcadHatch hatch = doc.ModelSpace.AddHatch(1, "ANSI31", true);

            AcadCircle circle = doc.ModelSpace.AddCircle(new double[] { 100.0, 100.0, 0.0 }, 200.0);

            object inLoop = new AcadEntity[] { circle as AcadEntity };

            hatch.AppendOuterLoop(inLoop);
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;HTH&lt;/P&gt;</description>
    <pubDate>Tue, 15 Sep 2015 20:03:28 GMT</pubDate>
    <dc:creator>norman.yuan</dc:creator>
    <dc:date>2015-09-15T20:03:28Z</dc:date>
    <item>
      <title>AutoCAD 2014, C# call AddHatch throw exception</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-2014-c-call-addhatch-throw-exception/m-p/5818113#M38632</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use Auto CAD 2014, by in the follow code throw exception error, &amp;nbsp;I donot why, pls help me&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;private void button4_Click(object sender, EventArgs e)&lt;BR /&gt;{&lt;BR /&gt;AcadApplication app = new AcadApplicationClass();&lt;BR /&gt;app.Documents.Open(this.textBox1.Text, missing, missing);&lt;BR /&gt;app.Visible = false;&lt;/P&gt;&lt;P&gt;IAcadHatch hatch = app.ActiveDocument.ModelSpace.AddHatch(1, "ANSI31", true);&lt;BR /&gt;// inner loop&lt;BR /&gt;object[] inloop = new object[1];&lt;BR /&gt;AcadCircle circle = app.ActiveDocument.ModelSpace.AddCircle(new double[] { 100, 100, 0 }, 200);&lt;BR /&gt;inloop[0] = circle;&lt;BR /&gt;hatch.AppendInnerLoop(inloop); &amp;nbsp;// &amp;lt;====== in here:&amp;nbsp;Invalid object array&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;string file = string.Format(@"{0}Demo_{1}.dwg", AppDomain.CurrentDomain.BaseDirectory, System.Guid.NewGuid());&lt;BR /&gt;app.ActiveDocument.SaveAs(file, AcSaveAsType.ac2010_dwg, missing);&lt;BR /&gt;app.Quit();&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 18:01:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-2014-c-call-addhatch-throw-exception/m-p/5818113#M38632</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-09-15T18:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD 2014, C# call AddHatch throw exception</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-2014-c-call-addhatch-throw-exception/m-p/5818358#M38633</link>
      <description>&lt;P&gt;The AcadHatch.AppendInner[Outer]Loop() method takes an OBJECT (Variant in COM world), not an OBJECT ARRAY as input. That is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;object inLoop=new XXXXX[]{xxx, xxx, xxx};&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is different from&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;object[] inLoop=new &lt;SPAN&gt;XXXXX[]{xxx, xxx, xxx};&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, this code works OK:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using CadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using CadDb = Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;

[assembly: CommandClass(typeof(ComHatchTest.Commands))]

namespace ComHatchTest
{
    public class Commands 
    {
        [CommandMethod("MyHatch")]
        public static void DoDocumentCommand()
        {
            Document dwg = CadApp.DocumentManager.MdiActiveDocument;
            Editor ed = dwg.Editor;

            try
            {
                DoHatch();
            }
            catch (Autodesk.AutoCAD.Runtime.Exception aex)
            {
                ed.WriteMessage("\nError: {0}", aex.Message);
                ed.WriteMessage("\n*Cancel*");
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("\nError: {0}", ex.Message);
                ed.WriteMessage("\n*Cancel*");
            }
            finally
            {
                Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
            }
        }

        public static void DoHatch()
        {
            AcadApplication app = CadApp.AcadApplication as AcadApplication;
            AcadDocument doc = app.ActiveDocument;

            AcadHatch hatch = doc.ModelSpace.AddHatch(1, "ANSI31", true);

            AcadCircle circle = doc.ModelSpace.AddCircle(new double[] { 100.0, 100.0, 0.0 }, 200.0);

            object inLoop = new AcadEntity[] { circle as AcadEntity };

            hatch.AppendOuterLoop(inLoop);
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 20:03:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-2014-c-call-addhatch-throw-exception/m-p/5818358#M38633</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2015-09-15T20:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD 2014, C# call AddHatch throw exception</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-2014-c-call-addhatch-throw-exception/m-p/10164479#M38634</link>
      <description>&lt;P&gt;I also Encountered the same problem. Then I corrected it follow your code.But when I define the elements of inLoop&lt;/P&gt;&lt;P&gt;as object,It still throws an exception.&amp;nbsp; Why?&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;The AcadHatch.AppendInner[Outer]Loop() method takes an OBJECT (Variant in COM world), not an OBJECT ARRAY as input. That is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;object inLoop=new XXXXX[]{xxx, xxx, xxx};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is different from&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;object[] inLoop=new &lt;SPAN&gt;XXXXX[]{xxx, xxx, xxx};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, this code works OK:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using CadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using CadDb = Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;

[assembly: CommandClass(typeof(ComHatchTest.Commands))]

namespace ComHatchTest
{
    public class Commands 
    {
        [CommandMethod("MyHatch")]
        public static void DoDocumentCommand()
        {
            Document dwg = CadApp.DocumentManager.MdiActiveDocument;
            Editor ed = dwg.Editor;

            try
            {
                DoHatch();
            }
            catch (Autodesk.AutoCAD.Runtime.Exception aex)
            {
                ed.WriteMessage("\nError: {0}", aex.Message);
                ed.WriteMessage("\n*Cancel*");
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("\nError: {0}", ex.Message);
                ed.WriteMessage("\n*Cancel*");
            }
            finally
            {
                Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
            }
        }

        public static void DoHatch()
        {
            AcadApplication app = CadApp.AcadApplication as AcadApplication;
            AcadDocument doc = app.ActiveDocument;

            AcadHatch hatch = doc.ModelSpace.AddHatch(1, "ANSI31", true);

            AcadCircle circle = doc.ModelSpace.AddCircle(new double[] { 100.0, 100.0, 0.0 }, 200.0);

            object inLoop = new AcadEntity[] { circle as AcadEntity };

            hatch.AppendOuterLoop(inLoop);
        }
    }
}&lt;/PRE&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 15:52:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-2014-c-call-addhatch-throw-exception/m-p/10164479#M38634</guid>
      <dc:creator>1605027848</dc:creator>
      <dc:date>2021-03-17T15:52:29Z</dc:date>
    </item>
  </channel>
</rss>

