cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Out of Date Version Warning on Check out

Out of Date Version Warning on Check out

It would be nice if there was a warning/confirmation box that would pop up when attempting to check out a file that is not the most recent version.  There is currently the red icon, but if you are checking something out from vault using the model tree its easy to miss the red icon.  

1 Comment
jclements7LNR5
Participant

After some trial an error I have an ilogic code that does this automatically.  We have this as a global event trigger anytime a part/assembly is opened.

 

AddReference "Autodesk.Connectivity.WebServices"
AddReference "Autodesk.DataManagement.Client.Framework.dll"
AddReference "Autodesk.DataManagement.Client.Framework.Vault.dll"
AddReference "Connectivity.Application.VaultBase.dll"
Imports ACW = Autodesk.Connectivity.WebServices
Imports VDF = Autodesk.DataManagement.Client.Framework
Imports VB = Connectivity.Application.VaultBase
Imports Autodesk.DataManagement.Client.Framework.Vault.Services
Imports Autodesk.DataManagement.Client.Framework.Vault.Currency.Connections
Imports Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties


Dim dateSmall As String = Replace(DateString, "-", "")
If System.IO.File.Exists("C:\Work\Designs\temp_statusCheck_" & dateSmall & ".txt")
	'This routine initiated a duplicate of itself while openeing an assembly.
	Exit Sub
Else
	'MessageBox.Show(DateString)
End If	

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oThisDoc As Document = ThisDoc.ModelDocument

If oDoc is oThisDoc
	'only want to run this on the highest part that was just open to reduce time.
Else
	Exit Sub
End If

Dim mVltCon As VDF.Vault.Currency.Connections.Connection = Nothing
mVltCon = VB.ConnectionManager.Instance.Connection

If  mVltCon Is Nothing Then
	'not connected to vault, no need to check
	Exit Sub
End If
	

'Creates temp file so status check doesn't keep looping itself
oWrite1 = System.IO.File.CreateText("C:\Work\Designs\temp_statusCheck_" & dateSmall & ".txt")
oWrite1.WriteLine(oDoc.FullFileName)
oWrite1.Close()




Dim thisPartName As String = oDoc.DisplayName
Dim modelFullFileName As String
Dim thisCheckedOutBy As String = Nothing
Dim CheckedOutByString As String = "The following parts are currently checked out:" & vbLf
Dim checkedOutCount As Integer = 0
Dim OutofDateString As String = "WARNING: The following parts do not match the most recent version in Vault:" & vbLf
Dim OutofDateCount As Integer = 0

'Creates settings for vault file aquire
Dim oSettings As New VDF.Vault.Settings.AcquireFilesSettings(mVltCon)
oSettings.LocalPath = New VDF.Currency.FolderPathAbsolute("C:\Work\Designs")
oSettings.OptionsResolution.OverwriteOption = oSettings.AcquireFileResolutionOptions.OverwriteOptions.ForceOverwriteAll
Dim CheckOutState As String = Nothing
Dim ErrorState As String = Nothing
Dim LocalEditsState As String = Nothing
Dim VersionState As String = Nothing
Dim thisDescription As String = Nothing
Dim oFile As ACW.File = Nothing		
Dim oFileIteration As VDF.Vault.Currency.Entities.FileIteration = Nothing	
Dim filePropDefs As ACW.PropDef() = mVltCon.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE")
Dim fileNamePropDef As ACW.PropDef = filePropDefs.[Single](Function(n) n.SysName = "ClientFileName")
Dim fileNameMatch As New ACW.SrchCond()
fileNameMatch.PropDefId = fileNamePropDef.Id
fileNameMatch.PropTyp = ACW.PropertySearchType.SingleProperty
fileNameMatch.SrchOper = 3
fileNameMatch.SrchRule = ACW.SearchRuleType.Must
Dim searchStatus As ACW.SrchStatus = Nothing
Dim searchResults As ACW.File() = Nothing

'Cretes variables for vault search
Dim wsFiels() As ACW.File = Nothing
ReDim wsFiels(0)
Dim wsFiels1() As ACW.File = Nothing
ReDim wsFiels1(0)
Dim mFileIt As VDF.Vault.Currency.Entities.FileIteration = Nothing
Dim mProps As PropertyDefinitionDictionary = mVltCon.PropertyManager.GetPropertyDefinitions(VDF.Vault.Currency.Entities.EntityClassIds.Files,Nothing, VDF.Vault.Currency.Properties.PropertyDefinitionFilter.IncludeAll)
Dim mVaultStatus As PropertyDefinition = mProps(PropertyDefinitionIds.Client.VaultStatus)
Dim status As EntityStatusImageInfo = Nothing
Dim mDefinition As PropertyDefinition = mProps(PropertyDefinitionIds.Server.Description)
Dim mCheckedOutBy As PropertyDefinition

'Get list of all parts that referenced by this file.
oAllSubDocs = oDoc.AllReferencedDocuments
oAllSubDocCount = oAllSubDocs.Count + 1
Dim curSubDocCount As Integer = 0
Dim subDoc As Document 
Dim VaultPaths(oAllSubDocCount) As String
Dim vaultNames(oAllSubDocCount) As String

