Set Revision through API

Programming and macros
Emra
Posts: 6
Joined: Tue Aug 03, 2021 11:11 pm
Answers: 0
x 3
x 6

Set Revision through API

Unread post by Emra »

Hello,

I have an API that is supposed to be setting the PDM vault revision counter, and runs without error, but does not actually write the new revision value.

Background: I'm trying to set revisions for a vault of legacy data where the rev is stored in the custom properties via external PDM and PLM systems, but the actual vault PDM rev isn't set.

Code details: I'm pulling the correct legacy revision from the custom properties via Document Manager API (plus some additional user input when there are 2+ unique revs saved on the same file :roll: ), and reading the information for the revision counter name and value through the PDM API. A lot of the code in question is borrowed heavily from the "Set Initial Revision" Help example:http://help.solidworks.com/2020/english ... _VBNET.htm.

This seems to be the problem area:

Code: Select all

If Not currentRev = newRev Then
            MsgBox("The PDM Revision, ( " & currentRev & " ), will be set to the file property revision, ( " & newRev & " ).")
            Dim RevCounters(0) As EdmRevCounter            'Assign the name of the revision counter  
            RevCounters(0).mbsComponentName = revVarName
            Dim RevInt As Long
            RevInt = Asc(newRev.ToUpper()) - Asc("A") + 1 ' Assign the New revision counter value to the value stored in the Revision card variable converted to an integer
            RevCounters(0).mlCounter = RevInt
            RevMgr.IncrementRevision(pdmFile.ID)
            Debug.Print("After incrementing, currentRev is  :" & pdmFile.CurrentRevision)
            RevMgr.SetRevisionCounters(pdmFile.ID, RevCounters)             'Set the revision counter to the new values
            Debug.Print("RevCounter value is  " & RevCounters(0).mlCounter)
            Debug.Print("Rev alpha value will be " & Chr(RevCounters(0).mlCounter))
            Dim RevErrors() As EdmRevError = {}
            RevMgr.Commit("Set starting revision for legacy file.", RevErrors) 'Save the new values to the database
            Debug.Print("After committing, currentRev is  :" & pdmFile.CurrentRevision)
        Else
            MsgBox("The PDM revision (" & currentRev & " ) already matches the cprop rev ( " & newRev & " )!")
            Exit Sub
        End If
I'm running out of troubleshooting ideas - there are debug statements every other line, and everything works perfectly right up to the set of write statements (RevMgr.IncrementRevision, RevMgr.SetRevisionCounters, RevMgr.Commit). There's no error or exception; the PDM revision just won't write. o[

Any ideas what I'm doing wrong?
by bnemec » Mon Oct 04, 2021 5:11 pm
Emra wrote: Mon Oct 04, 2021 3:46 pm Hello,

I have an API that is supposed to be setting the PDM vault revision counter, and runs without error, but does not actually write the new revision value.

Background: I'm trying to set revisions for a vault of legacy data where the rev is stored in the custom properties via external PDM and PLM systems, but the actual vault PDM rev isn't set.

Code details: I'm pulling the correct legacy revision from the custom properties via Document Manager API (plus some additional user input when there are 2+ unique revs saved on the same file :roll: ), and reading the information for the revision counter name and value through the PDM API. A lot of the code in question is borrowed heavily from the "Set Initial Revision" Help example:http://help.solidworks.com/2020/english ... _VBNET.htm.

This seems to be the problem area:

Code: Select all

If Not currentRev = newRev Then
            MsgBox("The PDM Revision, ( " & currentRev & " ), will be set to the file property revision, ( " & newRev & " ).")
            Dim RevCounters(0) As EdmRevCounter            'Assign the name of the revision counter  
            RevCounters(0).mbsComponentName = revVarName
            Dim RevInt As Long
            RevInt = Asc(newRev.ToUpper()) - Asc("A") + 1 ' Assign the New revision counter value to the value stored in the Revision card variable converted to an integer
            RevCounters(0).mlCounter = RevInt
            RevMgr.IncrementRevision(pdmFile.ID)
            Debug.Print("After incrementing, currentRev is  :" & pdmFile.CurrentRevision)
            RevMgr.SetRevisionCounters(pdmFile.ID, RevCounters)             'Set the revision counter to the new values
            Debug.Print("RevCounter value is  " & RevCounters(0).mlCounter)
            Debug.Print("Rev alpha value will be " & Chr(RevCounters(0).mlCounter))
            Dim RevErrors() As EdmRevError = {}
            RevMgr.Commit("Set starting revision for legacy file.", RevErrors) 'Save the new values to the database
            Debug.Print("After committing, currentRev is  :" & pdmFile.CurrentRevision)
        Else
            MsgBox("The PDM revision (" & currentRev & " ) already matches the cprop rev ( " & newRev & " )!")
            Exit Sub
        End If
