<?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: AttachExternalReference problem in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352298#M84650</link>
    <description>I tried another mothod ,and it work fine,so I think it's a bug in objectdbx.&lt;BR /&gt;
by the way ,could someone know how to attach external reference with arx, and how to close a docment with arx.&lt;BR /&gt;
&lt;BR /&gt;
the following  is my modified codes ,it works fine.&lt;BR /&gt;
&lt;BR /&gt;
     &lt;BR /&gt;
        private static void CreateRefDrawing(string subFolder)&lt;BR /&gt;
        {&lt;BR /&gt;
            string[] fileNames = new string[] { "Ref_S_Plan", "Ref_S_Beam", "Ref_S_Foot" };&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc = new AxDbDocumentClass();&lt;BR /&gt;
            string newName = subFolder + "\\" + fileNames[0] + ".dwg";    &lt;BR /&gt;
            axdoc.SaveAs(newName, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc);&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc1 = new AxDbDocumentClass();&lt;BR /&gt;
            string newName1 = subFolder + "\\" + fileNames[1] + ".dwg";&lt;BR /&gt;
            axdoc1.SaveAs(newName1, null);&lt;BR /&gt;
            //System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc);&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc2 = new AxDbDocumentClass();&lt;BR /&gt;
            string newName2 = subFolder + "\\" + fileNames[2] + ".dwg";&lt;BR /&gt;
            axdoc2.SaveAs(newName2, null);&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
            double[] insertPnt = new double[] { 0, 0, 0 };&lt;BR /&gt;
                double scale = 1;&lt;BR /&gt;
                double rotation = 0;&lt;BR /&gt;
                bool bOverlay = false; &lt;BR /&gt;
         &lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                //// the following comment line  will cause a fatal error&lt;BR /&gt;
&lt;BR /&gt;
                //Database curdb = HostApplicationServices.WorkingDatabase;&lt;BR /&gt;
                //Database db = Database.FromAcadDatabase(axdoc1.Database);&lt;BR /&gt;
                //HostApplicationServices.WorkingDatabase = db;&lt;BR /&gt;
                //axdoc1.ModelSpace.AttachExternalReference(newName, fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, null);&lt;BR /&gt;
                //axdoc1.SaveAs(newName1, null);                &lt;BR /&gt;
                //HostApplicationServices.WorkingDatabase = curdb;&lt;BR /&gt;
&lt;BR /&gt;
                string refName =  ".\\" + fileNames[0] + ".dwg";  &lt;BR /&gt;
                AcadDocument doc1 = ActiveX.AcadApp.Documents.Open(newName1, false, null);&lt;BR /&gt;
                doc1.ModelSpace.AttachExternalReference(refName, fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, null); &lt;BR /&gt;
                 doc1.Close(true, newName1);&lt;BR /&gt;
&lt;BR /&gt;
                  AcadDocument doc2 = ActiveX.AcadApp.Documents.Open(newName2, false, null);&lt;BR /&gt;
                 doc2.ModelSpace.AttachExternalReference(refName, fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, null); &lt;BR /&gt;
                 doc2.Close(true, newName2);&lt;BR /&gt;
             }&lt;BR /&gt;
            catch { }&lt;BR /&gt;
&lt;BR /&gt;
        }</description>
    <pubDate>Wed, 15 Jun 2005 10:01:12 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2005-06-15T10:01:12Z</dc:date>
    <item>
      <title>AttachExternalReference problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352288#M84640</link>
      <description>I want use objectDBX to AttachExternalReference ,but always encount fator error,could someone tell me how to solve it?&lt;BR /&gt;
&lt;BR /&gt;
           string[] fileNames = new string[] { "Ref_S_Plan", "Ref_S_Beam", "Ref_S_Foot" };&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc = new AxDbDocumentClass();&lt;BR /&gt;
            string newName;&lt;BR /&gt;
            newName = subFolder + "\\" + fileNames[0] + ".dwg";&lt;BR /&gt;
            axdoc.SaveAs(newName, null);&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc1 = new AxDbDocumentClass();&lt;BR /&gt;
            newName = subFolder + "\\" + fileNames[1] + ".dwg";&lt;BR /&gt;
            axdoc1.SaveAs(newName, null);&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc2 = new AxDbDocumentClass();&lt;BR /&gt;
            newName = subFolder + "\\" + fileNames[2] + ".dwg";&lt;BR /&gt;
            axdoc2.SaveAs(newName, null);&lt;BR /&gt;
