<?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 API C# detach xref current drawing in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5603209#M40351</link>
    <description>It appears that you are attempting to delete nested Xrefs. I don't think that is possible without opening the source database and deleting from there.</description>
    <pubDate>Wed, 22 Apr 2015 15:12:16 GMT</pubDate>
    <dc:creator>Jeff_M</dc:creator>
    <dc:date>2015-04-22T15:12:16Z</dc:date>
    <item>
      <title>AutoCAD API C# detach xref current drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5602502#M40347</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Here is what I am trying,&lt;/P&gt;&lt;P&gt;I am tryign to get the list of all th xref in the current drawing and then detach broken and resolved xref from a wpf ui.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Examples specified everywhere makes the user select the xref from the drawing not geting the objId from the db.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When i try to pick from the screen.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Xref ID: (8796084459232)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Xref Handle: 28BDE&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when i get object id using code I get differnt handle and object ID&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;XREF ID &amp;gt;&amp;gt;: (8796084449504) || 28A8E&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i try to detach xref usign this handle or object id it shows fatal exception.&lt;/P&gt;&lt;P&gt;Could someone help me with some code snippet on how to get the right handle for the xref in the current drawing using code and detach without user interaction to pick the xref from the screen.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2015 08:16:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5602502#M40347</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-04-22T08:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD API C# detach xref current drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5603015#M40348</link>
      <description>This reply to a post of yours a few years ago looks like it should work with the current drawing as well, and does not require user to select the xref.&lt;BR /&gt;&lt;A href="http://forums.autodesk.com/t5/net/net-c-unable-to-detaching-filenotfound-xref-without-opening-the/m-p/3573496#M30498" target="_blank"&gt;http://forums.autodesk.com/t5/net/net-c-unable-to-detaching-filenotfound-xref-without-opening-the/m-p/3573496#M30498&lt;/A&gt;</description>
      <pubDate>Wed, 22 Apr 2015 13:42:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5603015#M40348</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2015-04-22T13:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD API C# detach xref current drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5603032#M40349</link>
      <description>&lt;P&gt;Thanks Jeff,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Here is what I am trying to do,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My plugin when runs it gets the list of xrefs in the current drawing using the following code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public static void printchildren1(GraphNode i_root, string i_indent, Editor i_ed, Transaction i_Tx, Database db,  Document doc)
	{
	int workingcount = 0;
	string host = ZACAD14GenHelper.getDWGPath(doc);
	for (int r = 0; r &amp;lt; i_root.NumOut; r++)
	{
		
		XrefGraphNode child = i_root.Out(r) as XrefGraphNode;
		
		string xref = child.Name + child.XrefStatus.ToString();
		Global.variables.ed.WriteMessage("\n : " + xref);
		
		if (child.XrefStatus == XrefStatus.Resolved)
		{
			BlockTableRecord blk = i_Tx.GetObject(child.BlockTableRecordId, OpenMode.ForRead) as BlockTableRecord;
			printchildren1(child, "| " + i_indent, i_ed, i_Tx, db, doc);
			workingcount += 1;
			Global.XrefObj.XrefItem item = new Global.XrefObj.XrefItem() { FileName = child.Name, FileStatus = child.XrefStatus.ToString(), XrefNode = child, xrefHandle = child.BlockTableRecordId.Handle };
			Global.variables.Xreflist.Add(item);
			Global.variables.ed.WriteMessage("\nXREF ID &amp;gt;&amp;gt;: " + blk.ObjectId + " || " + blk.Handle);
		}
		else
		{
			continue;
		}
		Global.variables.ed.WriteMessage("\n=======================================================\n");
	}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which is displayed in a wpf window where user can pick an xref and detach if he wants to.&lt;/P&gt;&lt;P&gt;Now when i try to detach usign the object id from the stored node its giving fatal exception.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2015 13:53:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5603032#M40349</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-04-22T13:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD API C# detach xref current drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5603133#M40350</link>
      <description>&lt;P&gt;Jeff,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;If you take a look at my previous post where I am opening the parent drawing in another another drawing and then i am detaching. All the examples doing the same.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to detach in the drawing which is currently open and the plugin runs in the current open drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried several way and none of them work. Atleast of you let me know how to get the correct object id of the xref object that would be fine.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2015 14:38:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5603133#M40350</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-04-22T14:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD API C# detach xref current drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5603209#M40351</link>
      <description>It appears that you are attempting to delete nested Xrefs. I don't think that is possible without opening the source database and deleting from there.</description>
      <pubDate>Wed, 22 Apr 2015 15:12:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5603209#M40351</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2015-04-22T15:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD API C# detach xref current drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5604433#M40352</link>
      <description>&lt;P&gt;Jeff,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Here is the image of the app.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see the xref are in the current drawing not nested within another xref drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;I want detach the xref in the main drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://forums.autodesk.com/t5/image/serverpage/image-id/165273i76C9A4C43C6CD65E/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" title="4-17-2015 11-35-54 AM.png" alt="4-17-2015 11-35-54 AM.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to do it picking the xref using the following code but not using the wpf window.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[CommandMethod("DX")]
        static public void DetachXref()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            // Select an external reference

            Transaction tr =
              db.TransactionManager.StartTransaction();
            using (tr)
            {
                BlockTableRecord btr = null;
                ObjectId xrefId = ObjectId.Null;

                // We'll loop, as we need to open the block and
                // underlying definition to check the block is
                // an external reference during selection

                do
                {
                    PromptEntityOptions peo =
                      new PromptEntityOptions(
                        "\nSelect an external reference:"
                      );
                    peo.SetRejectMessage("\nMust be a block reference.");
                    peo.AddAllowedClass(typeof(BlockReference), true);

                    PromptEntityResult per = ed.GetEntity(peo);
                    if (per.Status != PromptStatus.OK)
                        return;

                    // Open the block reference

                    BlockReference br =
                      (BlockReference)tr.GetObject(
                        per.ObjectId,
                        OpenMode.ForRead
                      );

                    // And the underlying block table record

                    btr =
                      (BlockTableRecord)tr.GetObject(
                        br.BlockTableRecord,
                        OpenMode.ForRead
                      );

                    // If it's an xref, store its ObjectId

                    if (btr.IsFromExternalReference)
                    {
                        ed.WriteMessage("\nXref ID: " + br.BlockTableRecord.ToString());
                        xrefId = br.BlockTableRecord;
                    }
                    else
                    {
                        // Otherwise print a message and loop

                        ed.WriteMessage(
                          "\nMust be an external reference."
                        );
                    }
                }
                while (!btr.IsFromExternalReference);

                // If we have a valid ObjectID for the xref, detach it

                if (xrefId != ObjectId.Null)
                {
                    db.DetachXref(xrefId);
                    ed.WriteMessage("\nExternal reference detached.");
                }

                // We commit the transaction simply for performance
                // reasons, as the detach is independent

                tr.Commit();
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to select the Xref from the WPF window and detach.&lt;/P&gt;&lt;P&gt;Let me know if you have any ideas.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2015 04:18:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5604433#M40352</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-04-23T04:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD API C# detach xref current drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5605235#M40353</link>
      <description>&lt;P&gt;This simple code worked for me to detach Unresolved Xrefs.&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod ("DetachBadXrefs")]
        public void detachbadxrefs()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead);
                foreach (ObjectId id in bt)
                {
                    BlockTableRecord btr = (BlockTableRecord)id.GetObject(OpenMode.ForRead);
                    if(btr.XrefStatus != XrefStatus.NotAnXref &amp;amp;&amp;amp; btr.XrefStatus != XrefStatus.Resolved)
                    {
                        db.DetachXref(id);
                    }
                }
                tr.Commit();
            }
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2015 14:49:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/5605235#M40353</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2015-04-23T14:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD API C# detach xref current drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/8824862#M40354</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tested from Plant 2018 and after.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For detach xrefs that's classified as Autodesk files (like .dwg, .dwt etc), I use this code:&lt;/P&gt;&lt;PRE&gt;Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.Command("-XREF", "D", "*");&lt;/PRE&gt;&lt;P&gt;For Point Cloud References, I use this code:&lt;/P&gt;&lt;PRE&gt;Database db = Application.DocumentManager.MdiActiveDocument;
Transaction tr = db.TransactionManager.StartTransaction();
ObjectIdCollection pointCloudIds = null;
ObjectIdCollection pointCloudIds = null;
DBDictionary nos = null;
DBDictionary subDictionaryPointCloudDefExDic = null;
try
{
    this._listenerLog.Info("    Obtém os objetos responsáveis pelos Xrefs Nuvens de Pontos, para o DWG " + _acDoc.Name);
    pointCloudIds = new ObjectIdCollection();
    nos = tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead) as DBDictionary;
    if (nos.Contains("ACAD_POINTCLOUD_EX_DICT"))
    {
        subDictionaryPointCloudDefExDic =
        (DBDictionary)tr.GetObject(nos.GetAt("ACAD_POINTCLOUD_EX_DICT"), OpenMode.ForRead);

        this._listenerLog.Info("    Inicia iteração sob todos os Xrefs do tipo Nuvem de Pontos para o DWG " + _acDoc.Name);
        foreach (DBDictionaryEntry entry in subDictionaryPointCloudDefExDic)
        {
            pointCloudIds.Add(entry.Value);
        }
        this._listenerLog.Info("    Remove todos as Nuvens de Pontos (através de 'Erase' e 'Purge'), para o DWG " + _acDoc.Name);
        if (pointCloudIds.Count &amp;gt; 0)
        {
            foreach (ObjectId id in pointCloudIds)
            {
                DBObject obj = tr.GetObject(id, OpenMode.ForWrite);
                obj.Erase();
            }
            db.Purge(pointCloudIds);
        }
    }
}
catch (Exception ex)
{
    this._listenerLog.Error("    Surgiu uma falha inesperada durante a iteração sob os Xrefs do tipo Nuvem de Pontos para o DWG " + _acDoc.Name);
    this._listenerLog.FatalError(ex);
    throw new Exception("Falha durante operação de remoção de XREFs do tipo Nuvem de Pontos.", ex);
}
finally
{
    if (null != pointCloudIds)
    {
        pointCloudIds.Dispose();
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To remove raster image, is recommended use this StackOverflow link:&lt;BR /&gt;&lt;STRONG&gt;&lt;A title="How to delete a RasterImage in autocad using .NET [closed]" href="https://stackoverflow.com/questions/31429563/how-to-delete-a-rasterimage-in-autocad-using-net" target="_blank" rel="noopener"&gt;How to delete a RasterImage in autocad using .NET [closed]&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Att,&lt;/P&gt;&lt;P&gt;Antonio Leonardo&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="exam-483-programming-in-c.png" style="width: 125px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/642561i991679AC368B4D4B/image-size/small?v=v2&amp;amp;px=200" role="button" title="exam-483-programming-in-c.png" alt="exam-483-programming-in-c.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 02:56:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-c-detach-xref-current-drawing/m-p/8824862#M40354</guid>
      <dc:creator>antonio.leonardo</dc:creator>
      <dc:date>2019-05-31T02:56:23Z</dc:date>
    </item>
  </channel>
</rss>

