Move older Drawing Revisions from one folder to another

Hi

Can anyone help me with my script please? See attached.

I am trying to move (or archive) older drawing revisions from one folder to another. The first revision of a drawing would be P01 then the next revision would be P02, P03, etc…

So if my drawing revision was at P03 I want to move the P02 & P01 versions of that drawing to another folder.

Our typical drawing file name consist of the following:

0971-XXX-00-XX-GF-DR-S-1000-P01

My script brakes down the drawing file name to keep the last 2 items which are the drawing Number and Revision as shown below:

1000-P01

Now I am stuck and I don’t know how to get my script to filter out the older drawing revisions and move those files to another folder.

Can anyone help me with this and advise if there is an easier way to do this please?

Thank you

Archive Files.dyn (32.2 KB)

the key is how to filter, first sort them by name to get the last revision at last, then use GroupByKey node, and the 1000-p01 values as a keys, now you will have each revision in group, use LastItem node to get the last revision, the other revisions flatten them and it will be in one list , and manage to save each group to a place

1 Like

@Kieran_Atherton, I would do it slightly differently which i have uploaded a copy onto my github or attached below.

I would grab the file name then remove the revision, then group what is left. Once things are grouped you would grab the last item in each group and split the original paths by this list to get only the ones that need to be moved.

Archive Old Versions.dyn (42.6 KB)

Click the raw button then click save as but make sure you remove “.txt” from the end to leave “.dyn” at the end.

Thanks for your advice guys.

Brendan, I’ve tested your script, however, it doesn’t seem to move the older revision files to my selected archive folder but it doesn’t give me any error warnings? Not sure what I am doing wrong

It will move them to a subfolder of its original folder that is called archive or what ever you call it.

Did you change the string separator because i had used “_” but yours could be a “-”.

Sorry i forgot to explain that you would need to change the separator character and the archive folder name.

Morning Brendan, I changed the separator but your move files phython node flags up a warning:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 14, in
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\shutil.py”, line 316, in move
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\shutil.py”, line 144, in copy2
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\shutil.py”, line 97, in copyfile

Any ideas ?

@Kieran_Atherton, I think this might be to do with how dynamo now loads python modules since Dynamo 2.1. This is because you do not have to append the iron python module folder from this version on wards.

Eg line 7 in this example:
image

Try this version which i have removed all of the ironpyton lib folder appends from any python nodes.

Archive Old Versions(dynamo 2_1 or above).dyn (42.4 KB)

Brendan,

I still seem to be getting the same python error:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 13, in
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\shutil.py”, line 316, in move
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\shutil.py”, line 144, in copy2
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\shutil.py”, line 97, in copyfile
IOError: [Errno 2] Could not find a part of the path ‘C:\Dynamo Shared\Archive\0931-SWA-00-B2-DR-S-1001-P01.pdf’.: C:\Dynamo Shared\Archive\0931-SWA-00-B2-DR-S-1001-P01.pdf

Would it be better if I run the script through the latest sandbox?

Also, this is the test folder with the files I am trying to archive in the image below:

Worth a try but the box in the dynamo script with the text “Archived”, create a sub folder called “Archived” in that folder then run it.

Apologies Brendan, I must of missed that part. The script is brilliant !

Thanks alot mate !

I’m going to see if I can get this to work with windows task sheduler to clean up mulitple projects.

Cheers

Kieran

@Kieran_Atherton No worries, i did assumed it would make the folder if it did not exist.

Therefore i have just updated the last python node to include a way to create the folder if it does not exist.

Hopefully you agree this is a better way to do what you was after than the original way, sorry it is python heavy but i find some things easier in python. Do ask if you want to understand certain parts.

Archive Old Versions(dynamo 2_1 or above).dyn (42.6 KB)

Thanks Brendan, I understand what each of your nodes are doing but the problem I have is knowing how to put them all together to make a script run correctly. But, i suppose that boils down to experience.

Do you have any tutorial or training recomendations ?

Cheers

Kieran