(moved from ObjectARX forum to this .Net forum)
Hi everybody,
I'm trying to achieve the following;
Software;
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
==> 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...
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
Solved by FRFR1426. Go to Solution.
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
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.
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); } }
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 🙂
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.
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
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 🙂
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.
VS 2015 + AutoCAD 2016 (_VERNUM: M.49.0.0 (UNICODE)) + Use Managed Compatibility Mode works for me.
Can't find what you're looking for? Ask the community or share your knowledge.