Visual Basic Customization

Reply
Contributor
mendesva
Posts: 19
Registered: ‎04-10-2009
Message 1 of 5 (1,379 Views)

ThisDrawing.Application.Documents.Open

1379 Views, 4 Replies
06-11-2010 12:47 AM

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.

 

Contributor
vinayan
Posts: 13
Registered: ‎05-17-2009
Message 2 of 5 (1,296 Views)

Re: ThisDrawing.Application.Documents.Open

07-16-2010 11:32 PM 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

Member
KillerMungkay
Posts: 5
Registered: ‎11-07-2010
Message 3 of 5 (1,131 Views)

Re: ThisDrawing.Application.Documents.Open

11-07-2010 04:03 PM 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

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 5 (1,111 Views)

Re: ThisDrawing.Application.Documents.Open

11-10-2010 12:41 AM 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
Active Contributor
sardeson
Posts: 40
Registered: ‎10-20-2002
Message 5 of 5 (1,091 Views)

Re: ThisDrawing.Application.Documents.Open

11-11-2010 11:03 AM 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.

 

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community