Results 1 to 1 of 1

Thread: Bind Xref's in C#

  1. #1
    Member
    Join Date
    2008-08
    Posts
    49
    Login to Give a bone
    0

    Exclamation Bind Xref's in C#

    I am trying to create a utility for AutoCAD to bind all xrefs. I have ran into trouble with E-transmit when an xref is unloaded. I have found that you can do a switch for XREFSTATUS and am able to get all resolved xref's. It seems that when I run the code it says they are bound but when I open xref manager they are not.

    Is there something similar to editing attributes where I need to open the xref for editing and then close it? I have seen an xrefeditenable command


    Below is my current code setup. I plan on making a collection for each XREFSTATUS and working with it accordingly.

    Code:
    [CommandMethod("Bindem")]
            public void bindXref()
            {
                
                Document doc = acad.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;
                Database db = doc.Database;
                Transaction tr = doc.TransactionManager.StartTransaction();
    
    
                try
                {
    
    
                    using (tr)
                    {
                        ObjectIdCollection btrCol = new ObjectIdCollection();
                        XrefGraph xrgraph = doc.Database.GetHostDwgXrefGraph(false);
                        // look at all Nodes in the XrefGraph.  Skip 0 node since it is the drawing itself.
                        for (int i = 1; i < (xrgraph.NumNodes - 1); i++)
                        {
                            XrefGraphNode xrNode = xrgraph.GetXrefNode(i);
    
                            BlockTableRecord btr = (BlockTableRecord)tr.GetObject
                                (xrNode.BlockTableRecordId, OpenMode.ForWrite);
                            
                            switch (xrNode.XrefStatus)
                            {
                                //if it is a resolved xref, then add to collection to be bound
                                case Autodesk.AutoCAD.DatabaseServices.XrefStatus.Resolved:
                                    btrCol.Add(btr.ObjectId);
                                    ed.WriteMessage("\n Xref added: " + btr.Name);
                                    break;
                                case Autodesk.AutoCAD.DatabaseServices.XrefStatus.Unloaded:
                                    
                                    break;
                                case Autodesk.AutoCAD.DatabaseServices.XrefStatus.FileNotFound:
                                    
                                    break;
                                case Autodesk.AutoCAD.DatabaseServices.XrefStatus.NotAnXref:
                                    
                                    break;
                                case Autodesk.AutoCAD.DatabaseServices.XrefStatus.Unreferenced:
                                    
                                    break;
                            }
    
                        }
                        ed.WriteMessage("\nTrying to bind");
                        try
                        {
                            //if there are xref id's in btrCol then attempt to bind each one
                            if (btrCol.Count > 0)
                            {
                                foreach (ObjectId id in btrCol)
                                {
                                    db.BindXrefs(btrCol, true);
                                    ed.WriteMessage("\nBound");
                                }
                            }
    
                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception ee)
                        {
                            ed.WriteMessage("\n Could Not Bind!" + ee);
                        }
                    }
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ee)
                {
                    ed.WriteMessage("\nFailed!" + ee);
                }
    
            }
    Last edited by RobertB; 2009-02-02 at 06:49 PM. Reason: Added code tags

Similar Threads

  1. Xref Bind Option
    By BCrouse in forum AutoCAD General
    Replies: 6
    Last Post: 2014-06-19, 04:28 PM
  2. Bind an xref with VLISP
    By msretenovic in forum AutoLISP
    Replies: 7
    Last Post: 2011-08-24, 07:44 PM
  3. Bind xref
    By slaforest in forum AutoLISP
    Replies: 2
    Last Post: 2007-09-28, 01:31 PM
  4. Unable to Bind Xref's / Some Xref's no longer there
    By cwjean76 in forum AutoCAD General
    Replies: 1
    Last Post: 2006-12-22, 05:00 PM
  5. Xref Bind
    By rflores.73491 in forum AutoCAD General
    Replies: 2
    Last Post: 2005-01-06, 12:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •