Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modifying Multiple Drawings via VBA

Status
Not open for further replies.

BML

Industrial
Jun 22, 1999
104
I'm trying to write some code that will make certain modifications to a set of drawings. One of the first tasks is to get the list of all layers on the active drawing, then cycle through each using a for-next loop to modify those layers (turn off, rename, etc.). This works okay for the first drawing I process. I then continue on with some other changes, save and close the active drawing. Then when I switch to the next drawing and make it active, I try to read in the new layer names and run the for-next loop again. On the second pass through I get a fatal error unhandled access violation exception. I thought it might have been caused by using the same variable to represent the current and set of all layers, but indexing the variables did not help. Any thoughts?

Thanks!
 
Replies continue below

Recommended for you

Make sure your variables are not globals. Local variables will get set to nothing when the function or sub is done running. Like you said, you may have assigned a object to a variable that loses its reference when you close the file and start on the next one.

"Whether you think that you can, or that you can't, you are usually right "
.. Henry Ford
 
I don't have any global declarations in this file. I know that I can read what the current document is, as I put in some message boxes and stepped through the code. I can cycle to the beginning of the 2nd For-Next loop, activate the next drawing, count the number of total drawings open, and display a message box that shows these values. But when I start the For-Next loop to go through the layers, it always hangs up.

Thanks!
 
Not seeing the code, I will try a few tips:
-Purge the drawing before processing it.
-Make sure layers are not locked or frozen (something that might make it trip)
-Set the variable that seems to catch on to nothing before exiting the routine
-Make sure the layer is not an xref layer

A beginning place..

"Whether you think that you can, or that you can't, you are usually right "
.. Henry Ford
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor