.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Loading an external database and not being able to read the Xrefs - AcCoreCosole

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Anonymous
1449 Views, 9 Replies

Loading an external database and not being able to read the Xrefs - AcCoreCosole

(moved from ObjectARX forum to this .Net forum)

 

Hi everybody,

 

I'm trying to achieve the following;

  1. Using AcCoreConsole and loading my custom .Net assembly
  2. Loading DWG files (file by file from disk, with a side or external database approach and using ReadDwgFile method.)
  3. Reading the Xref information (Object based, FileDependencyManager, etc)
    Prefferable all files related to the main DWG file.
  4. Writing the collected results to an XML file for further use.

 

Software;

  • Windows 10
  • AutoCAD software 2016 - SP1
  • ObjectARX SDK for 2016 64bit
  • VS2015 (vb) with .Net 4.5

 

I've been reading a lot of posts, blogs, tips and ideas how to load external databases and how to read references from a database. I'm able to succesfully read references when I'm reading the 'current' database, but I'm simply not able to read the same from an external database and it's getting realy frustrating. Also the jungle of the DGW objects doesn't realy help.

 

In my last try, I'm

  1. loading AcCoreConsole calling my custom method.
  2. Storing the current db into a temp var
  3. Creating a new database Database(False, True)
  4. ClosingInput
  5. Setting the HostWorking databse to my new DB
  6. Reading a DWG file from disk in ReadShareAll mode. E.g. "my_other_dwg_file.dwg"
  7. Going through the Graph using newdb.GetHostXrefGraph
  8. Strting with the root object, getting the FileName

==> Issue; I'm still getting the original drawing info "Drawing1"...

 

Also tried Database(False, False) and got an eInput error (or something). The removed the CommandFlag.Session which solved that part, but still no external database xref solution. Fried FIleManager with the initialize options, but it;s simpley empty (no index)...

 

Has anybody got a clue what I'm doing wrong here?

Rg, Ingmar.

 

 

P.s.;The anoing part also, is that my VS2015 debugging is only able to stop at break points, but not diplaying me the content of any variable or using the 'Watch' (It's called edit & continue I think). There was a (30-day) moment where I was using AutoCAD 2017+sp1 with SDK 2017 with a working debugger (which cause me a lot of effor to get it working). I recently downloaded 2016+sp1 with SDK 2016 to have an additional trial period of 30 day, but now the debugger is broken... Maybe it only works in AC2017...

9 REPLIES 9
Message 2 of 10
Alexander.Rivilis
in reply to: Anonymous

Try Database.ResolveXrefs

http://adndevblog.typepad.com/autocad/2013/09/databaseresolvexrefs-documentation.html

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 10
FRFR1426
in reply to: Anonymous

In VS2015, go to Tools, Options, Debugging, General and try to change Use Managed Compatibility Mode to see it that help. You can read this post to get more informations on this settings.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 4 of 10
FRFR1426
in reply to: Anonymous

Here is a working code, derived from http://adndevblog.typepad.com/autocad/2012/06/finding-all-xrefs-in-the-current-database-using-cnet.h...

 

[CommandMethod("XREFGRAPH")]
public void XrefGraph()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
    using (var sideDb = new Database(buildDefaultDrawing: false, noDocument: false))
    {
        sideDb.ReadDwgFile(@"<Your path>", FileShare.Read, 
            allowCPConversion: true, password: null);
        using (Transaction tr = sideDb.TransactionManager.StartTransaction())
        {
            ed.WriteMessage("\n---Resolving the XRefs------------------");
            sideDb.ResolveXrefs(useThreadEngine: true, doNewOnly: false);
            XrefGraph xg = sideDb.GetHostDwgXrefGraph(includeGhosts: true);
            ed.WriteMessage("\n---XRef's Graph-------------------------");
            var root = (XrefGraphNode) xg.RootNode;
            ed.WriteMessage($"\nCURRENT DRAWING ({root.Name})");
            PrintChildren(root, "|-------");
            ed.WriteMessage("\n----------------------------------------\n");
            tr.Commit();
        }
    }
}