&lt;BR /&gt;
            double[] insertPnt = new double[] { 0, 0, 0 };&lt;BR /&gt;
            double scale = 1;&lt;BR /&gt;
            double rotation = 0;&lt;BR /&gt;
            bool bOverlay = false;&lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc);&lt;BR /&gt;
            }&lt;BR /&gt;
            catch { }&lt;BR /&gt;
&lt;BR /&gt;
            string refFileNameNoext;&lt;BR /&gt;
            refFileNameNoext = fileNames[0];&lt;BR /&gt;
            axdoc1.ModelSpace.AttachExternalReference(subFolder, refFileNameNoext, insertPnt,&lt;BR /&gt;
                scale, scale, scale, rotation, bOverlay, null);&lt;BR /&gt;
&lt;BR /&gt;
            refFileNameNoext = fileNames[0];&lt;BR /&gt;
            axdoc2.ModelSpace.AttachExternalReference(subFolder, refFileNameNoext, insertPnt,&lt;BR /&gt;
              scale, scale, scale, rotation, bOverlay, null);&lt;BR /&gt;
&lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc1);&lt;BR /&gt;
                System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc2);&lt;BR /&gt;
            }&lt;BR /&gt;
            catch { }&lt;BR /&gt;
        }</description>
      <pubDate>Mon, 13 Jun 2005 11:42:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352288#M84640</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-06-13T11:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: AttachExternalReference problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352289#M84641</link>
      <description>What is the error that you are encountering? On what line?&lt;BR /&gt;
&lt;BR /&gt;
Albert&lt;BR /&gt;
&lt;BR /&gt;
&lt;NETCAI&gt; wrote in message news:4872847@discussion.autodesk.com...&lt;BR /&gt;
I want use objectDBX to AttachExternalReference ,but always encount fator &lt;BR /&gt;
error,could someone tell me how to solve it?&lt;BR /&gt;
&lt;BR /&gt;
           string[] fileNames = new string[] { "Ref_S_Plan", "Ref_S_Beam", &lt;BR /&gt;
"Ref_S_Foot" };&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc = new AxDbDocumentClass();&lt;BR /&gt;
            string newName;&lt;BR /&gt;
            newName = subFolder + "\\" + fileNames[0] + ".dwg";&lt;BR /&gt;
            axdoc.SaveAs(newName, null);&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc1 = new AxDbDocumentClass();&lt;BR /&gt;
            newName = subFolder + "\\" + fileNames[1] + ".dwg";&lt;BR /&gt;
            axdoc1.SaveAs(newName, null);&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc2 = new AxDbDocumentClass();&lt;BR /&gt;
            newName = subFolder + "\\" + fileNames[2] + ".dwg";&lt;BR /&gt;
            axdoc2.SaveAs(newName, null);&lt;BR /&gt;
&lt;BR /&gt;
            double[] insertPnt = new double[] { 0, 0, 0 };&lt;BR /&gt;
            double scale = 1;&lt;BR /&gt;
            double rotation = 0;&lt;BR /&gt;
            bool bOverlay = false;&lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc);&lt;BR /&gt;
            }&lt;BR /&gt;
            catch { }&lt;BR /&gt;
&lt;BR /&gt;
            string refFileNameNoext;&lt;BR /&gt;
            refFileNameNoext = fileNames[0];&lt;BR /&gt;
            axdoc1.ModelSpace.AttachExternalReference(subFolder, &lt;BR /&gt;
refFileNameNoext, insertPnt,&lt;BR /&gt;
                scale, scale, scale, rotation, bOverlay, null);&lt;BR /&gt;
&lt;BR /&gt;
            refFileNameNoext = fileNames[0];&lt;BR /&gt;
            axdoc2.ModelSpace.AttachExternalReference(subFolder, &lt;BR /&gt;
refFileNameNoext, insertPnt,&lt;BR /&gt;
              scale, scale, scale, rotation, bOverlay, null);&lt;BR /&gt;
&lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc1);&lt;BR /&gt;
                System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc2);&lt;BR /&gt;
            }&lt;BR /&gt;
            catch { }&lt;BR /&gt;
        }&lt;/NETCAI&gt;</description>
      <pubDate>Mon, 13 Jun 2005 16:26:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352289#M84641</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-06-13T16:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: AttachExternalReference problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352290#M84642</link>
      <description>string[] fileNames = new string[] { "Ref_S_Plan", "Ref_S_Beam", "Ref_S_Foot" };&lt;BR /&gt;
