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

How to programmatically find all references (xref dwg, jpg, pdf, OLE etc)?

13 REPLIES 13
Reply
Message 1 of 14
mattiash
6372 Views, 13 Replies

How to programmatically find all references (xref dwg, jpg, pdf, OLE etc)?

Hi,

I have some code (.Net addin application) that reads xrefs from a drawing. This code uses DataBase.GetHostDwgXrefGraph() and has worked fine until now.


However, now I've run into some drawings that references not only .dwg-files, but also .jpg-files.


In the XREF dialog in AutoCAD I can see that .jpg-files are referenced by the "parent" drawing, but GetHostDwgXrefGraph() doesn't seem to find the .jpg files.

I have attached some sample code to illustrate what I do (FindExternalReferences.cs). In that file, I have a CommandMethod "xrl" finds all references of the mdi document and writes to debug output in visual studio.


Also I added a zip-file containing a drawing "parent.dwg", and it referenes some other files that also are in the zip-file:
* Another .dwg - child.dwg
* sample-jpg.jpg
* OLE link - sample-word.docx
* PDF - sample-pdf.pdf
* WMF - sample-wmf.wmf

My top priority is to find referenced images (jpg, png, bmp), but I'd also be interested in how to find referenced OLE links, PDF and WMF.


Can I use GetHostDwgXrefGraph to accomplish this, or do I need to use some other method? Basically I'd like some code suggestion how I can find all referenced files from "parent.dwg" (not only the .dwg as my code works now).


Thanks in advance,
Mattias
13 REPLIES 13
Message 2 of 14
Anonymous
in reply to: mattiash

Have a look at the Database's FileDependencyManager property.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6343866@discussion.autodesk.com...
Hi,

I have some code (.Net addin application) that reads xrefs from a drawing. This
code uses DataBase.GetHostDwgXrefGraph() and has worked fine until now.


However, now I've run into some drawings that references not only .dwg-files,
but also .jpg-files.


In the XREF dialog in AutoCAD I can see that .jpg-files are referenced by the
"parent" drawing, but GetHostDwgXrefGraph() doesn't seem to find the .jpg files.

I have attached some sample code to illustrate what I do
(FindExternalReferences.cs). In that file, I have a CommandMethod "xrl" finds
all references of the mdi document and writes to debug output in visual studio.


Also I added a zip-file containing a drawing "parent.dwg", and it referenes some
other files that also are in the zip-file:
* Another .dwg - child.dwg
* sample-jpg.jpg
* OLE link - sample-word.docx
* PDF - sample-pdf.pdf
* WMF - sample-wmf.wmf

My top priority is to find referenced images (jpg, png, bmp), but I'd also be
interested in how to find referenced OLE links, PDF and WMF.


Can I use GetHostDwgXrefGraph to accomplish this, or do I need to use some other
method? Basically I'd like some code suggestion how I can find all referenced
files from "parent.dwg" (not only the .dwg as my code works now).


Thanks in advance,
Mattias
Message 3 of 14
mattiash
in reply to: mattiash

Hi Tony, thanks for replying.

FileDependencyManager looks really interesting, however I found no documentation or samples on how to use it. By looking at FileDependencyManager in Visual Studio, it looks like it has methods for updating and erasing entries, but I found no way of enumerating all entries (???). Am I missing something obvious here? Do you have any suggestion on how to use the FileDependencyManager?

Thanks in advance,
Mattias
Message 4 of 14
btmsoftware
in reply to: mattiash

Mattias,

Have you found some examples somewhere (or do yo have some) and can you share them with me (us), I have the same requirements...

Thanx in advance
Message 5 of 14
vasantpadhiyar71
in reply to: mattiash

Hi,

 

Your code is good and it works fine..

 

But when I want to find only Direct Children then what to do?

 

 

Suppose I have a Drawing Structure like:
MasterRoot
    Root1
        MasterChild1
            Child
        MasterChild2
            Child
    Root2
        MasterChild1
            Child
        MasterChild2
            Child

When I use XrefGraph xg = mainDb.GetHostDwgXrefGraph(true); in Code then I get all the Files as a node including MasterRoot (say count=6).
If I want to get Only direct Children (here, Root1 and Root2)(means count=2 only), then wha i have to do?
Is it Possible?
Any help will be appreciated.

Thanks in Advance..

Thanks & Regards,
Vasant Padhiyar

Vasant PADHIYAR
Message 6 of 14
rick_hgy
in reply to: mattiash

