Jump to content
CaveMan

VB.Net - Edit dwg files without opening them

Recommended Posts

CaveMan

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

Share this post


Link to post
Share on other sites
Tyke

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.

Share this post


Link to post
Share on other sites
CaveMan

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

Share this post


Link to post
Share on other sites
Jeff H

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 by Jeff H

Share this post


Link to post
Share on other sites
BlackBox

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! :beer:

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...