&lt;BR /&gt;
AxDbDocumentClass axdoc = new AxDbDocumentClass();&lt;BR /&gt;
string newName;&lt;BR /&gt;
newName = subFolder + "\\" + fileNames[0] + ".dwg";&lt;BR /&gt;
axdoc.SaveAs(newName, null);&lt;BR /&gt;
&lt;BR /&gt;
AxDbDocumentClass axdoc1 = new AxDbDocumentClass();&lt;BR /&gt;
newName = subFolder + "\\" + fileNames[1] + ".dwg";&lt;BR /&gt;
axdoc1.SaveAs(newName, null);&lt;BR /&gt;
&lt;BR /&gt;
AxDbDocumentClass axdoc2 = new AxDbDocumentClass();&lt;BR /&gt;
newName = subFolder + "\\" + fileNames[2] + ".dwg";&lt;BR /&gt;
axdoc2.SaveAs(newName, null);&lt;BR /&gt;
&lt;BR /&gt;
double[] insertPnt = new double[] { 0, 0, 0 };&lt;BR /&gt;
double scale = 1;&lt;BR /&gt;
double rotation = 0;&lt;BR /&gt;
bool bOverlay = false;&lt;BR /&gt;
try&lt;BR /&gt;
{&lt;BR /&gt;
System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc);&lt;BR /&gt;
}&lt;BR /&gt;
catch { }&lt;BR /&gt;
&lt;BR /&gt;
string refFileNameNoext;&lt;BR /&gt;
refFileNameNoext = fileNames[0];&lt;BR /&gt;
axdoc1.ModelSpace.AttachExternalReference(subFolder, refFileNameNoext, insertPnt,&lt;BR /&gt;
scale, scale, scale, rotation, bOverlay, null); // this line will cause a fatal error&lt;BR /&gt;
&lt;BR /&gt;
refFileNameNoext = fileNames[0];&lt;BR /&gt;
axdoc2.ModelSpace.AttachExternalReference(subFolder, refFileNameNoext, insertPnt,&lt;BR /&gt;
scale, scale, scale, rotation, bOverlay, null);&lt;BR /&gt;
&lt;BR /&gt;
try&lt;BR /&gt;
{&lt;BR /&gt;
System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc1);&lt;BR /&gt;
System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc2);&lt;BR /&gt;
}&lt;BR /&gt;
catch { }&lt;BR /&gt;
}</description>
      <pubDate>Tue, 14 Jun 2005 00:36:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352290#M84642</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-06-14T00:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: AttachExternalReference problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352291#M84643</link>
      <description>There are too many variables here to actually reproduce the error. What is &lt;BR /&gt;
