Revision control app macro (release)

It sounds like you opened both the old and the new version at the same time, but when you run it from the editor, you activate the wrong version. I don’t think it should overwrite anything. If you can still open the correct version from SW, it means that file is still intact. Check what file is the macro button pointing to:
image.png
And make sure you backup that one.

As for the editor, try to close it, maybe restart SW - that should get rid of the two instances of the macro in the editor.

I restarted everything but it seems to be lost for good :unamused:
I retrieved a version with Windows’ version history but either it never cached the one I modified or, since we use OneDrive, it’s messed up by Windows.
I’ll send a copy home next time!

We need a way to implement changes without having to load two macros in SW Macro Editor.

What version of Solidworks are you all running? I’m on 2023 SP5.0 currently. I just downloaded V4 and went to run it and it acts like it is thinking for a minute but then nothing happens, no window appears, errors or anything. I also can’t find a string in this code to change the Repository file path.

I was running V2 and used it all the time. Then I transfered all my files into one drive to keep them backed up, they are all still saved locally. I fixed the file path but it has not worked propperly since. It will show the past revisions and can preview and restore them but when I go to create a new revison it will not increment and sometimes will even back up the number instead. I’d be glad to update but like I said I cant gt it to run.

Unfortunaly I know just enough about coding to do very basic stuff with the help of Chat GPT so I’m at a loss where to look to solve the issues. I have really liked using this macro. It is some really awesome work but as much as I like it I may have to purchase a PDM license to keep moving.

Thanks

Hey, I am using 2024 SP3.1. I haven’t used this macro much after the last release, maybe I missed some bugs. Does this happen with new parts as well? If you can work out the steps how to reproduce this issue from scratch, I can probably fix it. Let me know.

I did reread the information on V3 and got V4 to run that way (I think I have been running the wrong entry point) but whenever I hit new branch or new version I get an error “Subscript out of range”. On a new file it is able to put in the base information needed but still throws the same error. On this test I did have the repository routed to a folder that backs up to One drive

I just tried it again with the default repo location which would not be backed up by one drive and it seems to work, though it did hit a stopping point at Branch C till I released a few versions. I may be able to work with this but somehow I need to find a way to back up repo files.

Our IT guy just told me about Symbolic linked folders. I may look into this to make it appear to the macro that One drive doesn’t exists but it would still backup files to that location.

As far as V2 goes the problem happens with any file, new or old I may try the above idea with it as well. It seem to be with the incrementation though. It can view/restore other files in the repository but it can’t increment and thus create a new file.

Hi,
I used the macro quite a lot here it was great and, with a few changes to follow our revision scheme, it was perfect.
I say “was” because since yesterday several files won’t work.
Symptoms:
-When increasing the branch or the revision I may get the error message “Subscript out of range”
-In the “available versions” drop-down, there’s no version available, when there are several in the repository.
If I edit the macro and step in the problem is there:
22024-11-05 09_48_36.png
I join my version of the macro. I think I only made changes to the interface language and file properties names.
VC V4.swp (306 KB)

I think it is failing because there is only 1 instance of “_” in the FileName string, and you are looking for the 2nd one.

The file I’m using right now that I’m testing on has these in the “Repo” folder:
66233193_A.1_231130-312.SLDPRT
66233193_A.2_231130-312.SLDPRT
66233193_A.2_231130-312.SLDPRT
66233193_A.4_231130-312.SLDPRT
66233193_A.5_231130-312.SLDPRT

NM. I found the additional modules.

In the quick little bit of testing I did, I only got the “subscript out of range” error if there was no “_” in the filename.

Frustrating… it worked well for months and now this.
The only thing that happened is that I showed how to use it to a co-worker. It did not work on his computer, but I’ll debug that after, if I manage to get it working again on mine.

Hi guys, sorry for my absence, for some reason I was not getting notifications, and now like 5 of them arrived at once :open_mouth: I am looking into this issue as we speak. If there is no NDA or anything, could you please share at least one file (and it’s revision history files) that shows the “subscript out of range” error, or missing revisions in the list? I can’t seem to replicate either of these issues. If I had some samples, I could finally nail this down.

P.S. I think the issue was the revision sorting algorithm, I rewrote it, but I still want to test it with some of problematic files to ensure I didn’t miss something.

I think the root problem will be that the filename doesn’t have an underscore. Figuring out where, in all of that code, the filename is selected and fed to the function is a different question.

Here’s a file and it’s versions from the Repo folder. I don’t know why there’s no “A.1” version. To be sure it was not a cause to the problem I duplicated A.2 and renamed to A.1 but it changes nothing.
When I run the macro on this file, “Phases” and “Revision” change results in the “subscript out of range” error. The drop-down shows nothing.
231130-416.zip (1.02 MB)

Thank you! I think the issue was indeed the sorting algorithm that I changed from v3 to v4 (if I remember right). I tested your files with updated version, and it seems to work correctly now, but please check yourself to make sure. Attaching the v5_beta. Changes I made, this is from my changelog in progress:

  • Rewrote the sorting algorithm, added a few helper functions to Utilities. Should fix the “subscript out of range” issue.


  • The application will no longer automatically lock Released documents (make them read-only, lock external references and enable freeze bar), but will prompt the user by default. If you prefer to always lock these references (old behavior), or to never lock, edit the value of Constants.LOCK_RELEASED_DOCS_OPTION. As a result of this change, SET_RELEASED_VERSIONS_FREEZEBAR and SET_RELEASED_VERSIONS_LOCK_REFS have been deprecated.


  • Additional Actions → “Delete version history” was renamed into “Set new tracking ID”, and the prompt rewritten to make it less confusing. The actual functionality did not change, but it should be clearer what this function does: it starts a new tracking history to the current document starting with revision A.1. Intended usage is when you save a tracked part with SOLIDWORKS Save As, and want to have a separate tracking history for this new file without deleting the old one.


  • Eliminated the confusing “the key is already associated with this collection” error. It happens when you save a tracked part with SOLIDWORKS Save As, but do not assign a new tracking number. The application will now recognize this, and warn the user.


  • Renamed some constants and functions.


  • Some refactoring.

