Revision control app macro (release)
Posted: Wed Mar 23, 2022 8:53 am
Hi,
Like many of you, I use SOLIDWORKS at home for my personal projects. Since I don't have PDM, and 3DEXPERIENCE is still a mess, I decided to throw together a very simple revision control app (macro). Took me a grand total of 2 days. Since it seems to be working fine, I thought I'd share it with you. Feel free to modify it as per your needs.
Purpose:
This app is intended for a simple version control of parts, assemblies and drawings. It allows you to create multiple revisions of your document, easily switch between these revisions, and lock a particular revision from any further changes by setting it to Released once it is ready for exporting/printing/manufacturing. This app achieves it by saving versioned copies of your document to a repository which is located in the hard drive in a directory of your choosing, and storing revision data in document's Custom Properties.
Benefits:
-No more file mess when trying to version them (myPart, myPartV2, myPartV2_1, myPartV2_1_final, myPartV2_1_final_alternate...)
-Clear and intuitive way to bookmark your current design before making major changes;
-Replace one version of document with another without breaking references in assemblies and drawings;
-No more accidental overwriting of your files - every copy is safe in the repository for retrieval when you need it.
How it works:
1. App creates and uses three Custom Properties - ID, State and Revision:
ID is the unique identifier for the document, generated from a random number. All revisions of the document will retain the same ID. It is used to prevent file name collisions in the repository by appending that ID to the file name when saving it in the repository. This might be important if you have two files from two different projects that have the same name.
State is the working state of the current revision. There are two right now - "In work" and "Released". "In work" means that the current revision is open to make any changes. "Released" means that the document is now read-only and cannot be modified anymore.
Revision is the version of the document. By default, all new parts are assigned A.1 revision. When new revisions are created, they can be incremented in the major part (B.1, C.1, etc.), or the minor part (A.2, A.3, etc.).
2. The document you are working with is always the main source of truth, so your normal SOLIDWORKS workflow stays the same. When you save the document, it is only saved to your project folder. If you decide to release the current revision, create a new revision, or revert to a previous revision, a copy of your current document is made inside the repository, but all the references still point to the original document. File name of this copy is made from the ID, Revision and the original document name (for example, 51668462_A.1_MyPart.SLDPRT). But you don't have to worry about this - the file you are working with will retain the name you created.
3. If you decide to revert to an earlier revision, your current document is then replaced from the repository. File name and location remains the same (MyPart.SLDPRT), and references in open documents are automatically updated. Meaning that if you revert from revision B.1 to A.1 in a part, and then switch back to an assembly or drawing, it will display the A.1 revision. For all intents and purposes, you can think of this as replacing the contents of your document.
User interface
Very simple
How to use it:
Set up: open the app macro (SOLIDWORKS -> Macro Toolbar -> Edit Macro), and at the top of the code, specify the path to where you want to keep your repository. By default it is "C:\Repo". Save the macro. I recommend assigning it to a button on the Taskbar, or a keyboard shortcut.
1. Create a new document and save it on your hard drive, or open an existing document.
2. Launch the app like any other macro. If you are using it for the first time on that document, it will generate appropriate Custom Properties, create revision A.1, and set it's state to "In work". If you have used this document with this app before, it will read it's Custom Properties, display the current Revision and State, as well as read the repository, find other revisions of this document (by it's ID), and display them in the drop-down list.
3. Do some awesome modelling. App does not have to be open - you can close it and re-open at any time.
4. When you are satisfied, click "Release revision". Your document will be set to Read-Only, and a copy of it will be saved to the repository. This Read-Only lock is meant to prevent accidental changes to a revision that is already confirmed, but it can be disabled in the macro code (not recommended).
5. If you need to make further changes after the revision has been released, you need to create a new revision. Choose whether the new revision should increment from the current one by the major or minor part (from A.1 to B.1 or to A.2), and click New Revision. The old revision will be saved to the repository if it is not there already, and a new one will be created with the "In work" state.
You can also create a new revision without releasing a current one. Just click New Revision. The current revision will still be saved to the repository in the "In work" state, and a new revision will be created.
6. If you want to revert to a previous revision of your document, select the revision from the drop-down list, and click Restore Revision. Your current document will replaced in-place with the appropriate copy from the repository, and all references should be updated. If the revision you loaded is "In work", you can just continue working on it as usual. If you loaded a "Released" revision, you will be unable to make any changes to it. If you want to continue work from that version, click New Revision.
Please note that the document is only saved to repository when you click New Revision or Release Revision, or Restore Revision. There is no automatic saving of the document to the repository when you click Ctrl+S.
Pro tips:
-Since Revision and State are saved as Custom Properties in your document, you can use them in a drawing via Notes -> Link to Custom Property, or in BOMs.
-You can customize the name of the Custom Properties that this app creates, in case you are already using default names for something else. Check the constants at the top of the macro code.
-On Parts, can add a Boss Extrude/Cut feature of a Sketch Text that is linked to the "Revision" Custom Property, to have a physical watermark of the revision on one of the Part's faces. I use this a lot when prototyping 3D printed parts, to be able to track which printed part represents which revision. I am including a Library Feature of a Cut-Extrude with a sketch that is set up like this, with a text font and size that should print clearly enough on most 3D printers with any settings. Saved in SW 2021. Adjust as needed.
Limitations:
-I have only tested this with Bottom-Up strategy projects. I have no idea how well this revisioning system is adapted to Top-Down, as well as things like Save Bodies, Insert Part, Derived Part and so on. Versioning in such cases is very confusing.
-I am not yet 100% sure that all the references to the document will be retained when it is replaced with the copy from repository, since SOLIDWORKS documents also have their internal IDs. If you know how to use ModelDoc2.Extension.SaveAs3 API call to make a copy of the active document with the same internal ID, let me know.
-If repository is in the network directory, and shared between multiple users, there is no reservation lock check. Perhaps this could be implemented, turning this macro into a mini-PDM, but I don't think it's worth the effort right now.
Known bugs:
-Sometimes when launching this app, it throws "ActiveX component can't create object" error. It's rare, but still happens. No idea why, all references seem to be fine... If anyone knows, please do tell.
Disclaimer:
I have tested the app and it seems to be working fine, but I haven't checked all possible workflow combinations, so there might be some bugs. Consider this a Beta release, and make backups of your projects so you don't lose your work!
To-Do:
-Add revision comments;
-Add multiple repositories (repository per project);
-Add "preview revision" button to check a revision without replacing anything;
-Add optional automatic file saving to the repository when document is saved normally (CTRL+S);
-Add detection and disabling of the app if a repository document is opened directly (currently can cause file name corruptions if any buttons are pressed);
-Make app settings editable in the UI (settings persistence);
-Prevent repository copies from appearing in SOLIDWORKS Recent Files list;
-Implement ID checking of the repository files when creating new ID to prevent accidental random number collision (astronomically small chance, but still);
-Your suggestions...
Let me know what you think. Like I said, I threw it together in 2 days, so it might have bugs. If I find any and fix them, I will upload updated version here too. Feel free to share suggestions on how to improve it as well.
Waiting for comments
P.S. Before downloading, check posts below, I will post updated versions there. Not sure how long I can continue editing this original post and adding new files to it.
Like many of you, I use SOLIDWORKS at home for my personal projects. Since I don't have PDM, and 3DEXPERIENCE is still a mess, I decided to throw together a very simple revision control app (macro). Took me a grand total of 2 days. Since it seems to be working fine, I thought I'd share it with you. Feel free to modify it as per your needs.
Purpose:
This app is intended for a simple version control of parts, assemblies and drawings. It allows you to create multiple revisions of your document, easily switch between these revisions, and lock a particular revision from any further changes by setting it to Released once it is ready for exporting/printing/manufacturing. This app achieves it by saving versioned copies of your document to a repository which is located in the hard drive in a directory of your choosing, and storing revision data in document's Custom Properties.
Benefits:
-No more file mess when trying to version them (myPart, myPartV2, myPartV2_1, myPartV2_1_final, myPartV2_1_final_alternate...)
-Clear and intuitive way to bookmark your current design before making major changes;
-Replace one version of document with another without breaking references in assemblies and drawings;
-No more accidental overwriting of your files - every copy is safe in the repository for retrieval when you need it.
How it works:
1. App creates and uses three Custom Properties - ID, State and Revision:
ID is the unique identifier for the document, generated from a random number. All revisions of the document will retain the same ID. It is used to prevent file name collisions in the repository by appending that ID to the file name when saving it in the repository. This might be important if you have two files from two different projects that have the same name.
State is the working state of the current revision. There are two right now - "In work" and "Released". "In work" means that the current revision is open to make any changes. "Released" means that the document is now read-only and cannot be modified anymore.
Revision is the version of the document. By default, all new parts are assigned A.1 revision. When new revisions are created, they can be incremented in the major part (B.1, C.1, etc.), or the minor part (A.2, A.3, etc.).
2. The document you are working with is always the main source of truth, so your normal SOLIDWORKS workflow stays the same. When you save the document, it is only saved to your project folder. If you decide to release the current revision, create a new revision, or revert to a previous revision, a copy of your current document is made inside the repository, but all the references still point to the original document. File name of this copy is made from the ID, Revision and the original document name (for example, 51668462_A.1_MyPart.SLDPRT). But you don't have to worry about this - the file you are working with will retain the name you created.
3. If you decide to revert to an earlier revision, your current document is then replaced from the repository. File name and location remains the same (MyPart.SLDPRT), and references in open documents are automatically updated. Meaning that if you revert from revision B.1 to A.1 in a part, and then switch back to an assembly or drawing, it will display the A.1 revision. For all intents and purposes, you can think of this as replacing the contents of your document.
User interface
Very simple
How to use it:
Set up: open the app macro (SOLIDWORKS -> Macro Toolbar -> Edit Macro), and at the top of the code, specify the path to where you want to keep your repository. By default it is "C:\Repo". Save the macro. I recommend assigning it to a button on the Taskbar, or a keyboard shortcut.
1. Create a new document and save it on your hard drive, or open an existing document.
2. Launch the app like any other macro. If you are using it for the first time on that document, it will generate appropriate Custom Properties, create revision A.1, and set it's state to "In work". If you have used this document with this app before, it will read it's Custom Properties, display the current Revision and State, as well as read the repository, find other revisions of this document (by it's ID), and display them in the drop-down list.
3. Do some awesome modelling. App does not have to be open - you can close it and re-open at any time.
4. When you are satisfied, click "Release revision". Your document will be set to Read-Only, and a copy of it will be saved to the repository. This Read-Only lock is meant to prevent accidental changes to a revision that is already confirmed, but it can be disabled in the macro code (not recommended).
5. If you need to make further changes after the revision has been released, you need to create a new revision. Choose whether the new revision should increment from the current one by the major or minor part (from A.1 to B.1 or to A.2), and click New Revision. The old revision will be saved to the repository if it is not there already, and a new one will be created with the "In work" state.
You can also create a new revision without releasing a current one. Just click New Revision. The current revision will still be saved to the repository in the "In work" state, and a new revision will be created.
6. If you want to revert to a previous revision of your document, select the revision from the drop-down list, and click Restore Revision. Your current document will replaced in-place with the appropriate copy from the repository, and all references should be updated. If the revision you loaded is "In work", you can just continue working on it as usual. If you loaded a "Released" revision, you will be unable to make any changes to it. If you want to continue work from that version, click New Revision.
Please note that the document is only saved to repository when you click New Revision or Release Revision, or Restore Revision. There is no automatic saving of the document to the repository when you click Ctrl+S.
Pro tips:
-Since Revision and State are saved as Custom Properties in your document, you can use them in a drawing via Notes -> Link to Custom Property, or in BOMs.
-You can customize the name of the Custom Properties that this app creates, in case you are already using default names for something else. Check the constants at the top of the macro code.
-On Parts, can add a Boss Extrude/Cut feature of a Sketch Text that is linked to the "Revision" Custom Property, to have a physical watermark of the revision on one of the Part's faces. I use this a lot when prototyping 3D printed parts, to be able to track which printed part represents which revision. I am including a Library Feature of a Cut-Extrude with a sketch that is set up like this, with a text font and size that should print clearly enough on most 3D printers with any settings. Saved in SW 2021. Adjust as needed.
Limitations:
-I have only tested this with Bottom-Up strategy projects. I have no idea how well this revisioning system is adapted to Top-Down, as well as things like Save Bodies, Insert Part, Derived Part and so on. Versioning in such cases is very confusing.
-I am not yet 100% sure that all the references to the document will be retained when it is replaced with the copy from repository, since SOLIDWORKS documents also have their internal IDs. If you know how to use ModelDoc2.Extension.SaveAs3 API call to make a copy of the active document with the same internal ID, let me know.
-If repository is in the network directory, and shared between multiple users, there is no reservation lock check. Perhaps this could be implemented, turning this macro into a mini-PDM, but I don't think it's worth the effort right now.
Known bugs:
-Sometimes when launching this app, it throws "ActiveX component can't create object" error. It's rare, but still happens. No idea why, all references seem to be fine... If anyone knows, please do tell.
Disclaimer:
I have tested the app and it seems to be working fine, but I haven't checked all possible workflow combinations, so there might be some bugs. Consider this a Beta release, and make backups of your projects so you don't lose your work!
To-Do:
-Add revision comments;
-Add multiple repositories (repository per project);
-Add "preview revision" button to check a revision without replacing anything;
-Add optional automatic file saving to the repository when document is saved normally (CTRL+S);
-Add detection and disabling of the app if a repository document is opened directly (currently can cause file name corruptions if any buttons are pressed);
-Make app settings editable in the UI (settings persistence);
-Prevent repository copies from appearing in SOLIDWORKS Recent Files list;
-Implement ID checking of the repository files when creating new ID to prevent accidental random number collision (astronomically small chance, but still);
-Your suggestions...
Let me know what you think. Like I said, I threw it together in 2 days, so it might have bugs. If I find any and fix them, I will upload updated version here too. Feel free to share suggestions on how to improve it as well.
Waiting for comments
P.S. Before downloading, check posts below, I will post updated versions there. Not sure how long I can continue editing this original post and adding new files to it.