we meet same problem.

 

we can get the files attachment by Interop.TRANSMITTALLib.dll, but it's contain the pc3 and so on. 

 

Who has the perfect solution?

 

Thanks!

 

Rick

Message 7 of 14
vasantpadhiyar71
in reply to: rick_hgy

Hi,

 

Please Go through the following link for the Solution:

 

http://forums.autodesk.com/t5/NET/How-can-I-get-Direct-xref-of-a-Particular-Drawing-using-C-Code/m-p...

 

Hope it helps..

 

Thanks,

Vasant PADHIYAR
Message 8 of 14
rick_hgy
in reply to: mattiash

Thanks, Vasant!

 

we can get all DWG reference file, but can't find the image(jpg/png/tiff)/PDF format file which attached my xref manager.

 

so your link's  soluton can get the image file name/path?

 

Thanks!

 

Rick

 

 

Message 9 of 14
rick_hgy
in reply to: vasantpadhiyar71

Dear Vasant,

 

We tested the code in the new link(http://adndevblog.typepad.com/autocad/2012/06/finding-all-xrefs-in-the-current-database-using-cnet.h... it's can't find the image file's name/path.

 

Pls see the attachment of sample drawings with dwg/JPG xref files.

 

Thanks again!

 

Rick

 

 

 

 

Message 10 of 14
Artvegas
in reply to: rick_hgy

It is my understanding that the xref graphing part of the API only applies to xrefs. To handle pdfs and raster images you need to work more directly with the named objects dictionary, specifically the PdfDefinition and RasterImageDef classes. It should be noted that you can also access xrefs from the block table, because xrefs are essentially brought in as blocks. However xref graphing provides additional support for nesting (which doesn't apply with pdfs or images). Here are some samples posted by norman yuan for pdfs: http://forums.autodesk.com/t5/NET/Attach-PDF-or-RasterImage-Reload/m-p/3095024/. And for raster images: http://adndevblog.typepad.com/autocad/2012/05/how-to-insert-a-rasterimage-using-the-net-api.html I strongly recommend that you dig into the database structure to see what's going on under the hood. You can do this using the MgdDbg tool: http://adndevblog.typepad.com/autocad/2012/04/dwg-debugger-mgddbg-app-for-autocad-20122013.html Art
Message 11 of 14
rick_hgy
in reply to: Artvegas

Artvegas,

 

Your suggestion is very useful. we will check it with blocktable for testing, thanks!

 

Rick

Message 12 of 14
Artvegas
in reply to: rick_hgy

Based on your response i think i should clarify for you. For xrefs it is better to use the xref graph and nodes. But for pdfs and images you use the named object dictionary. Art.
Message 13 of 14
kbarnettza
in reply to: Artvegas

ARTVEGAS ... thx for participating with this thread, your input helped me get all references very quickly using "internal" managed c# (NETLOAD DLL).

 

What about COM?

 

How would we do the same process in an interop/com development (ouitside AutoCAD)?

 

I thought that maybe document.filedependencies would list the referenced files. On my test it did not.

 

Thanks again..

 

Kevin.

 

Message 14 of 14
Littlerubarb
in reply to: Artvegas

Just to close the discussion here's how to do it...

 

<CommandMethod("DetachImg")> _
Public Sub detach_img(mainDrawingFile As String)
Dim db As New Database(False, True)
db.ReadDwgFile(mainDrawingFile, System.IO.FileShare.ReadWrite, True, "")
Using db
Dim saveRequired As Boolean = False
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim imageDictId As ObjectId = RasterImageDef.GetImageDictionary(db)
If imageDictId.IsNull Then
Else
Dim imageDefinitions As New Dictionary(Of ObjectId, RasterImageDef)()
Dim imageDictionary As DBDictionary = tr.GetObject(RasterImageDef.GetImageDictionary(db), OpenMode.ForWrite)
For Each entry As DBDictionaryEntry In imageDictionary
Dim id As ObjectId = entry.Value, ObjectId
Dim rasterImageDef__1 As RasterImageDef = tr.GetObject(id, OpenMode.ForWrite)
If rasterImageDef__1.LocateActivePath = "" Then
rasterImageDef__1.Erase()
saveRequired = True
End If
Next
End If
tr.Commit()
tr.Dispose()
End Using
If saveRequired Then
db.SaveAs(mainDrawingFile, DwgVersion.Current)
End If
End Using
End Sub

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost