Skip to content

Commit

Permalink
GetVaultFileStatus() implemented
Browse files Browse the repository at this point in the history
new sample rules for AddFile() and GetVaultFileStatus()
  • Loading branch information
koechlm committed Apr 8, 2021
1 parent d300d39 commit 0734bcc
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 3 deletions.
4 changes: 2 additions & 2 deletions iLogic-Vault-QuickstartLibrary/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2021.1.0.3")]
[assembly: AssemblyFileVersion("2021.1.0.3")]
[assembly: AssemblyVersion("2021.1.0.5")]
[assembly: AssemblyFileVersion("2021.1.0.5")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
AddReference "QuickstartiLogicLibrary.dll"
'enable iLogicVault commands and validate user's login state
break
Dim iLogicVault As New QuickstartiLogicLibrary.QuickstartiLogicLib
If iLogicVault.LoggedIn = False
Logger.Error("Not Logged In to Vault! - Login first and repeat executing this rule.")
Exit Sub
End If

'don't run rules for AnyCAD components.
If ThisDoc.Document.FullFileName.Contains("*LocalDocs*") = True Then
Exit Sub
End If

Dim oAssyDoc As Inventor.AssemblyDocument
Dim oAssyCompDef As Inventor.AssemblyComponentDefinition
Dim oBom As Inventor.BOM
Dim oBomView As Inventor.BOMView
Dim oBomRow As Inventor.BOMRow
Dim oBomRowEnum As Inventor.BOMRowsEnumerator

Try
oDoc = ThisDoc.Document
If oDoc.DocumentType = kAssemblyDocumentObject Then
oAssyDoc = oDoc
oAssyCompDef = oAssyDoc.ComponentDefinition
End If
oBom = oAssyCompDef.BOM
oBom.StructuredViewEnabled = True
oBom.StructuredViewFirstLevelOnly = False

'secure constant item numbers
oBomView = oBom.BOMViews.Item("Structured")
For Each oBomRow In oBomView.BOMRows
oBomRow.ItemNumberLocked = True
Next

Catch ex As Exception
Logger.Error("Something went wrong while enabling BOM Structured View.")
End Try

'derive export file name from this document
Dim oBOMExpFile = ThisDoc.ChangeExtension("xlsx")

'enable LOD Master (BOM export is not support using other LOD)
Try
oAssyCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master").Activate(True)
Catch ex As Exception
Logger.Error("Something went wrong while activating LOD Master")
End Try

'Delete existing file to avoid overwrite restrictions
Dim oFileInfo As New System.IO.FileInfo(oBOMExpFile)
If oFileInfo.Exists = True Then
If (oFileInfo.Attributes) Then
oFileInfo.Attributes = (oFileInfo.Attributes And Not oFileInfo.Attributes.ReadOnly)
System.IO.File.Delete(oBOMExpFile)
End If
End If

'create BOM export
ThisBOM.Export("Structured", oBOMExpFile, kMicrosoftExcelFormat)
'attach result
If System.IO.File.Exists(oBOMExpFile) Then
Dim mReturn As Boolean
Dim mVaultPath As String = iLogicVault.ConvertLocalPathToVaultPath(oBOMExpFile)
mReturn = iLogicVault.AddFile(oBOMExpFile, mVaultPath, True)
Else
Logger.Error("Something went wrong exporting BOM (ThisBOM.Export()")
End If

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
AddReference "QuickstartiLogicLibrary.dll"
'DISCLAIMER:
'---------------------------------
'In any case, code, templates, and snippets of this solution are of "work in progress" character.
'Neither Markus Koechl, nor Autodesk represents that these samples are reliable, accurate, complete, or otherwise valid.
'Accordingly, those configuration samples are provided “as is” with no warranty of any kind and you use the applications at your own risk.

Sub Main
break
'enable iLogicVault commands and validate user's login state
Dim iLogicVault As New QuickstartiLogicLibrary.QuickstartiLogicLib
If iLogicVault.LoggedIn = False
Logger.Error("Not Logged In to Vault! - Login first and repeat executing this rule.")
Exit Sub
End If

'Retrieve the active document's Vault file status as name/value pairs
Dim mDocVaultStatus As New Dictionary(Of String, String)
mDocVaultStatus = iLogicVault.GetVaultFileStatus(ThisDoc.PathAndFileName(True))
If mDocVaultStatus.Item("ErrorState") = "None"
Logger.Info("CheckOutState = " + mDocVaultStatus.Item("CheckOutState"))
Logger.Info("ConsumableState = " + mDocVaultStatus.Item("ConsumableState"))
Logger.Info("ErrorState = " + mDocVaultStatus.Item("ErrorState"))
Logger.Info("LocalEditsState = " + mDocVaultStatus.Item("LocalEditsState"))
Logger.Info("LockState = " + mDocVaultStatus.Item("LockState"))
Logger.Info("RevisionState = " + mDocVaultStatus.Item("RevisionState"))
Logger.Info("VersionState = " + mDocVaultStatus.Item("VersionState"))
Else
Logger.Error("ErrorState = " + mDocVaultStatus.Item("ErrorState"))
End If
End Sub
60 changes: 59 additions & 1 deletion iLogic-Vault-QuickstartLibrary/iLogic-Vault QuickstartLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using ACW = Autodesk.Connectivity.WebServices;
using VDF = Autodesk.DataManagement.Client.Framework;
using VltBase = Connectivity.Application.VaultBase;
using Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties;

namespace QuickstartiLogicLibrary
{
Expand Down Expand Up @@ -58,6 +59,7 @@ public VDF.Vault.Currency.Connections.Connection GetVaultConnection()
return null;
}

/// <summary>
/// Adds local file to Vault.
/// </summary>
/// <param name="FullFileName">File path and name of file to add in local working folder.</param>
Expand Down Expand Up @@ -299,7 +301,10 @@ public string GetFileByFullFilePath(string VaultFullFileName, ref Dictionary<str


/// <summary>
///
/// Downloads Vault file using full file path, e.g. "$/Designs/Base.ipt". Returns full file name in local working folder(download enforces override, if local file exists),
/// returns nothing if the file does not exist at indicated location.
/// File and Item property dictionaries return all values converted to text. Access the value using the Vault property display name as key.
/// Preset Options: Download Children (recursively) = Enabled, Enforce Overwrite = True
/// </summary>
/// <param name="VaultFullFileName"></param>
/// <param name="VaultFileProperties"></param>
Expand Down Expand Up @@ -363,6 +368,59 @@ public string GetFileByFullFilePath(string VaultFullFileName, ref Dictionary<str
return null;
}


/// <summary>
/// Get the local file's status in Vault. Validate the ErrorState = "None" to get all return values.
/// </summary>
/// <param name="LocalFullFileName">Local path and file name, e.g., ThisDoc.FullFileName</param>
/// <returns>ErrorState only if file does not exist, otherwise CheckOutState, ConsumableState, ErrorState, LocalEditsState, LockState, RevisionState, VersionState</returns>
public Dictionary<string, string> GetVaultFileStatus(string LocalFullFileName)
{
Dictionary<string, string> keyValues = new Dictionary<string, string>();

//convert the local path to the corresponding Vault path
string FileName = null;
System.IO.FileInfo fileInfo = new System.IO.FileInfo(LocalFullFileName);
if (fileInfo.Exists)
{
FileName = fileInfo.Name;
}
else
{
keyValues.Add("ErrorState", "Local file not found");
return keyValues;
}
string VaultFilePath = ConvertLocalPathToVaultPath(LocalFullFileName) + "/" + FileName;

//get the file object consuming the Vault Path; if the file does not exist return the file-non-exist status information
Autodesk.Connectivity.WebServicesTools.WebServiceManager mWsMgr = conn.WebServiceManager;
ACW.File mFile = mWsMgr.DocumentService.FindLatestFilesByPaths(new string[] { VaultFilePath }).FirstOrDefault();

if (mFile.Id == -1)// file not found
{
keyValues.Add("ErrorState", "File does not exist in Vault.");
return keyValues;
}

VDF.Vault.Currency.Entities.FileIteration mFileIteration = new VDF.Vault.Currency.Entities.FileIteration(conn, mFile);

PropertyDefinitionDictionary mProps = conn.PropertyManager.GetPropertyDefinitions(VDF.Vault.Currency.Entities.EntityClassIds.Files, null, PropertyDefinitionFilter.IncludeAll);

PropertyDefinition mVaultStatus = mProps[PropertyDefinitionIds.Client.VaultStatus];

EntityStatusImageInfo status = conn.PropertyManager.GetPropertyValue(mFileIteration, mVaultStatus, null) as EntityStatusImageInfo;

keyValues.Add("CheckOutState", status.Status.CheckoutState.ToString());
keyValues.Add("ConsumableState", status.Status.ConsumableState.ToString());
keyValues.Add("ErrorState", status.Status.ErrorState.ToString());
keyValues.Add("LocalEditsState", status.Status.LocalEditsState.ToString());
keyValues.Add("LockState", status.Status.LockState.ToString());
keyValues.Add("RevisionState", status.Status.RevisionState.ToString());
keyValues.Add("VersionState", status.Status.VersionState.ToString());

return keyValues;
}

/// <summary>
/// Copy Vault file on file server and download using full file path, e.g. "$/Designs/Base.ipt".
/// Create new file name using default or named numbering scheme.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<None Include="Sample Rules iLogic-Vault\iLogicVault_AddFile.iLogicVb" />
<None Include="Sample Rules iLogic-Vault\iLogicVault_CheckFilesExists.iLogicVb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -166,6 +167,7 @@
<None Include="Sample Rules iLogic-Vault\iLogicVault_GetThumbnailFileBySourceFullFilePath.iLogicVb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Sample Rules iLogic-Vault\iLogicVault_GetVaultFileStatus.iLogicVb" />
<None Include="Sample Rules iLogic-Vault\iLogicVault_UndoCheckOut.iLogicVb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down

0 comments on commit 0734bcc

Please sign in to comment.