'Builds a list of part paths to be checked
While curSubDocCount  < oAllSubDocCount
	If curSubDocCount = 0
		subDoc = oDoc
	Else
		subDoc = oAllSubDocs.Item(curSubDocCount)
	End If
	thisPartName = System.IO.Path.GetFileName(subDoc.FullFileName)	
    Try
		VaultPaths(curSubDocCount) = "$/Designs/" & thisPartName
		vaultNames(curSubDocCount) = thisPartName
	Catch
		curSubDocCount = curSubDocCount + 1
		Continue While
	End Try
	curSubDocCount=curSubDocCount+1
End While
	
'Creates a list of files to pull into memory
wsFiels = mVltCon.WebServiceManager.DocumentService.FindLatestFilesByPaths(VaultPaths)
	
curSubDocCount=0
Dim oProgressBar As Inventor.ProgressBar = ThisApplication.CreateProgressBar(False, oAllSubDocCount, "Checking Part Vault Status for " & thisPartName, False,)	
While curSubDocCount  < oAllSubDocCount
	oProgressBar.Message = "Checking " &  vaultNames(curSubDocCount) & " Vault Status " & curSubDocCount+1 & " of " & oAllSubDocCount
	oProgressBar.UpdateProgress
	Try
		mFileIt = New VDF.Vault.Currency.Entities.FileIteration(mVltCon, wsFiels(curSubDocCount))
		status = mVltCon.PropertyManager.GetPropertyValue(mFileIt, mVaultStatus, Nothing)
		CheckOutState = status.Status.CheckoutState.ToString()
		'ErrorState= status.Status.ErrorState.ToString()
		'LocalEditsState = status.Status.LocalEditsState.ToString()
		VersionState = status.Status.VersionState.ToString()
		'MessageBox.Show("CheckOutState= " & CheckOutState & vbLf & "ErrorState= " & ErrorState & vbLf & "LocalEditsState= " &LocalEditsState & vbLf & "VersionState= " & VersionState)
		If VersionState = "MatchesOlderVaultVersion" Or VersionState = "MatchesNoVaultVersion"
			'add to list of updates to retrieve
			thisDescription = mVltCon.PropertyManager.GetPropertyValue(mFileIt, mDefinition, Nothing)
			'Adds part to list of parts to aqurie
			oSettings.AddFileToAcquire(mFileIt, VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download)
			OutofDateString = OutofDateString & vbLf & vaultNames(curSubDocCount) & " - " & thisDescription 
			OutofDateCount=OutofDateCount+1
		Else If CheckOutState = "CheckedOutByOtherUser"
			thisDescription = mVltCon.PropertyManager.GetPropertyValue(mFileIt, mDefinition, Nothing)
			thisCheckedOutBy = mVltCon.PropertyManager.GetPropertyValue(mFileIt, mCheckedOutBy, Nothing)
			CheckedOutByString =CheckedOutByString & vbLf & vaultNames(curSubDocCount) & " - "  & thisDescription & " is currently checked out by "& thisCheckedOutBy
			checkedOutCount=checkedOutCount+1
		End If	
	Catch ex As Exception
		curSubDocCount=curSubDocCount+1
		Continue While
	End Try
	curSubDocCount=curSubDocCount+1
End While
oProgressBar.Close

'Note if newer count is more than 0
If OutofDateCount > 0
	updateFileBool = MessageBox.Show(OutofDateString &  vbLf & vbLf & "It is recommended that you update to the most recent versions of these part(s) before continuing." & vbLf & vbLf & "Would you like to replace these file(s) with the most recent version at this time?", CStr(OutofDateCount) & " File(s) Out of Date", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
	If updateFileBool = vbYes 'update files yes
		'Pull results
		Dim oResults As VDF.Vault.Results.AcquireFilesResults = mVltCon.FileManager.AcquireFiles(oSettings)
		'Close all changed files and their references and reopen into memory
		Dim oAllRefDocNames As New ArrayList
		Dim oAllRefDocs = oDoc.ReferencingDocuments
		If oAllRefDocs.Count > 0
			For Each oSubDoc As Document In oAllRefDocs
				oAllRefDocNames.Add(oSubDoc.FullDocumentName)
				oSubDoc.Close(False)
			Next
		End If
			oAllRefDocNames.Add(oDoc.FullDocumentName)
			oDoc.Close(True)
		For Each oSubDocName In oAllRefDocNames
			'MessageBox.Show("opening " + oSubDocName)
			ThisApplication.Documents.Open(oSubDocName)
		Next				
		MessageBox.Show("All files are now in sync with Vault.")
	Else If updateFileBool = vbNo
		'Do nothing
	End If
End If
		
'Displays checked out parts
If checkedOutCount > 0
	MessageBox.Show(CheckedOutByString, CStr(checkedOutCount) & " File(s) Checked-Out", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If

'Deletes hold file now that rule is complete.
System.IO.File.Delete("C:\Work\Designs\temp_statusCheck_"& dateSmall &".txt")

Can't find what you're looking for? Ask the community or share your knowledge.

Submit Idea