Hi all,
I know this is an old thread. I came across it recently while looking for ways to burn scheme numbers as colleagues had deviated from our system, causing the Vault Numbering Scheme to be out of date. @JhoelForshav your code worked well in Inventor 2024 without much tweaking!
I've updated it to automatically get a list of the current Numbering Scheme names that Vault has, allowing the user to select one. They are then asked to specify the amount of numbers they want to burn. These 2 variables are fed into the rest of the code. At any point, if the user exits/cancels it should abort the code and no numbers will be consumed. I've tested this quickly and it seems to work well, so hopefully there aren't too many issues.
Again, thank you @JhoelForshav for doing the original work.
AddReference "Autodesk.Connectivity.WebServices"
AddReference "Autodesk.DataManagement.Client.Framework.Forms"
AddReference "Autodesk.DataManagement.Client.Framework.Vault"
AddReference "Autodesk.DataManagement.Client.Framework.Vault.Forms"
AddReference "Connectivity.InventorAddin.EdmAddin"
Imports ACW = Autodesk.Connectivity.WebServices
Imports VDF = Autodesk.DataManagement.Client.Framework
Imports Autodesk.DataManagement.Client.Framework.Vault.Services
Imports Autodesk.DataManagement.Client.Framework.Vault.Currency.Connections
Imports edm = Connectivity.InventorAddin.EdmAddin
Sub Main
'Fetch list of existing numbering schemes in vault for user to select
Dim Connection As VDF.Vault.Currency.Connections.Connection = edm.EdmSecurity.Instance.VaultConnection()
Dim genNum As String = String.Empty
Dim first As String
Dim last As String
If Not Connection Is Nothing Then
Dim entityClassId = VDF.Vault.Currency.Entities.EntityClassIds.Files
Dim numSchemes As ACW.NumSchm() = Connection.WebServiceManager.NumberingService.GetNumberingSchemes(entityClassId, Nothing) 'kanske inte nothing
'Create array list for selection
Dim oNumberingSchemeArrayList As New ArrayList
For Each numScheme In numSchemes
oNumberingSchemeArrayList.Add(numScheme.Name)
Next
'Sort Array List
oNumberingSchemeArrayList.Sort
'Form to select which numbering scheme is selected
oScheme = InputListBox("Select scheme to burn numbers. You can specify the amount of numbers in the next step.", oNumberingSchemeArrayList, "", iLogicVb.RuleName, "Available schemes:", 420)
If oScheme = ""
MessageBox.Show("Cancelled", iLogicVb.RuleName, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
oCount = InputBox("How many numbers do you need to burn from '" & oScheme.ToString & "'?", iLogicVb.RuleName)
If oCount = ""
MessageBox.Show("Cancelled", iLogicVb.RuleName, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
oConfirm = MessageBox.Show("Are you sure you want to burn " & oCount.ToString & " number(s) from " & oScheme.ToString & "?", iLogicVb.RuleName,MessageBoxButtons.YesNo,MessageBoxIcon.Warning)
If oConfirm = vbYes Then
'Selection to specify range or number count to generate
getFilenamesFromVaultNamingScheme(oScheme, "", oCount)
Else
MessageBox.Show("Cancelled", iLogicVb.RuleName, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
End If
End Sub
Public Sub getFilenamesFromVaultNamingScheme(RequiredSchemeName As String, RequiredSchemeString As String, numberOfNames As Integer)
Dim Connection As VDF.Vault.Currency.Connections.Connection = edm.EdmSecurity.Instance.VaultConnection()
Dim genNum As String = String.Empty
Dim first As String
Dim last As String
If Not Connection Is Nothing Then
Dim entityClassId = VDF.Vault.Currency.Entities.EntityClassIds.Files
Dim numSchemes As ACW.NumSchm() = Connection.WebServiceManager.NumberingService.GetNumberingSchemes(entityClassId, Nothing) 'kanske inte nothing
Dim requiredScheme As ACW.NumSchm = (From sch As ACW.NumSchm In numSchemes
Where sch.Name = RequiredSchemeName
Select sch).FirstOrDefault()
Dim numGenArgs() As String = {RequiredSchemeString }
For i = 1 To numberOfNames
genNum = Connection.WebServiceManager.DocumentService.GenerateFileNumber(requiredScheme.SchmID, numGenArgs)
If i = 1 Then first = genNum
If i = numberOfNames Then last = genNum
Next
MessageBox.Show("Numbers generated: " & first & " to " & last, "Success!", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Vault didn't work", "Fail!", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub