Status of all Underlays

Status of all Underlays

serge
Advocate Advocate
1,624 Views
7 Replies
Message 1 of 8

Status of all Underlays

serge
Advocate
Advocate

Good evening,
I'm searching for some code to analyse the status of linked *.dwg, *.jpg (Bitmaps) and *.pdf
In fact I want to be sure that these type of Underlays are not MISSING in drawing(s)
Thank you for any ideas...

DEVIDTS Serge, CAD Consultant
http://www.CADdICT.be
0 Likes
Accepted solutions (1)
1,625 Views
7 Replies
Replies (7)
Message 2 of 8

norman.yuan
Mentor
Mentor

While all the things you mentioned (*.dwg, *.dwf, *.jpg/*.bmp, *.pdf) that "linked" to a drawing shows in XReference Manager window and may be called Xreferences in general, they are different things in AutoCAD's Object Model:

 

XReferenced drawing is inserted into the current drawing as a block definition and then a reference to it is shown;

*.dwf, *.dgn, *.pdf, is inserted into drawing as AcadXXXUnderlay;

*.jpg/*.bmp... is inserted into drawing as AcadRasterImage;

 

Each of the object has either "Path" property (XRefed drawing), or "File" (AcadXXXUnderlay), or "ImageFile" for image inserted. You can use code to search the drawing to find these types of entities, read the "Path/File/ImageFile" property's value, then check to see if the physical file actually exists or not (if not, the lined reference is "missing", obviously).

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 8

serge
Advocate
Advocate

Thank you very much for those hints.
When the underlay is Pathless of Hardcoded, then it is rather easy to write some code to find the existance of it.
But when the underlay has a Relative Path, then the code to be written seems a lot more complex?
Do you have by any chance an example?
Unfortunately theres is no .status property?
Thank you.

DEVIDTS Serge, CAD Consultant
http://www.CADdICT.be
0 Likes
Message 4 of 8

norman.yuan
Mentor
Mentor
The the "Path/File/ImagaeFile" property is a only a file name (without path), you need to search all AutoCAD support paths for that file. the linked Xref/Underlay/Image would be flagged "missing" when AutoCAD cannot find it from all support paths. I do not have code at hand. You need to use Dir() method to get all files in each support paths.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 8

Ed__Jobe
Mentor
Mentor
In addition to what Norman said, I would think that most likely the reference location would be based off of the parent file's location. If the xref type is Relative, then the File property would give you the path in relation to the parent file. If the File property is set to just the file name without any path info, then the xref type is set to None. Like Norman said, you can search all the paths in the support file search paths, but I NEVER put xrefs there. I always keep the parent and the reference in the same folder. Therefore, you should be able to just concatenate the parent's path with the underlay's File property. If that fails, then you can search the sfsp. For searching files, I would use the scripting object's FileSystemObject. It has a FileExists() method. You supply the path and it tells you if the path is resolved. Below is a sample of copied code to show you how to create/use the FileSystemObject. Dim fso As Scripting.FileSystemObject Dim fsoFile As Scripting.file Set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists(strDefaultFile) = True Then strFileName = fso.GetParentFolderName(strDefaultFile) End If

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 6 of 8

serge
Advocate
Advocate

To get grip on all linked Bitmaps I included:

Dim m_objBitmap as AcadRasterImage
For each m_objBitmap in ActiveDocument.Modelspace
 (Get name, etc...)
next m_objBitmap

But this does NOT work if the Bitmmaps are linked in a Paperspace Layout
Strange... are linked Bitmaps objects not Space-independent?
How can I include some code to respect also Paperspace?

Thank you!




DEVIDTS Serge, CAD Consultant
http://www.CADdICT.be
0 Likes
Message 7 of 8

norman.yuan
Mentor
Mentor
Accepted solution

@serge wrote:

... ...
Strange... are linked Bitmaps objects not Space-independent?
...


Image inserted into drawing, just like any AcadEntity, is similar to block in AutoCAD: there is block definition (AcadBlock), which stays in block table, not visible; and there could be zero, or more block references (AcadBlockReference) being inserted ModelSpace or PaperSpaces. So, the image you are talking here is like acadBlockReference that can be inserted into ModelSpace, or PaperSpaces (Layouts). So, if you want to find all Images existing in a drawing, but not sure if they only in ModelSpace, or in one or more Layouts, then you need to search all layouts (including ModelSpace)

 

Obviously, when you do

 

For Each m_objBitmap in ActiveDocument.ModelSpace

    ...

Next

 

it ONLY searches/loops through ModelSpace.

 

To go through all Layouts (including "Model" layout - ModelSpace), you can simply loop through AcadLayouts collection, something like:

 

Dim lay As AcadLayout

Dim ent As AcadEntity

Dim img As AcadRasterImage

Dim count As Integer

For Each lay in ThisDrawing.Layouts

    count=0

    For Each ent In lay.Block

        If TypeOf ent Is AcadRasterImager Then

            Set img=ent

            MsgBox "Found image: " & img.ImageFile

            count = count + 1

        End If

    Next

    MsgBox count & " image(s) found in layout """ & lay.Name & """"

Next

 

HTH

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 8 of 8

serge
Advocate
Advocate

Good afternoon,
thank you very much, this seems to give me a solution, I'll have to integrate it in my code.
Still... I dont' understand why I can't approach the 'collection' of linked Images and their status,
instead needing to browse through every layout searching for instances of them.

DEVIDTS Serge, CAD Consultant
http://www.CADdICT.be
0 Likes