the error that you are getting? Does AutoCAD simply vaporizes or does it &lt;BR /&gt;
display some error?&lt;BR /&gt;
&lt;BR /&gt;
Albert&lt;BR /&gt;
&lt;BR /&gt;
&lt;NETCAI&gt; wrote in message news:4873818@discussion.autodesk.com...&lt;BR /&gt;
string[] fileNames = new string[] { "Ref_S_Plan", "Ref_S_Beam", &lt;BR /&gt;
"Ref_S_Foot" };&lt;BR /&gt;
&lt;BR /&gt;
AxDbDocumentClass axdoc = new AxDbDocumentClass();&lt;BR /&gt;
string newName;&lt;BR /&gt;
newName = subFolder + "\\" + fileNames[0] + ".dwg";&lt;BR /&gt;
axdoc.SaveAs(newName, null);&lt;BR /&gt;
&lt;BR /&gt;
AxDbDocumentClass axdoc1 = new AxDbDocumentClass();&lt;BR /&gt;
newName = subFolder + "\\" + fileNames[1] + ".dwg";&lt;BR /&gt;
axdoc1.SaveAs(newName, null);&lt;BR /&gt;
&lt;BR /&gt;
AxDbDocumentClass axdoc2 = new AxDbDocumentClass();&lt;BR /&gt;
newName = subFolder + "\\" + fileNames[2] + ".dwg";&lt;BR /&gt;
axdoc2.SaveAs(newName, null);&lt;BR /&gt;
&lt;BR /&gt;
double[] insertPnt = new double[] { 0, 0, 0 };&lt;BR /&gt;
double scale = 1;&lt;BR /&gt;
double rotation = 0;&lt;BR /&gt;
bool bOverlay = false;&lt;BR /&gt;
try&lt;BR /&gt;
{&lt;BR /&gt;
System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc);&lt;BR /&gt;
}&lt;BR /&gt;
catch { }&lt;BR /&gt;
&lt;BR /&gt;
string refFileNameNoext;&lt;BR /&gt;
refFileNameNoext = fileNames[0];&lt;BR /&gt;
axdoc1.ModelSpace.AttachExternalReference(subFolder, refFileNameNoext, &lt;BR /&gt;
insertPnt,&lt;BR /&gt;
scale, scale, scale, rotation, bOverlay, null); // this line will cause a &lt;BR /&gt;
fatal error&lt;BR /&gt;
&lt;BR /&gt;
refFileNameNoext = fileNames[0];&lt;BR /&gt;
axdoc2.ModelSpace.AttachExternalReference(subFolder, refFileNameNoext, &lt;BR /&gt;
insertPnt,&lt;BR /&gt;
scale, scale, scale, rotation, bOverlay, null);&lt;BR /&gt;
&lt;BR /&gt;
try&lt;BR /&gt;
{&lt;BR /&gt;
System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc1);&lt;BR /&gt;
System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc2);&lt;BR /&gt;
}&lt;BR /&gt;
catch { }&lt;BR /&gt;
}&lt;/NETCAI&gt;</description>
      <pubDate>Tue, 14 Jun 2005 05:30:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352291#M84643</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-06-14T05:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: AttachExternalReference problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352292#M84644</link>
      <description>I have found the problem.I misunderstanding the first parameter, but a new problem appear, the ExternalReference doesn't attached to axdoc1 and axdoc2,but attached to the current drawing in autocad.</description>
      <pubDate>Tue, 14 Jun 2005 09:25:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352292#M84644</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-06-14T09:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: AttachExternalReference problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352293#M84645</link>
      <description>the following is my current code,the problem is line is added to axdoc1 and axdoc2, but External Reference isn't attached to axdoc1 and axdoc2,but attached to current drawing in autocad, it's so strange.&lt;BR /&gt;
 private static void CreateRefDrawing(String subFolder)&lt;BR /&gt;
        {&lt;BR /&gt;
            string[] fileNames = new string[] { "Ref_S_Plan", "Ref_S_Beam", "Ref_S_Foot" };&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc = new AxDbDocumentClass();&lt;BR /&gt;
            string newName = subFolder + "\\" + fileNames[0] + ".dwg";&lt;BR /&gt;
            axdoc.SaveAs(newName, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc);&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc1 = new AxDbDocumentClass();&lt;BR /&gt;
            string newName1 = subFolder + "\\" + fileNames[1] + ".dwg";&lt;BR /&gt;
            //axdoc1.SaveAs(newName1, null);&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc2 = new AxDbDocumentClass();&lt;BR /&gt;
            string newName2 = subFolder + "\\" + fileNames[2] + ".dwg";&lt;BR /&gt;
            ////axdoc2.SaveAs(newName2, null);&lt;BR /&gt;
&lt;BR /&gt;
            double[] insertPnt = new double[] { 0, 0, 0 };&lt;BR /&gt;
            double scale = 1;&lt;BR /&gt;
            double rotation = 0;&lt;BR /&gt;
            bool bOverlay = false;&lt;BR /&gt;
&lt;BR /&gt;
            axdoc1.ModelSpace.AddLine(new double[] { 0, 0, 0 }, new double[] { 1000, 1000, 0 });&lt;BR /&gt;
            axdoc1.ModelSpace.AttachExternalReference(newName, fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, null);&lt;BR /&gt;
            axdoc1.SaveAs(newName1, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc1);&lt;BR /&gt;
&lt;BR /&gt;
            axdoc2.ModelSpace.AddLine(new double[] { 0, 0, 0 }, new double[] { 1000, 1000, 0 });&lt;BR /&gt;
            axdoc2.ModelSpace.AttachExternalReference(newName, fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, null);&lt;BR /&gt;
            axdoc2.SaveAs(newName2, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc2);&lt;BR /&gt;
&lt;BR /&gt;
        }</description>
      <pubDate>Tue, 14 Jun 2005 09:55:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352293#M84645</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-06-14T09:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: AttachExternalReference problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352294#M84646</link>
      <description>Can say if this will work, but it may be&lt;BR /&gt;
