CaveMan Posted August 2, 2011 Share Posted August 2, 2011 Good Day looking for code in vb.net where i can retrieve what exrefs are in a drawing file without opening it. Will also like to be able to edit the exrefs paths and files within the drawing database. The method would also be useful to extract attributes etc. from drawing files without opening them. Any help most welcome. Regards CaveMan Quote Link to comment Share on other sites More sharing options...
Tyke Posted August 2, 2011 Share Posted August 2, 2011 Have a look on Kean Walmsley's site Through the Interface and try a search there. Link: http://through-the-interface.typepad.com/ It is possible to access a drawing database without opening the drawing or having AutoCAD installed on the machine, but I'm not sure if you need software called RealDWG to doit, never tried it myself. Quote Link to comment Share on other sites More sharing options...
CaveMan Posted August 2, 2011 Author Share Posted August 2, 2011 I have read through some of Kean Walmsley's tutorials before - quiet intense level at times - appreciate the link - at the moment have a sample - but have to step through it piece by piece - not sure if it will work though??? Guess if we do not try we cant make mistakes to learn from? Regards CaveMan Quote Link to comment Share on other sites More sharing options...
Jeff H Posted August 2, 2011 Share Posted August 2, 2011 (edited) You need RealDWG if AutoCAD is not installed or if you do not want AutoCAD running. For a better solution look at Database.GetHostDwgXrefGraph where you can get nested Xrefs This is Hard-coded for a simple example and just to get you started You have both Drawings in "C\Test" XrefDrawing.dwg and XrefHost.dwg XrefHost has XrefDrawing xref in and move it to another folder --Database.ReadDwgFile for opening a drawing where you do not interact with it in the Editor --Iterate the BlockTable checking the BlockTableRecord.IsFromExternalReference Property --Change PathName property and move file <CommandMethod("ChangeXrefPath")> _ Public Sub ChangeXrefPath() Using db As New Database(False, True) Try db.ReadDwgFile("C:\Test\XrefHost.dwg", FileOpenMode.OpenForReadAndWriteNoShare, True, Nothing) Using trx As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = trx.GetObject(db.BlockTableId, OpenMode.ForRead) For Each objId As ObjectId In bt Dim btr As BlockTableRecord = trx.GetObject(objId, OpenMode.ForRead) If btr.IsFromExternalReference Then btr.UpgradeOpen() btr.PathName = "C:\Test\NewLocation\XrefDrawing.dwg" Exit For End If Next trx.Commit() End Using db.SaveAs(db.Filename, True, DwgVersion.Current, db.SecurityParameters) Catch End Try End Using System.IO.File.Move("C:\Test\XrefDrawing.dwg", "C:\Test\NewLocation\XrefDrawing.dwg") End Sub End Class Edited August 2, 2011 by Jeff H Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 2, 2011 Share Posted August 2, 2011 Interesting thread. @ Jeff - "ChangeXrefPath" has a lot of new stuff (for me) in there, which has helped to answer *how* to re-write some of my LISP code in VB.NET (hooray!). Cheers! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.