Author Topic: Come one come all - Bind my xrefs  (Read 9723 times)

0 Members and 1 Guest are viewing this topic.

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Come one come all - Bind my xrefs
« Reply #45 on: January 11, 2008, 03:49:41 PM »
yea, I know I should as well.  KB and I have had that discussion, and I just never go there.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Come one come all - Bind my xrefs
« Reply #46 on: January 11, 2008, 04:01:11 PM »
OK, here is version 2 which works.  Now to try and figure out how to do it without opening the dwg in the editor
Code: [Select]
        [CommandMethod("BindTep2")]
        static public void BindTitleBlocks2()
        {
            Document Doc = AcadApp.DocumentManager.MdiActiveDocument;
            Database Db = Doc.Database;
            Editor Ed = Doc.Editor;
            XrefGraph XG = Db.GetHostDwgXrefGraph(true);
            if (XG.IsEmpty || XG.NumNodes == 1)
            {
                return;
            }
            using (Transaction Trans = Doc.TransactionManager.StartTransaction())
            {
                BlockTable BT = Trans.GetObject(Db.BlockTableId, OpenMode.ForWrite) as BlockTable;

                for (int i = 0; i < XG.NumNodes; i++)
                {
                    XrefGraphNode XGN = XG.GetXrefNode(i) as XrefGraphNode;
                    if (string.Compare(XGN.Name, "TEP", true).Equals(0) ||
                        string.Compare(XGN.Name, "UES", true).Equals(0) ||
                        string.Compare(XGN.Name, "VTEP", true).Equals(0) ||
                        string.Compare(XGN.Name, "VUES", true).Equals(0))
                    {
                        BlockTableRecord BTR = Trans.GetObject(XGN.BlockTableRecordId, OpenMode.ForWrite, false) as BlockTableRecord;
                        ObjectIdCollection BlkRefCol = BTR.GetBlockReferenceIds(true, true);
                        if (BlkRefCol.Count > 0)
                        {
                            ObjectIdCollection OIC = new ObjectIdCollection();
                            OIC.Add(BTR.Id);
                            Db.BindXrefs(OIC, true);
                        }
                        else
                        {
                            Db.DetachXref(BTR.Id);
                        }

                    }
                }
                Trans.Commit();
            }
            Db.SaveAs(Doc.Name , DwgVersion.Current);
        }
« Last Edit: January 11, 2008, 04:39:35 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Come one come all - Bind my xrefs
« Reply #47 on: January 11, 2008, 04:07:18 PM »
yea, I know I should as well.  KB and I have had that discussion, and I just never go there.
I understand.  If you can find what you need here, no need to really go over there.

Code wise, it looks good to me.  Let see what the masters think when they log on.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Come one come all - Bind my xrefs
« Reply #48 on: January 11, 2008, 04:44:55 PM »
I read the thread where Glenn opened files from a dialog box, but I have never done that either.  Any ideas?  I did a search on batching, but couldn't find anything that looked close enough to make sure I was looking at the correct thing
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Come one come all - Bind my xrefs
« Reply #49 on: January 11, 2008, 05:01:55 PM »
I read the thread where Glenn opened files from a dialog box, but I have never done that either.  Any ideas?  I did a search on batching, but couldn't find anything that looked close enough to make sure I was looking at the correct thing
Sure.  Here is some snippets of code that I use to open multiply drawing databases.

Code: [Select]
Document Doc = AcadApp.DocumentManager.MdiActiveDocument;
Autodesk.AutoCAD.Windows.OpenFileDialog OpenDia =
new Autodesk.AutoCAD.Windows.OpenFileDialog("Select drawings to update title blocks.",
"",
"dwg",
"",
Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple
   );
if (OpenDia.ShowDialog() != DialogResult.OK) return;
foreach (string Path in OpenDia.GetFilenames()) {
try {
using (Database db = new Database(false, true)) {
db.ReadDwgFile (Path, System.IO.FileShare.Read, true, null);
[color=red]                       // Don't need the red if not updating attributes or text
if (db != HostApplicationServices.WorkingDatabase)
HostApplicationServices.WorkingDatabase = db;[/color]
GetTitleBlock(db);
//MessageBox.Show(Doc.Name);
HostApplicationServices.WorkingDatabase = Doc.Database;
db.RetainOriginalThumbnailBitmap = true;
db.SaveAs (Path, DwgVersion.Current);
}
}
catch (System.Exception ex) {
MessageBox.Show("Error in drawing: " + Path + "\n\n" + ex.Message);
}
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Come one come all - Bind my xrefs
« Reply #50 on: January 11, 2008, 05:04:29 PM »
Thanks Tim, that points me in the right direction.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Come one come all - Bind my xrefs
« Reply #51 on: January 11, 2008, 05:05:32 PM »
Thanks Tim, that points me in the right direction.
You're welcome.  Let us know if you need any explanation.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Come one come all - Bind my xrefs
« Reply #52 on: January 11, 2008, 05:20:16 PM »
Oh I need LOTS of explanation, I'm just trying to struggle through it w/o asking you to throw me a fish
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second