worth a try:&lt;BR /&gt;
&lt;BR /&gt;
1.  Get the managed Database from the AcadDatabase, using&lt;BR /&gt;
     Database.FromAcadDatabase(AxDbDocument.Database)&lt;BR /&gt;
&lt;BR /&gt;
2.  Save the value of HostApplicationServices.WorkingDatabase&lt;BR /&gt;
&lt;BR /&gt;
3.  Set HostApplicationServices.WorkingDatabase to the&lt;BR /&gt;
     Database obtained from the AcadDatabase.&lt;BR /&gt;
&lt;BR /&gt;
4. Attach the xref&lt;BR /&gt;
&lt;BR /&gt;
5. Set the value of HostApplicationServices.WorkingDatabase&lt;BR /&gt;
    back to the original value saved previously.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;NETCAI&gt; wrote in message news:4873960@discussion.autodesk.com...&lt;BR /&gt;
the following is my current code,the problem is line is added to axdoc1 and axdoc2, but External Reference isn't &lt;BR /&gt;
attached to axdoc1 and axdoc2,but attached to current drawing in autocad, it's so strange.&lt;BR /&gt;
 private static void CreateRefDrawing(String subFolder)&lt;BR /&gt;
        {&lt;BR /&gt;
            string[] fileNames = new string[] { "Ref_S_Plan", "Ref_S_Beam", "Ref_S_Foot" };&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc = new AxDbDocumentClass();&lt;BR /&gt;
            string newName = subFolder + "\\" + fileNames[0] + ".dwg";&lt;BR /&gt;
            axdoc.SaveAs(newName, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc);&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc1 = new AxDbDocumentClass();&lt;BR /&gt;
            string newName1 = subFolder + "\\" + fileNames[1] + ".dwg";&lt;BR /&gt;
            //axdoc1.SaveAs(newName1, null);&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc2 = new AxDbDocumentClass();&lt;BR /&gt;
            string newName2 = subFolder + "\\" + fileNames[2] + ".dwg";&lt;BR /&gt;
            ////axdoc2.SaveAs(newName2, null);&lt;BR /&gt;
&lt;BR /&gt;
            double[] insertPnt = new double[] { 0, 0, 0 };&lt;BR /&gt;
            double scale = 1;&lt;BR /&gt;
            double rotation = 0;&lt;BR /&gt;
            bool bOverlay = false;&lt;BR /&gt;
&lt;BR /&gt;
            axdoc1.ModelSpace.AddLine(new double[] { 0, 0, 0 }, new double[] { 1000, 1000, 0 });&lt;BR /&gt;
            axdoc1.ModelSpace.AttachExternalReference(newName, fileNames[0], insertPnt, scale, scale, scale, rotation, &lt;BR /&gt;
bOverlay, null);&lt;BR /&gt;
            axdoc1.SaveAs(newName1, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc1);&lt;BR /&gt;
&lt;BR /&gt;
            axdoc2.ModelSpace.AddLine(new double[] { 0, 0, 0 }, new double[] { 1000, 1000, 0 });&lt;BR /&gt;
            axdoc2.ModelSpace.AttachExternalReference(newName, fileNames[0], insertPnt, scale, scale, scale, rotation, &lt;BR /&gt;
bOverlay, null);&lt;BR /&gt;
            axdoc2.SaveAs(newName2, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc2);&lt;BR /&gt;
&lt;BR /&gt;
        }&lt;/NETCAI&gt;</description>
      <pubDate>Tue, 14 Jun 2005 12:30:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352294#M84646</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-06-14T12:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: AttachExternalReference problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352295#M84647</link>
      <description>thanks tony,I do as you suggested,but it still doesn't work for me , a fatal error will appeare when attacth external reference.&lt;BR /&gt;
