Close every open file during a macro

Hello

I downloaded a macro to export all a folder of plans, parts and assemblies but it doesn't close the files after export.

Thank you for your help.

 

Here's the macro


convertir_ficher_sw.swp

Hello

Do you have myCADtools by any chance?

Hello

I downloaded your macro and did a test with slddrw and sldprt, everything went well including the closure of each file. Is the problem permanent or only on certain files?

Kind regards

Hello Gentlemen,

Unfortunately I don't have mycadtools.

Here's my last modified macro with the right properties for the purposes of the filenames.

On the other hand, I am attaching some files under SW2017 because I still can't close the files automatically. (Drawings or parts)

Thank you again for your help.

Kind regards


import_3d.zip

Hello

I just took a look at your macro.

Replace:

Set Part = Nothing
swApp.CloseDoc ListAComvertir(i, 3) & ".sldprt"

By:

swApp.CloseDoc Part.GetPathName

Set Part=Nothing

PS: sometimes, going through a class avoids a lot of problems:)

3 Likes

Hello Yves.T,

Thank you for your advice, it closes the file well.

On the other hand, when I restart the macro on the same files I have an interrogation to each file to overwrite the existing export file and to save the open file.

Another small problem, is it possible to validate the message on the scale different from that of the sheet.

In fact my first macro worked very well, I just had the problem of a folder where there was too much drawing. Dond I was reaching the limit of the number of files open in solidworks.

Thank you again for your advice.

Kind regards

Hello

I took a few minutes to modify a tiny part of the code. You will find your modified macro attachments.

As for checking the existence of the output file, you have two solutions that amount to the same thing.

Either you test the error return value of the SaveAs function, you will delete the file and save it again

Either you go check in the folder before saving to see if there isn't already one and you delete it and then save.

In both cases, you need to use the filestream (fso) APIs to manage the files.


convertir_ficher_sw_-_09-10.rar
2 Likes

Hello Yves.T,

Thank you for your changes.

After several tries, I encountered the same problem.

A priori I don't have the problem anymore if I restart SW and if all the files are converted in 2017.

For now, I'm going to talk about your work.

Thank you for all.

Kind regards