Can you please check if everything is working now? Please don’t forget to change the Constants to your custom settings. If something is not working, please enable the Debug mode and make a screenshot or two.

EDIT: I see lots of people are downloading it already, so please tell me of any issues that you find. I would like this V5 to be the final version, free of any remaining bugs, because I got lots of other projects going on, and I don’t think I will have much time in the future to maintain this :unamused: Besides, it has already grown past what a macro is meant for, and should be better-off re-written as an add-in… Nevertheless, if anyone wants to take over the development afterwards, feel free. Macro is open source project by definition anyway :smiley:
Version control app V5_beta.swp (591 KB)

Thanks to you!
I’ll do extensive testing in the next couple of days and report.
Are you using only SolidWorks’ macro editor to edit your macros?

Thank you, I’ll be waiting :slight_smile: And yes, I am using SolidWorks macro editor. I thought there aren’t any other IDE options, or are there..?

Ok, I still get this “Subscript out of range” error.
Here’s a video:
sldrx.wmv (282 KB)
-Nothing happens if I just use “Tools->Macro->Run…” or use the button “Run Macro”. The MainForm shows up when I assign the macro to a button. Is it because there’s a field for the method (Core.main) that cannot be specified otherwise? I lost a lot of time trying to find why the macro would do nothing as I was testing with a “Run Macro” button.
-When I “Step into” and then F8 repeatedly, I get in a loop here:
2024-11-06 15_21_53-Microsoft Visual Basic for Applications - Version_control_app_V5 [break].png
2024-11-06 15_28_13-Microsoft Visual Basic for Applications - Version_control_app_V5 [break].png
-Where is defined the sentence “This will assign a new ID to the document xxxx.sldprt and reset version back to A.1. Versions associated with the old ID will remain in the repository. Are you sure to proceed?”

Sorry you lost a lot of time with this. We will find a way to fix this issue, I promise :slight_smile: Okay, reviewing your video, I strongly suspect that the issue is that you have some foreign files in your Repo directory with names that do not match the convention expected by the macro: [trackingId][Version][FileName.SLDPRT]. I will add a check function to disregard such files so they don’t cause this error. But just to make sure that this is the case, can you please do the following:

  1. Edit the macro, and in Constants, change the line:
Public Const DEBUG_ENABLED As Boolean = False

To

Public Const DEBUG_ENABLED As Boolean = True
  1. Run the macro again from the Core.main method, and try to create a new version or anything else that causes the “Subscript out of range” error. The macro editor should pop up with an error box. Click “debug”.

  2. Macro editor should pop into the function IsCurrentDocumentAlreadyInRepoWithDifferentFilename. Hower your mouse over the “fileName” variable, and it should show you the value of that variable, like in this screenshot:
    image.png
    If it does not match the [trackingId][Version][FileName.SLDPRT] convention… Then it means this is indeed the issue. Like I said, I can easily fix this, but I want to be 100% sure that this is what is causing the error for you :slight_smile:

Yeah, Tools->Run does not allow you to choose which method to run the macro from… Sometimes the macro “loses” the reference to which method is the default (entry) one, and I honestly don’t know how to specify that. I can try to re-create the macro from scratch (copy over the code), maybe that will fix it. But for now, use a macro button, or run the macro from the macro editor by pressing F5 and then choosing the correct entry method (Core.main).

This is a loop that traverses through all of your files in the repo directory, you probably have quite a lot of them, that is why it appears to get stuck. You can add a breakpoint after the loop and press F5 to run the macro until that breakpoint, it will save you a lot of time.

This is from AdditionalActionsForm:
image.png
For future reference, since you’re making quite a few changes to this macro, you can find things easier if you do a global search with Ctrl+F and set the search scope to “Current project”:


Let me know the results of that first test. And thanks!

Well, thanks to you!!!
That’s certainly the problem, when I hover over “filename” it shows “231130-450.sldprt”. So it’s a file that was copied there without the macro.
I can enforce a “do not touch directly” policy to the Repo folder but I cannot guarantee it will be followed in the long term.

Edit: I cleaned-up the Repo folder and it works!!!

For the problem of the “Run macro”, don’t spend time on this. It’s a problem with SolidWorks’ implementation.

For editing the macro I copy the text into Notepad++. I can have 2 files side-by-side with synchronized scrolling. And it has VB code highlighting.

Thank you for confirming, I thought that was it :slight_smile: I added a check to disregard such files so you don’t have to enforce that policy, but I suspect there is still plenty of ways to break my macro, I didn’t include a lot of error checking because of how limited VBA is and how annoying it soon becomes to maintain a project of such complexity in that macro editor. I too sometimes use Notepad++ for refactoring, but still have to copy the code back over to the VBA editor afterwards… Visual Studio is such a relief to work in compared to this. Sad that we can’t use it for writing and debugging macros.

Anyway, I will test that macro further for a few more days, maybe do some clean up and further refactoring, and then I will post it here.