&lt;BR /&gt;
    private static void CreateRefDrawing(string subFolder)&lt;BR /&gt;
        {&lt;BR /&gt;
            string[] fileNames = new string[] { "Ref_S_Plan", "Ref_S_Beam", "Ref_S_Foot" };&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc = new AxDbDocumentClass();&lt;BR /&gt;
            string newName = subFolder + "\\" + fileNames[0] + ".dwg";&lt;BR /&gt;
           &lt;BR /&gt;
            axdoc.ModelSpace.AddLine(new double[] { 0, 0, 0 }, new double[] { 1000, 1000, 0 });&lt;BR /&gt;
           &lt;BR /&gt;
            axdoc.SaveAs(newName, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc);&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc1 = new AxDbDocumentClass();&lt;BR /&gt;
            string newName1 = subFolder + "\\" + fileNames[1] + ".dwg";&lt;BR /&gt;
            axdoc1.SaveAs(newName1, null);&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc2 = new AxDbDocumentClass();&lt;BR /&gt;
            string newName2 = subFolder + "\\" + fileNames[2] + ".dwg";&lt;BR /&gt;
            axdoc2.SaveAs(newName2, null);&lt;BR /&gt;
&lt;BR /&gt;
            double[] insertPnt = new double[] { 0, 0, 0 };&lt;BR /&gt;
            double scale = 1;&lt;BR /&gt;
            double rotation = 0;&lt;BR /&gt;
            bool bOverlay = false;&lt;BR /&gt;
 &lt;BR /&gt;
            Database curdb = HostApplicationServices.WorkingDatabase;&lt;BR /&gt;
&lt;BR /&gt;
            Database db = Database.FromAcadDatabase(axdoc1.Database);&lt;BR /&gt;
            HostApplicationServices.WorkingDatabase = db;&lt;BR /&gt;
&lt;BR /&gt;
            // the following line will cause a fatal error,&lt;BR /&gt;
            axdoc1.ModelSpace.AttachExternalReference(newName, fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, null);&lt;BR /&gt;
            axdoc1.SaveAs(newName1, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc1);&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
            db = Database.FromAcadDatabase(axdoc2.Database);&lt;BR /&gt;
            HostApplicationServices.WorkingDatabase = db;&lt;BR /&gt;
&lt;BR /&gt;
            axdoc2.ModelSpace.AttachExternalReference(newName, fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, null);&lt;BR /&gt;
            axdoc2.SaveAs(newName1, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc2);&lt;BR /&gt;
&lt;BR /&gt;
            HostApplicationServices.WorkingDatabase = curdb;&lt;BR /&gt;
&lt;BR /&gt;
        }</description>
      <pubDate>Wed, 15 Jun 2005 01:29:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352295#M84647</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-06-15T01:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: AttachExternalReference problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352296#M84648</link>
      <description>I don't know if this is your problem but in your code,&lt;BR /&gt;
you do this:&lt;BR /&gt;
&lt;BR /&gt;
   Database curdb = HostApplicationServices.WorkingDatabase;&lt;BR /&gt;
&lt;BR /&gt;
   Database db = Database.FromAcadDatabase(axdoc1.Database);&lt;BR /&gt;
   HostApplicationServices.WorkingDatabase = db;&lt;BR /&gt;
&lt;BR /&gt;
   //...&lt;BR /&gt;
&lt;BR /&gt;
   axdoc1.ModelSpace.AttachExternalReference(newName,&lt;BR /&gt;
        fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, null);&lt;BR /&gt;
&lt;BR /&gt;
   axdoc1.SaveAs(newName1, null);&lt;BR /&gt;
&lt;BR /&gt;
   System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc1);&lt;BR /&gt;
