ThisDrawing.Application.Documents.Open

ThisDrawing.Application.Documents.Open

mendesva
Enthusiast Enthusiast
3,370 Views
4 Replies
Message 1 of 5

ThisDrawing.Application.Documents.Open

mendesva
Enthusiast
Enthusiast

Hi every one,

I have a VBA marco which opens (one by one)  all the DWGs in a specific folder and subfolders.

After opening and closing a few files, Autocad needs a least 5 minutes until the file is opened.

Actually I think that at that point the file is already loaded and  opened.

Autocad seems to be checking something in background (not part of my macro).

As I have +/-2200 files to open and apply some changes to them with the macro, it would take 2200 files * 5 minutes = 11000 minutes (= 183 hours or 7 days).

The part of the macro which applies the changes to the drawing just last for less than second.

The macro looks like this (reduced for message propose...):

 

Sub ListSubFolder(subFolders As Scripting.Folders)

    Dim fileItem As Scripting.File

    Dim subFolder As Scripting.Folder

 

    For Each subFolder In subFolders

        If subFolder.subFolders.Count > 0 Then

            ListSubFolder subFolder.subFolders

        End If

        If subFolder.Files.Count > 0 Then

            For Each fileItem In subFolder.Files

                If fileItem.Type = "AutoCAD Drawing" Then

 this is the line where the waiting takes place...

                    ThisDrawing.Application.Documents.Open fileItem.Path

' on the COMMANDLINE I see that the file is opened.

' from this point on nothing seems to hapen expept that the CPU usage is at 100%

' and Memory usage at it's maximum.

' the computer gets so slow that all I can do is sit and wait (like Sydney Youngblood...)

                    currFilename = ThisDrawing.Name ' for later control in macro

' run my macro here, it takes less than a second to step to the next line

                    ThisDrawing.Save

                End If

            Next fileItem

        End If

    Next subFolder

End Sub

 

So if someone knows why this is like it is until I get retired, I would be very happy and pleased.

Thank you.

 

0 Likes
3,371 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

hi mendesva,

I too have a similar code(don't have it today..it is at my office computer)

 

i have used some logic similar to the one below for recognising autocad file..this may be faster to the filetype method..my files are opening rather fast using this..try it..will get full code if u want on monday..

 

If Right(fileitem.path,3) = "DWG" OR Right(fileitem.path,3)="dwg" Then

 

Thank you

Vinayan

0 Likes
Message 3 of 5

Anonymous
Not applicable

Hi guys,

 

Just a small correction to your code and explanation why I would do it.

 

Instead of:

If Right(fileitem.path,3) = "DWG" OR Right(fileitem.path,3)="dwg" Then

 

I would use:

If UCase(Right$(fileitem.path, 3)) = "DWG" Then

 

  1. The reason for the UCase() statement is because it pushes everything to uppercase, eliminating the second verification.
  2. The reason for the Right$() instead of using just Right() is because the Right$() returns a string value rather than a variant value.

Just some proper programming techniques I thought I'd share.  Have a great day guys!  =D

0 Likes
Message 4 of 5

Hallex
Advisor
Advisor

Just an idea...

You might want to create an array of file names before and then loop through this array

(FileSystemOBject must be released after this point)

It may helps  I think

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 5 of 5

Anonymous
Not applicable

Much more than your code could be causing this problem.  Just some thoughts ...

 

Could there be missing xref issues?

is there a hidden dialog box?

Any Autolisp code running on some drawings, not others?

Network traffic issues?  

do the file paths have urls or mapped drive references?  

could the mapped drive be auto-timing out?

if the dwg files are rather large, you may need to put a wait-timer in between opening and closing the files to allow natural behind the scenes stuff to occur.

 

can the drawings be opened and modified in a minimized state for the macro to work?  professional experience proves drawings can be automated much quicker when minimized and rendering not required.

 

 

0 Likes