VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ThisDrawing.Application.Documents.Open

4 REPLIES 4
Reply
Message 1 of 5
mendesva
3095 Views, 4 Replies

ThisDrawing.Application.Documents.Open

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.

 

4 REPLIES 4
Message 2 of 5
vinayan
in reply to: mendesva

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

Message 3 of 5
KillerMungkay
in reply to: vinayan

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

Message 4 of 5
Hallex
in reply to: mendesva

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
Message 5 of 5
sardeson
in reply to: mendesva

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.

 

 

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

Post to forums  

Autodesk Design & Make Report

”Boost