&lt;BR /&gt;
When you call ReleaseComObject(axdoc1), the Database that it&lt;BR /&gt;
wraps is destroyed while it is the current 'WorkingDatabase',&lt;BR /&gt;
which is almost certainly going to blow up.&lt;BR /&gt;
&lt;BR /&gt;
Try restoring the WorkingDatabase back to curdb before&lt;BR /&gt;
you let go of axdoc1.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;NETCAI&gt; wrote in message news:4875028@discussion.autodesk.com...&lt;BR /&gt;
thanks tony,I do as you suggested,but it still doesn't work for me , a fatal error will appeare when attacth external reference.&lt;BR /&gt;
&lt;BR /&gt;
    private static void CreateRefDrawing(string subFolder)&lt;BR /&gt;
        {&lt;BR /&gt;
            string[] fileNames = new string[] { "Ref_S_Plan", "Ref_S_Beam", "Ref_S_Foot" };&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc = new AxDbDocumentClass();&lt;BR /&gt;
            string newName = subFolder + "\\" + fileNames[0] + ".dwg";&lt;BR /&gt;
&lt;BR /&gt;
            axdoc.ModelSpace.AddLine(new double[] { 0, 0, 0 }, new double[] { 1000, 1000, 0 });&lt;BR /&gt;
&lt;BR /&gt;
            axdoc.SaveAs(newName, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc);&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc1 = new AxDbDocumentClass();&lt;BR /&gt;
            string newName1 = subFolder + "\\" + fileNames[1] + ".dwg";&lt;BR /&gt;
            axdoc1.SaveAs(newName1, null);&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc2 = new AxDbDocumentClass();&lt;BR /&gt;
            string newName2 = subFolder + "\\" + fileNames[2] + ".dwg";&lt;BR /&gt;
            axdoc2.SaveAs(newName2, null);&lt;BR /&gt;
&lt;BR /&gt;
            double[] insertPnt = new double[] { 0, 0, 0 };&lt;BR /&gt;
            double scale = 1;&lt;BR /&gt;
            double rotation = 0;&lt;BR /&gt;
            bool bOverlay = false;&lt;BR /&gt;
&lt;BR /&gt;
            Database curdb = HostApplicationServices.WorkingDatabase;&lt;BR /&gt;
&lt;BR /&gt;
            Database db = Database.FromAcadDatabase(axdoc1.Database);&lt;BR /&gt;
            HostApplicationServices.WorkingDatabase = db;&lt;BR /&gt;
&lt;BR /&gt;
            // the following line will cause a fatal error,&lt;BR /&gt;
            axdoc1.ModelSpace.AttachExternalReference(newName, fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, &lt;BR /&gt;
null);&lt;BR /&gt;
            axdoc1.SaveAs(newName1, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc1);&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
            db = Database.FromAcadDatabase(axdoc2.Database);&lt;BR /&gt;
            HostApplicationServices.WorkingDatabase = db;&lt;BR /&gt;
&lt;BR /&gt;
            axdoc2.ModelSpace.AttachExternalReference(newName, fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, &lt;BR /&gt;
null);&lt;BR /&gt;
            axdoc2.SaveAs(newName1, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc2);&lt;BR /&gt;
&lt;BR /&gt;
            HostApplicationServices.WorkingDatabase = curdb;&lt;BR /&gt;
&lt;BR /&gt;
        }&lt;/NETCAI&gt;</description>
      <pubDate>Wed, 15 Jun 2005 07:31:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352296#M84648</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-06-15T07:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: AttachExternalReference problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352297#M84649</link>
      <description>tony&lt;BR /&gt;
I tried as you told, but still occurred a error.&lt;BR /&gt;
error: Exception occurred: 0xC0000005 (Access Violation)&lt;BR /&gt;
&lt;BR /&gt;
    private static void CreateRefDrawing(string subFolder)&lt;BR /&gt;
        {&lt;BR /&gt;
            string[] fileNames = new string[] { "Ref_S_Plan", "Ref_S_Beam", "Ref_S_Foot" };&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc = new AxDbDocumentClass();&lt;BR /&gt;
            string newName = subFolder + "\\" + fileNames[0] + ".dwg";    &lt;BR /&gt;
            axdoc.SaveAs(newName, null);&lt;BR /&gt;
           system.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc);&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc1 = new AxDbDocumentClass();&lt;BR /&gt;
            string newName1 = subFolder + "\\" + fileNames[1] + ".dwg";&lt;BR /&gt;
            axdoc1.SaveAs(newName1, null);&lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                 double[] insertPnt = new double[] { 0, 0, 0 };&lt;BR /&gt;
                double scale = 1;&lt;BR /&gt;
                double rotation = 0;&lt;BR /&gt;
                bool bOverlay = false; &lt;BR /&gt;
                Database curdb = HostApplicationServices.WorkingDatabase;&lt;BR /&gt;
                Database db = Database.FromAcadDatabase(axdoc1.Database);&lt;BR /&gt;
                HostApplicationServices.WorkingDatabase = db;&lt;BR /&gt;
                axdoc1.ModelSpace.AttachExternalReference(newName, fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, null);//a fatal error occurred&lt;BR /&gt;
                axdoc1.SaveAs(newName1, null);                &lt;BR /&gt;
                HostApplicationServices.WorkingDatabase = curdb;&lt;BR /&gt;
            }&lt;BR /&gt;
            catch { }&lt;BR /&gt;
&lt;BR /&gt;
        }</description>
      <pubDate>Wed, 15 Jun 2005 08:26:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352297#M84649</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-06-15T08:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: AttachExternalReference problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352298#M84650</link>
      <description>I tried another mothod ,and it work fine,so I think it's a bug in objectdbx.&lt;BR /&gt;
