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

0 Members and 1 Guest are viewing this topic.

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Come one come all - Bind my xrefs
« Reply #15 on: January 09, 2008, 07:30:46 PM »
Duh,

More info please, especially on the 1/4 rule that is in effect.

Cheers,
Glenn.
Me

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Come one come all - Bind my xrefs
« Reply #16 on: January 09, 2008, 07:41:05 PM »
I was reading in the Arx doc's to see how one would do this about the dll import, and it says that xref bind uses the 'wblockclone' method.  I was wondering if there would be any redeeming qualities for going this route with .Net instead of using 'dll import'.  The only thing I can think of is you wouldn't have to change the code per new release of Acad, as you wouldn't have to find the new entry point.
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 #17 on: January 10, 2008, 09:17:15 AM »
Glenn, I have 4 titleblocks named TEP.dwg, UES.dwg, VTEP.dwg, and VUES.dwg.  There should be only 1 of the four in  the dwg file.  There could be a definition to one of the others, i.e. it was a TEP dwg then became a UES dwg, and the drafter erased the xref instead of detaching it.  Does that make sense?
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

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Come one come all - Bind my xrefs
« Reply #18 on: January 10, 2008, 09:20:35 AM »
Yep.

What version of AutoCAD?

Cheers,
Glenn.
Me

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Come one come all - Bind my xrefs
« Reply #19 on: January 10, 2008, 09:33:19 AM »
Im using 08, but the dwgs were created in 2002-> 08
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

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Come one come all - Bind my xrefs
« Reply #20 on: January 10, 2008, 09:41:30 AM »
Cool, no problems there.
Me

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Come one come all - Bind my xrefs
« Reply #21 on: January 10, 2008, 10:58:07 AM »
Well doing some initial research, I found this in the object browser
Quote
public void BindXrefs(Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection xrefIds, bool insertBind)
    Member of Autodesk.AutoCAD.DatabaseServices.Database

So it looks like we can get there from here.  Now just to figure out how.  Im thinking we have to do a selection set w/ filter for blocks with the correct names, and then check if its a Xref.  then grab id and pass to the function.  OR we browse the BlockTable for the names, and check the individual BTR for is it a xref, then pass it to function.  Just thinking out loud
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: 5218
Re: Come one come all - Bind my xrefs
« Reply #22 on: January 10, 2008, 11:05:43 AM »
Look at 'XrefGraph' to find the xrefs.  If you need to find the ObjectId's of the inserted xref, then you can get that from the BlockTableRecord.
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 #23 on: January 10, 2008, 11:27:19 AM »
would xrefgraph be faster than just browsing the BTR for the names Im looking for?
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: 5218
Re: Come one come all - Bind my xrefs
« Reply #24 on: January 10, 2008, 11:51:13 AM »
would xrefgraph be faster than just browsing the BTR for the names Im looking for?
Yes because it will only list the xrefs.  Think if you have a drawing that has one xref, and a thousand blocks.  You can get the BTR from the XrefGraphNode of the XrefGraph.  Just note that the first item in the XrefGraph is the drawing itself.

Tried to post this earlier, but got an error that the site couldn't be reached.
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 #25 on: January 10, 2008, 05:25:40 PM »
Well Im finding some good stuff, so I will go think on this and post something hopefully tomorrow
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 #26 on: January 11, 2008, 11:11:25 AM »
WOOOOOOOOHHHHHOOOOOOOOO .Net kicks butt!!!!

Ok, I made some progress.  I was able to bind 1 xref fairly simply.  Please critique what you can, and see if I could do it better.  Thanks to Glenn R for the idea, and TW for pointing me in the direction of Glenn's code

Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace XrefBind
{
    public class DSHClass
    {
        [CommandMethod("BindTep")]
        static public void BindTitleBlocks()
        {
            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.ForRead) as BlockTable;
                for (int i = 0; i < XG.NumNodes; i++)
                {
                    XrefGraphNode XGN = XG.GetXrefNode(i) as XrefGraphNode;
                    if (XGN.Name.ToUpper() == "TEP")
                    {
                        BlockTableRecord BTR = Trans.GetObject(XGN.BlockTableRecordId, OpenMode.ForRead, false) as BlockTableRecord;
                        ObjectIdCollection OIC = new ObjectIdCollection();
                        OIC.Add(BTR.Id);
                        Db.BindXrefs(OIC, true);
                    }
                }
                Trans.Commit();
            }

        }
    }
}
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: 5218
Re: Come one come all - Bind my xrefs
« Reply #27 on: January 11, 2008, 11:24:45 AM »
Looks good to me.  Now to write it so you don't have to open the drawing in the editor so it will be faster.  You will only open the database, since that is all you need.  This snippet from Glenn should get you going in the right direction.

Glad your having fun with it!  It is addicting.   :-D
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 #28 on: January 11, 2008, 11:33:36 AM »
Thanks Tim.  Before I move on to the hard pard of not opening the dwg, what would be the best way to test for the 4 options.  Coming from VBA, I'm thinking Select Case.  But, I noticed the || in the IF statement, and was wondering if there might be a way to use that?
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: 5218
Re: Come one come all - Bind my xrefs
« Reply #29 on: January 11, 2008, 11:46:08 AM »
I think that is how I would do it.  I also would use ' string.Compare(XGN.Name, "TEP", true).Equals(0) '.  Where the 'true' tell it to ignore case.  If two strings are equal, the method returns a 0 ( less that 0 if a < b, greater than 0 if a > b), hence the ' .Equals(0) '.

Edit: Link to string.Compare method on MSDN.
« Last Edit: January 11, 2008, 11:57:37 AM by Daron »
Tim

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

Please think about donating if this post helped you.