I'm running out of troubleshooting ideas - there are debug statements every other line, and everything works perfectly right up to the set of write statements (RevMgr.IncrementRevision, RevMgr.SetRevisionCounters, RevMgr.Commit). There's no error or exception; the PDM revision just won't write. o[

Any ideas what I'm doing wrong?
A couple things if you don't mind a little "spit-balling":
- What is revVarName? If I understand correctly this needs to be "Name of revision number component as specified in the administration tool." According to https://help.solidworks.com/2019/englis ... tName.html
Do you have more than one rev counter set up in the Admin Tool? I'm assuming you are setting that in code before your what you pasted here, but just double checking.

- Is RevErrors empty after calling Commit? You said no errors so I assume so, but thought maybe worth a double check.
https://help.solidworks.com/2019/englis ... tring.html

- In the help example they call IncrementRevision after calling SetRevisionCounters which your code does it the other way around. I wasn't going to mention it because the remarks for both help pages say it doesn't matter which one is called first. But I've been "out of troubleshooting ideas" before and will try about anything at that point.
Go to full post
User avatar
bnemec
Posts: 1869
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2466
x 1344

Re: Set Revision through API

Unread post by bnemec »

Emra wrote: Mon Oct 04, 2021 3:46 pm Hello,

I have an API that is supposed to be setting the PDM vault revision counter, and runs without error, but does not actually write the new revision value.

Background: I'm trying to set revisions for a vault of legacy data where the rev is stored in the custom properties via external PDM and PLM systems, but the actual vault PDM rev isn't set.

Code details: I'm pulling the correct legacy revision from the custom properties via Document Manager API (plus some additional user input when there are 2+ unique revs saved on the same file :roll: ), and reading the information for the revision counter name and value through the PDM API. A lot of the code in question is borrowed heavily from the "Set Initial Revision" Help example:http://help.solidworks.com/2020/english ... _VBNET.htm.

This seems to be the problem area:

Code: Select all

If Not currentRev = newRev Then
            MsgBox("The PDM Revision, ( " & currentRev & " ), will be set to the file property revision, ( " & newRev & " ).")
            Dim RevCounters(0) As EdmRevCounter            'Assign the name of the revision counter  
            RevCounters(0).mbsComponentName = revVarName
            Dim RevInt As Long
            RevInt = Asc(newRev.ToUpper()) - Asc("A") + 1 ' Assign the New revision counter value to the value stored in the Revision card variable converted to an integer
            RevCounters(0).mlCounter = RevInt
            RevMgr.IncrementRevision(pdmFile.ID)
            Debug.Print("After incrementing, currentRev is  :" & pdmFile.CurrentRevision)
            RevMgr.SetRevisionCounters(pdmFile.ID, RevCounters)             'Set the revision counter to the new values
            Debug.Print("RevCounter value is  " & RevCounters(0).mlCounter)
            Debug.Print("Rev alpha value will be " & Chr(RevCounters(0).mlCounter))
            Dim RevErrors() As EdmRevError = {}
            RevMgr.Commit("Set starting revision for legacy file.", RevErrors) 'Save the new values to the database
            Debug.Print("After committing, currentRev is  :" & pdmFile.CurrentRevision)
        Else
            MsgBox("The PDM revision (" & currentRev & " ) already matches the cprop rev ( " & newRev & " )!")
            Exit Sub
        End If
I'm running out of troubleshooting ideas - there are debug statements every other line, and everything works perfectly right up to the set of write statements (RevMgr.IncrementRevision, RevMgr.SetRevisionCounters, RevMgr.Commit). There's no error or exception; the PDM revision just won't write. o[

Any ideas what I'm doing wrong?
A couple things if you don't mind a little "spit-balling":
- What is revVarName? If I understand correctly this needs to be "Name of revision number component as specified in the administration tool." According to https://help.solidworks.com/2019/englis ... tName.html
Do you have more than one rev counter set up in the Admin Tool? I'm assuming you are setting that in code before your what you pasted here, but just double checking.

- Is RevErrors empty after calling Commit? You said no errors so I assume so, but thought maybe worth a double check.
https://help.solidworks.com/2019/englis ... tring.html

- In the help example they call IncrementRevision after calling SetRevisionCounters which your code does it the other way around. I wasn't going to mention it because the remarks for both help pages say it doesn't matter which one is called first. But I've been "out of troubleshooting ideas" before and will try about anything at that point.
Emra
Posts: 6
Joined: Tue Aug 03, 2021 11:11 pm
Answers: 0
x 3
x 6

Re: Set Revision through API

Unread post by Emra »

A couple things if you don't mind a little "spit-balling":
- What is revVarName? If I understand correctly this needs to be "Name of revision number component as specified in the administration tool." According to https://help.solidworks.com/2019/englis ... tName.html
Do you have more than one rev counter set up in the Admin Tool? I'm assuming you are setting that in code before your what you pasted here, but just double checking.
That was it! I had defined it as the name of the revision variable instead of the revision number component - there are way, way too many "revisions" in our system at the moment, and I lost track.

Thanks so much!
Post Reply