by the way ,could someone know how to attach external reference with arx, and how to close a docment with arx.&lt;BR /&gt;
&lt;BR /&gt;
the following  is my modified codes ,it works fine.&lt;BR /&gt;
&lt;BR /&gt;
     &lt;BR /&gt;
        private static void CreateRefDrawing(string subFolder)&lt;BR /&gt;
        {&lt;BR /&gt;
            string[] fileNames = new string[] { "Ref_S_Plan", "Ref_S_Beam", "Ref_S_Foot" };&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc = new AxDbDocumentClass();&lt;BR /&gt;
            string newName = subFolder + "\\" + fileNames[0] + ".dwg";    &lt;BR /&gt;
            axdoc.SaveAs(newName, null);&lt;BR /&gt;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc);&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc1 = new AxDbDocumentClass();&lt;BR /&gt;
            string newName1 = subFolder + "\\" + fileNames[1] + ".dwg";&lt;BR /&gt;
            axdoc1.SaveAs(newName1, null);&lt;BR /&gt;
            //System.Runtime.InteropServices.Marshal.ReleaseComObject(axdoc);&lt;BR /&gt;
&lt;BR /&gt;
            AxDbDocumentClass axdoc2 = new AxDbDocumentClass();&lt;BR /&gt;
            string newName2 = subFolder + "\\" + fileNames[2] + ".dwg";&lt;BR /&gt;
            axdoc2.SaveAs(newName2, null);&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
            double[] insertPnt = new double[] { 0, 0, 0 };&lt;BR /&gt;
                double scale = 1;&lt;BR /&gt;
                double rotation = 0;&lt;BR /&gt;
                bool bOverlay = false; &lt;BR /&gt;
         &lt;BR /&gt;
            try&lt;BR /&gt;
            {&lt;BR /&gt;
                //// the following comment line  will cause a fatal error&lt;BR /&gt;
&lt;BR /&gt;
                //Database curdb = HostApplicationServices.WorkingDatabase;&lt;BR /&gt;
                //Database db = Database.FromAcadDatabase(axdoc1.Database);&lt;BR /&gt;
                //HostApplicationServices.WorkingDatabase = db;&lt;BR /&gt;
                //axdoc1.ModelSpace.AttachExternalReference(newName, fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, null);&lt;BR /&gt;
                //axdoc1.SaveAs(newName1, null);                &lt;BR /&gt;
                //HostApplicationServices.WorkingDatabase = curdb;&lt;BR /&gt;
&lt;BR /&gt;
                string refName =  ".\\" + fileNames[0] + ".dwg";  &lt;BR /&gt;
                AcadDocument doc1 = ActiveX.AcadApp.Documents.Open(newName1, false, null);&lt;BR /&gt;
                doc1.ModelSpace.AttachExternalReference(refName, fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, null); &lt;BR /&gt;
                 doc1.Close(true, newName1);&lt;BR /&gt;
&lt;BR /&gt;
                  AcadDocument doc2 = ActiveX.AcadApp.Documents.Open(newName2, false, null);&lt;BR /&gt;
                 doc2.ModelSpace.AttachExternalReference(refName, fileNames[0], insertPnt, scale, scale, scale, rotation, bOverlay, null); &lt;BR /&gt;
                 doc2.Close(true, newName2);&lt;BR /&gt;
             }&lt;BR /&gt;
            catch { }&lt;BR /&gt;
&lt;BR /&gt;
        }</description>
      <pubDate>Wed, 15 Jun 2005 10:01:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352298#M84650</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-06-15T10:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: AttachExternalReference problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352299#M84651</link>
      <description>Is  my judgement correct? has External reference  a bug in objectdbx?</description>
      <pubDate>Wed, 22 Jun 2005 00:29:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352299#M84651</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-06-22T00:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: AttachExternalReference problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352300#M84652</link>
      <description>This was logged in our bug tracking database. Nobody looked into it yet so I &lt;BR /&gt;
can't confirm or deny. It looks suspeciously like a bug.&lt;BR /&gt;
&lt;BR /&gt;
Albert&lt;BR /&gt;
&lt;BR /&gt;
&lt;NETCAI&gt; wrote in message news:4881355@discussion.autodesk.com...&lt;BR /&gt;
Is  my judgement correct? has External reference  a bug in objectdbx?&lt;/NETCAI&gt;</description>
      <pubDate>Wed, 22 Jun 2005 00:45:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attachexternalreference-problem/m-p/1352300#M84652</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-06-22T00:45:02Z</dc:date>
    </item>
  </channel>
</rss>

