Replace all instances of a file on a network drive with new version

Use this space to ask how to do whatever you're trying to use SolidWorks to do.
Jacomuller
Posts: 24
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 0
x 18
x 2

Replace all instances of a file on a network drive with new version

Unread post by Jacomuller »

We have a small engineering department using Solidworks and PDM. The factory is in a separate building and does not have access to the PDM. We have a folder system on the network with folders for each product. We then have a subfolder for DXF files and a subfolder for PDF drawings.

I have created a macro that will create a DXF file of a Solidworks sheet metal part in the PDM. It will then create a copy in the correct folder in the Factory. It will also delete older versions of the DXF file as well as deleting the Laser Cut file for that part.

That bit works really well. The issue is that the same part can be used in different products. So I want to delete the old version of the DXF file and laser cut file in all sub folders on the network drive. I then want to copy the new version of the DXF file to all those subfolders where the old dxf was deleted.

Any ideas to do that fast? I am sure i can work it out but it will be slow in stepping through each folder. :D
by JSculley » Wed Nov 08, 2023 2:37 pm
Jacomuller wrote: Wed Nov 08, 2023 1:01 am Any ideas to do that fast? I am sure i can work it out but it will be slow in stepping through each folder. :D
Why do you believe it will be slow? Have you tested? With a C# macro I can retrieve and store the name of every file on my desktop and all subdirectories (5328 files in 739 directories) in 0.1 seconds.
Go to full post
User avatar
bnemec
Posts: 1851
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2436
x 1330

Re: Replace all instances of a file on a network drive with new version

Unread post by bnemec »

Jacomuller wrote: Wed Nov 08, 2023 1:01 am We have a small engineering department using Solidworks and PDM. The factory is in a separate building and does not have access to the PDM. We have a folder system on the network with folders for each product. We then have a subfolder for DXF files and a subfolder for PDF drawings.

I have created a macro that will create a DXF file of a Solidworks sheet metal part in the PDM. It will then create a copy in the correct folder in the Factory. It will also delete older versions of the DXF file as well as deleting the Laser Cut file for that part.

That bit works really well. The issue is that the same part can be used in different products. So I want to delete the old version of the DXF file and laser cut file in all sub folders on the network drive. I then want to copy the new version of the DXF file to all those subfolders where the old dxf was deleted.

Any ideas to do that fast? I am sure i can work it out but it will be slow in stepping through each folder. :D
It sounds like you have the folder structure set up by project, product or order and put copies of the common components in the project/product folder?
User avatar
JSculley
Posts: 575
Joined: Tue May 04, 2021 7:28 am
Answers: 53
x 7
x 808

Re: Replace all instances of a file on a network drive with new version

Unread post by JSculley »

Jacomuller wrote: Wed Nov 08, 2023 1:01 am Any ideas to do that fast? I am sure i can work it out but it will be slow in stepping through each folder. :D
Why do you believe it will be slow? Have you tested? With a C# macro I can retrieve and store the name of every file on my desktop and all subdirectories (5328 files in 739 directories) in 0.1 seconds.
Jacomuller
Posts: 24
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 0
x 18
x 2

Re: Replace all instances of a file on a network drive with new version

Unread post by Jacomuller »

@bnemec Thanks for the reply. We have our product specific components and then we have generic parts. The generic part numbers start with 000- , so it is easy to separate. The issue is with parts that are not generic, but is used in two or three (max 6) other products. We have about 800 products with about 25 parts in each. These parts are not generic and are normally just shared in products for a specific vehicle. E.g we make 3 different towbars for a Ford F150, the chassis mounting plates will be the same in all 3.

@JSculley Thanks for the feedback. I haven't tested it yet, I was just feeling it will be slow and I though there will be a better way to do it. I use VBA, so it maybe a bit slower, but I will start playing around with it. The dxf file names will be in the following format "793-03-00 (12mm) 2Per.DXF" where the red "00" indicate the revision number. To delete the old files, I use the following "793-03-*.DXF" as well as "793-03-*.dft" for the laser cut file. The new DXF file then needs to be copied only in the folders where an old dxf file was found.
User avatar
bnemec
Posts: 1851
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2436
x 1330

Re: Replace all instances of a file on a network drive with new version

Unread post by bnemec »

I see, that makes sense, kind of. I'm used to the entire data set being standard parts library so no limit of 6 where used before becoming a generic part.

What Jim says is your best bet, get a little practice with C# and file operations will become very simple. Can also be one in command script too, I guess whatever you're more comfortable with. I'm familiar enough with VBA to know that I like C# better. The .NET framework has some handy classes for working with files and directories and paths. If there's no good way to know where copies of the old files might be, a recursive directory search for a file name is pretty quick. Use command arguments for the file to update and the new rev to go to so your .exe can be called from other tool (such as PDM transition action) if that helps. That way your PDM task only generates the dxf, then after the task completes the copy action can call your stand alone tool to cascade it out.

Just some thoughts.
User avatar
SPerman
Posts: 1834
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 13
x 2014
x 1688
Contact:

Re: Replace all instances of a file on a network drive with new version

Unread post by SPerman »

For extra credit, you could dump the file name and path to a text file to know what files/locations were modified.

Personally, I start twitching when I think about the same information being available in multiple locations, and worrying about keeping them all in sync. But I recognize the reason behind doing that. (Teamcenter handles this much better, but it is waaay out of my budget.)
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
Jacomuller
Posts: 24
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 0
x 18
x 2

Re: Replace all instances of a file on a network drive with new version

Unread post by Jacomuller »

I have done the "loop through all folders and subfolder" thing and it works - it is a bit slow, but will do for now - a lot faster than manual and no errors :D . There are about 3500 folders and 9000 files to check and it is done in about 5 sec. So it is all good.
User avatar
bnemec
Posts: 1851
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2436
x 1330

Re: Replace all instances of a file on a network drive with new version

Unread post by bnemec »

SPerman wrote: Wed Nov 08, 2023 6:06 pm For extra credit, you could dump the file name and path to a text file to know what files/locations were modified.

Personally, I start twitching when I think about the same information being available in multiple locations, and worrying about keeping them all in sync. But I recognize the reason behind doing that. (Teamcenter handles this much better, but it is waaay out of my budget.)
Text files are easy to dump data to, but not as slick for reading/finding data back. I've gone mostly to logging to database if it's long term.

I feel the same about redundant data, I was on the fence about suggesting links back to the original. Then leave the rev off the file name (and link name) for the current rev so no updating required. But that seemed a long way off what JacoMuller was looking for.
Post Reply