void PrintChildren(GraphNode root, string indent)
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
    for (int o = 0; o < root.NumOut; o++)
    {
        var child = (XrefGraphNode) root.Out(o);
        if (child.XrefStatus != XrefStatus.Resolved) continue;
        var bl = (BlockTableRecord) child.BlockTableRecordId.GetObject(OpenMode.ForRead);
        ed.WriteMessage("\n" + indent + child.Database.Filename);
        // Name of the Xref (found name)
        // You can find the original path too:
        if (bl.IsFromExternalReference)
            ed.WriteMessage($"\n{indent}Xref path name: {bl.PathName}");
        PrintChildren(child, "| " + indent);
    }
}
Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 5 of 10
Anonymous
in reply to: FRFR1426

Hi Maxence,

 

I'm a bit suppriced, because I had this setting checked (true) "Use Managed Compatibility Mode", because I used the same blog when I was bedugging with the same VS2015, but then using ObjectARX for AC2017 release (few weeks ago).

 

Now working with AC2016 and SDk2016 and I wa snot able to dubug normaly. I just simply unchecked this option, "Use Managed Compatibility Mode" and now everything works again. Its a bit ackward... But I'm happy 🙂

Message 6 of 10
Anonymous
in reply to: FRFR1426

Hi Maxence,

 

Thanks for the quick reply. Found that bolog also. This blog code is working fine, but it's not the solution I'm looking for. This code uses the active document of the document loaded when starting AcCoreConsole.

 

The problem is that when Im loading an external database using ReadDwgFile, I would like to use the document from that database. Every step succeeds:

 

Dim workingDb As Database = HostApplicationServices.WorkingDatabase

Dim workingDoc As Document = Application.DocumentManager.MdiActiveDocument

Dim dwgDb As New Database(False, False)

dwgDb.ReadDwgFile(dwgFileName, FileOpenMode.OpenForReadAndAllShare, True, String.Empty)

dwgDb.CloseInput(True)

dwgDb.ResolveXrefs(True, False)

HostApplicationServices.WorkingDatabase = dwgDb

Dim docDwg As Document = Application.DocumentManager.MdiActiveDocument

 

 

1. Object docDwg is still refering to "Drawing1"

2. dwgDB shows me my filename from ReadDwgFile, but when I use method: GetHostDwgXrefGraph(True), i still get info from "Drawing1"

 

I'm trying to get the Xref graph from my ReadDwgFile source, but still fail to do so.

 

Message 7 of 10
Alexander.Rivilis
in reply to: Anonymous

Hi @Anonymous

First of all code of @FRFR1426 do not use active document. HostDwg is sideDb. Did you checked his code?

 

>>>The problem is that when Im loading an external database using ReadDwgFile, I would like to use the document from that database.<<<

It is impossible at all. You can not get document for external database if this database is not opened in AutoCAD editor with methods such as DocumentCollection.AppContextOpenDocument

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 8 of 10
Anonymous
in reply to: Anonymous

It looks like I found a solution to load the Xref file info from an external db!:

 

Dim bt As BlockTable = tr.GetObject(dwgDb.BlockTableId, OpenMode.ForRead)

sText = ""

Try

    For Each objId As ObjectId In bt

        Dim btr As BlockTableRecord = tr.GetObject(objId, OpenMode.ForRead)

        If btr.XrefStatus <> XrefStatus.NotAnXref Then

            sText &= btr.PathName & vbCrLf

        End If

        btr.Dispose()

    Next

Catch ex As Exception

Finally

    bt.Dispose()

End Try

 

 

Copied and changed the logic a bit from this site;

http://www.cadtutor.net/forum/showthread.php?61496-VB.Net-Edit-dwg-files-without-opening-them

 

Now I can start cleaning my code 🙂

Message 9 of 10
Anonymous
in reply to: Alexander.Rivilis

Hi Alexander,

 

I might have found the problem;

 

Confusion 1: When I use the GetHostDwgXrefGraph, I checked the Xgraph in runtime when my debugger was fixed and saw the host document "Drawing1" and was expecting my test file "Demo".

 

Confusion 2: It seemes that I was using a wrong test file "demo". It did not contain any childs 😞

 

I just checked it again, and GetHostDwgXrefGraph is working on the side db!

Thanks for you help.

 

 

 

 

 

Message 10 of 10
FRFR1426
in reply to: Anonymous

VS 2015 + AutoCAD 2016 (_VERNUM: M.49.0.0 (UNICODE)) + Use Managed Compatibility Mode works for me.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report