Author Topic: Autodesk.AutoCAD.Internal.DrawingCompare  (Read 1537 times)

0 Members and 1 Guest are viewing this topic.

kaefer

  • Swamp Rat
  • Posts: 572
Autodesk.AutoCAD.Internal.DrawingCompare
« on: November 03, 2010, 09:41:38 PM »
Was anyone at it before?

Let's say we have two drawings, Drawing1 and Drawing2. Both are saved as files, Drawing2 is additionally opened in the application for visualisation of apparent changes.

Now let's compare these drawings. Drawing1 needs to be loaded into a side database, both databases have a transaction running, and...
Code: [Select]
   let comparer = Autodesk.AutoCAD.Internal.DrawingCompare()
    use objectDiffEven =
        comparer.ObjectDiffEvent
        |> Observable.subscribe(
            fun e ->
                transients :=
                    match e.ChangeType, e.DrawingId with
                    // from Drawing 1
                    | 1, 1 -> hnd2ent1 e.ObjHandle 2s
                    | 2, 1 -> hnd2ent1 e.ObjHandle 4s
                    | 3, 2 -> hnd2ent1 e.ObjHandle 1s
                    // from Drawing 2
                    | 1, 2 -> hnd2ent2 e.ObjHandle 5s
                    | 2, 2 -> hnd2ent2 e.ObjHandle 6s
                    | 3, 1 -> hnd2ent2 e.ObjHandle 3s
                    // Can anything else happen?
                    | _ -> !transients )
    let res = comparer.CompareDwgFiles(drawing1, drawing2)
...oh the joys of partial application.  If the entity comes from Drawing1, get the ObjectId out of the side database, open and clone it, else open and clone straight away. Assign a distinct color, show the entity in the drawing window and store it as head of the transients list ref cell for later disposal.

Now for the colors, whose meanings here aren't entirely clear to me. Yellow and blue objects share the same Handle and are in both drawings, albeit differing in their properties. Red or cyan means they are only in Drawing1, green or magenta for Drawing2. What's the difference?

Anyone?

Jeff H

  • Needs a day job
  • Posts: 5996
Re: Autodesk.AutoCAD.Internal.DrawingCompare
« Reply #1 on: November 03, 2010, 10:16:59 PM »
That is Great!!!
I have seen alot of people wish that was in AutoCAD

You can do a drawing compare in AutoCad MEP  and from that I wonder if you reverse the drawings
CompareDwgFiles(drawing2, drawing1) if the colors would swap

Jeff H

  • Needs a day job
  • Posts: 5996
Re: Autodesk.AutoCAD.Internal.DrawingCompare
« Reply #2 on: November 01, 2011, 03:39:50 PM »
How exactly did you get this working?
I have started something that looks promising with a DwgFiler, but if it is built-in no point in investing time in it.

kaefer

  • Swamp Rat
  • Posts: 572
Re: Autodesk.AutoCAD.Internal.DrawingCompare
« Reply #3 on: November 01, 2011, 07:18:27 PM »
How exactly did you get this working?
I have started something that looks promising with a DwgFiler, but if it is built-in no point in investing time in it.

It isn't really working. I'm just calling an undocumented method from the Internal namespace. For all I know, it could as well format my hard drive.

Incidentally, the easy part is calling the thing while an appropriate event handler is attached. ChangeType seems to be in the range 1 .. 3; DrawingId is 1 or 2.
Code: [Select]
            Dictionary<Handle, int> dict1 = new Dictionary<Handle, int>();
            Dictionary<Handle, int> dict2 = new Dictionary<Handle, int>();
            ObjectDiffEventHandler odeh = new ObjectDiffEventHandler(
                (sender, e) =>
                {
                    Dictionary<Handle, int> dict = e.DrawingId == 1 ? dict1 : dict2;
                    if (dict.ContainsKey(e.ObjHandle))
                        dict[e.ObjHandle] = e.ChangeType;
                    else
                        dict.Add(e.ObjHandle, e.ChangeType);
                });
            DrawingCompare compare = new DrawingCompare();
            compare.ObjectDiffEvent += odeh;
            CompareReturnStatus crs = compare.CompareDwgFiles(db1.Filename, ofd.Filename);
            compare.ObjectDiffEvent -= odeh;

I'm still at a loss generating a meaningful display of changes. TryGetObjectId will fail and eWasErased. Even when transients may be better suited than temporary changes to the Database, they will require importation of side database data too, e.g. SymbolTableRecords.
« Last Edit: November 01, 2011, 07:43:53 PM by kaefer »

Jeff H

  • Needs a day job
  • Posts: 5996
Re: Autodesk.AutoCAD.Internal.DrawingCompare
« Reply #4 on: November 01, 2011, 07:33:06 PM »
Thanks kaefer!!!
 
I will take a good look tonight or tommorrow and post what I have using a DwgFiler----Some kinks to work out like a hatch will have 24 more values if in opened drawing