Vault File Associations when Checking In

Vault File Associations when Checking In

Anonymous
Not applicable
6,648 Views
14 Replies
Message 1 of 15

Vault File Associations when Checking In

Anonymous
Not applicable

I am trying to make changes to iProperties of an ipt file and check it back into the vault through the Inventor/Vault API, and seem to be running into some issues.

 

Here is my process:

 

1. Download the file from the Vault through the API (using FileManager.AcquireFiles)

2. Open the file in Inventor

3. Update the iProperties

4. Save the file

5. Check in the file to the Vault (using FileManager.CheckinFile, with file associations through FileManager.GetFileAssociationLites)

 

I have succeeded when doing this for idw files, but for ipt file I get an error 1022, which I gather means that I have a file association to the file I'm checking in). I used to have this issue with the idw file, but added a check where I would remove associations if the CldFileId of the associated file matched the EntityIterationId of the file I'm trying to check in. This check doesn't seem to work when checking in an ipt file because the IDs don't match, even though the file name is the same.

 

Is there a way for me to get the correct associations of the files for all file types?

 

Here is the code for how I obtain the file associations:

 

 

 Private Function Vault_GetFileAssocs(connection As VDF.Vault.Currency.Connections.Connection, oFileIteration As VDF.Vault.Currency.Entities.FileIteration) As FileAssocParam()
        Dim myFileRelationshipSettings As VDF.Vault.Settings.FileRelationshipGatheringSettings
        myFileRelationshipSettings = New VDF.Vault.Settings.FileRelationshipGatheringSettings

        myFileRelationshipSettings.IncludeAttachments = True
        myFileRelationshipSettings.IncludeChildren = True
        myFileRelationshipSettings.IncludeParents = True
        myFileRelationshipSettings.IncludeRelatedDocumentation = True

        Dim myColOfFileAssocLite As System.Collections.Generic.IEnumerable(Of ACW.FileAssocLite) = Nothing
        myColOfFileAssocLite = connection.FileManager.GetFileAssociationLites(New Long() {oFileIteration.EntityIterationId}, myFileRelationshipSettings)
        Dim fileAssocParams As ArrayList = New ArrayList

        ' Add FileAssocParam objects to the ArrayList
        ' using values from the collection
        ' of FileAssocLite in the collection
        ' returned from GetFileAssociationLites()
        If Not myColOfFileAssocLite Is Nothing Then
            Dim myFileAssocLite As FileAssocLite
            '    'Go through each FileAssoLite in the
            '   in the collection of FileAssocLite
            For Each myFileAssocLite In myColOfFileAssocLite
                ' This is a new FileAssocParam that
                ' is going to be added to the List
                ' getting the properties
                If myFileAssocLite.CldFileId <> oFileIteration.EntityIterationId Then
                    Dim par As FileAssocParam = New FileAssocParam()
                    par.CldFileId = myFileAssocLite.CldFileId
                    par.RefId = myFileAssocLite.RefId
                    par.Source = myFileAssocLite.Source
                    par.Typ = myFileAssocLite.Typ
                    par.ExpectedVaultPath = myFileAssocLite.ExpectedVaultPath
                    fileAssocParams.Add(par)
                End If

            Next
        End If


        Dim myFileAssocParamArray As FileAssocParam() = DirectCast(fileAssocParams.ToArray(GetType(FileAssocParam)), FileAssocParam())

        Return myFileAssocParamArray

    End Function

 

0 Likes
Accepted solutions (1)
6,649 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable

Any suggestions here? Like I said, it works for the idw, just not the ipt files.

0 Likes
Message 3 of 15

wayne.brill
Collaborator
Collaborator

Hi,

 

As I understand there should be no scenario where a part file references itself. Does this happen with every ipt file you have tried it on?

 

Please upload a project I can use to research this behavior. Let me know if you want to send it directly to me.

 

Thanks,

Wayne

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 4 of 15

Anonymous
Not applicable

Hi Wayne,

 

It seems to happen with every ipt file I try to check in. The issue seems to be that when I am copying over the File Associations from the pre-checked in file to the file I'm checking in.

 

debug_window.png

 

As you can see from the Watch screen shown in the attached image, there are 4 file associations found when I use GetFileAssociationLites on the EntityIterationId of my local FileIteration. Two of those, for whatever reason, are the same file (ID 173433). This ID doesn't match the local File Iteration (ID 168107), but they are the same base file (you can see the file name matches except for the folder, because one is local and the other is on the Vault - "VEL002-p0411-Pivot Pin with Shoulder & Snap Ring - 1045 Carbon Steel - Nickel - M5 x 33.ipt").

 

 

 This is one example, but it happens every time I try to check an ipt file in. The drawings only seem to have one file association, which is the ipt file, so I don't get this issue. Am I doing something wrong here?

 

Wayne: I'd be happy to share my code, but I'm not sure how useful it would be to you. Our software is used to interface the Vault and Inventor with our ERP system, and you need to be able to access it in order to try checking in files. 

 

Here is my entire check in function, which calls the FileAssociations function:

 

 Public Function Vault_CheckIn(connection As VDF.Vault.Currency.Connections.Connection, oFile As Autodesk.Connectivity.WebServices.File, filePath As String, comment As String) As Boolean

        ' Update to get the latest file information
        oFile = Vault_UpdateFile(connection, oFile)
        ' Get the FileIteration 
        Dim oFileIteration As VDF.Vault.Currency.Entities.FileIteration = New VDF.Vault.Currency.Entities.FileIteration(connection, oFile)

        Dim filePathAbs As VDF.Currency.FilePathAbsolute = New VDF.Currency.FilePathAbsolute(filePath)

        'determine if the file exists
        If Not System.IO.File.Exists(filePath) Then
            MsgBox("The file you are attempting to check in does not exist on disk.")
            Return False
        End If
        Try
            If oFileIteration.IsCheckedOut = True Then

                connection.FileManager.CheckinFile(oFileIteration, comment, False, Vault_GetFileAssocs(connection, oFileIteration),
                                                                                 Nothing, False, Nothing,
                                                      ACW.FileClassification.None, False, filePathAbs)
                Return True
            End If
        Catch e As Exception
            MsgBox(e.Message)
        End Try

        Return False


    End Function

Here is the entire File Associations function, called by the check in Function:

 

 

Private Function Vault_GetFileAssocs(connection As VDF.Vault.Currency.Connections.Connection, oFileIteration As VDF.Vault.Currency.Entities.FileIteration) As FileAssocParam()
        Dim myFileRelationshipSettings As VDF.Vault.Settings.FileRelationshipGatheringSettings
        myFileRelationshipSettings = New VDF.Vault.Settings.FileRelationshipGatheringSettings

        myFileRelationshipSettings.IncludeAttachments = True
        myFileRelationshipSettings.IncludeChildren = True
        myFileRelationshipSettings.IncludeParents = True
        myFileRelationshipSettings.IncludeRelatedDocumentation = True

        Dim myColOfFileAssocLite As System.Collections.Generic.IEnumerable(Of ACW.FileAssocLite) = Nothing
        myColOfFileAssocLite = connection.FileManager.GetFileAssociationLites(New Long() {oFileIteration.EntityIterationId}, myFileRelationshipSettings)
        Dim fileAssocParams As ArrayList = New ArrayList

        ' Add FileAssocParam objects to the ArrayList
        ' using values from the collection
        ' of FileAssocLite in the collection
        ' returned from GetFileAssociationLites()
        If Not myColOfFileAssocLite Is Nothing Then
            Dim myFileAssocLite As FileAssocLite
            '    'Go through each FileAssoLite in the
            '   in the collection of FileAssocLite
            For Each myFileAssocLite In myColOfFileAssocLite
                ' This is a new FileAssocParam that
                ' is going to be added to the List
                ' getting the properties
                If myFileAssocLite.CldFileId <> oFileIteration.EntityIterationId Then
                    Dim par As FileAssocParam = New FileAssocParam()
                    par.CldFileId = myFileAssocLite.CldFileId
                    par.RefId = myFileAssocLite.RefId
                    par.Source = myFileAssocLite.Source
                    par.Typ = myFileAssocLite.Typ
                    par.ExpectedVaultPath = myFileAssocLite.ExpectedVaultPath
                    fileAssocParams.Add(par)
                End If

            Next
        End If


        Dim myFileAssocParamArray As FileAssocParam() = DirectCast(fileAssocParams.ToArray(GetType(FileAssocParam)), FileAssocParam())

        Return myFileAssocParamArray

    End Function

 

 

 

 If you would like the whole project, please let me know how to securely send it to you.

Thank you for your assistance!

 

 

 

 

 

0 Likes
Message 5 of 15

wayne.brill
Collaborator
Collaborator

Hi,

 

Here is what I have done to try and recreate this behavior:

 

Added your code and the code below (added a button) to this SDK sample:

C:\Program Files (x86)\Autodesk\Autodesk Vault 2016 SDK\vs12\VB\VaultList

 

I then used the Inventor Vault Add-In to check out an ipt. I changed an iProperty, saved and closed the ipt without checking it in.

 

I than ran the code. It is getting checked in and I don't see the error. Can you try doing a simple test like this?

 

I had to comment out this code in your Vault_CheckIn function. Can you share what that is doing?

oFile = Vault_UpdateFile(connection, oFile)

 

Code I created to call your Vault_Checkin().

 

  Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        ' For demonstration purposes, the information is hard-coded.
        Dim results As VDF.Vault.Results.LogInResult = VDF.Vault.Library.ConnectionManager.LogIn _
                                      ("localhost", "Vault", "Administrator", "", _
                                       VDF.Vault.Currency.Connections.AuthenticationFlags.Standard, Nothing)
        If Not results.Success Then
            Return
        End If

        Dim connection As VDF.Vault.Currency.Connections.Connection = results.Connection

        Dim webServicMGR As WebServiceManager = connection.WebServiceManager


        Dim oFile As Autodesk.Connectivity.WebServices.File = Nothing
        'Change this to a file on your system
        Dim filePath As String = "C:\Users\brillw\Documents\Vault\Inventor_Files_WB\WB-2-22-16.ipt"
        'Change this to folder in your vault where the ipt file is
        Dim myInvFolder As Folder = webServicMGR.DocumentService.GetFolderByPath("$/Inventor_Files_WB")
        Dim myInvFolderFiles() As File =
                            webServicMGR.DocumentService.GetLatestFilesByFolderId(myInvFolder.Id, True)

        If ((myInvFolderFiles Is Nothing) _
                     OrElse (myInvFolderFiles.Length = 0)) Then
            Return
        End If

        For Each oFileInFolder As File In myInvFolderFiles
            'Change this to the file you have checked out
            If (oFileInFolder.Name = "WB-2-22-16.ipt") Then
                oFile = oFileInFolder
                Exit For
            End If

        Next

        Vault_CheckIn(connection, oFile, filePath, "WB Comment")

        VDF.Vault.Library.ConnectionManager.LogOut(connection)

    End Sub

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 6 of 15

Anonymous
Not applicable
Accepted solution

Hi Wayne,

 

Thanks for all your help. I believe you spotted the issue. My original code for Vault_UpdateFile was:

 

Public Function Vault_UpdateFile(connection As VDF.Vault.Currency.Connections.Connection, myFile As Autodesk.Connectivity.WebServices.File) As Autodesk.Connectivity.WebServices.File
Dim file As Autodesk.Connectivity.WebServices.File = connection.WebServiceManager.DocumentService.GetFileById(myFile.Id)
Return file
End Function

I realize after your comments that this was requesting the file before it was checked out, and my file associations was comparing it to the checked out file. I changed code to what's below, and everything works!

 

Public Function Vault_UpdateFile(connection As VDF.Vault.Currency.Connections.Connection, myFile As Autodesk.Connectivity.WebServices.File) As Autodesk.Connectivity.WebServices.File
Dim file As Autodesk.Connectivity.WebServices.File = connection.WebServiceManager.DocumentService.GetLatestFileByMasterId(myFile.MasterId)
Return file
End Function

 

Message 7 of 15

Anonymous
Not applicable

Hi Wayne,

 

I seem to be having an issue with the solution for checking in files that you helped me with. Now when I go to open one of those files I checked in using this method, Vault gives me the following error then crashes:

 

 vault_error.png

 

It's not clear what this error means in terms of what I'm doing wrong, but it's causing a lot of frustration (because every time I open a file my vault is crashing). I've submitted error reports but haven't heard anything back from Autodesk.

0 Likes
Message 8 of 15

wayne.brill
Collaborator
Collaborator

Hi,

 

What type of file is getting the error when getting checked out?

 

 I just tested with an .ipt file. (checked in a file using the API that was checked out by the Inventor vault Add-In)

 

Was the file originally added to the Vault using the Inventor Vault Add-In?

 

We don’t recommend adding or checking in Inventor files through the API. There is a large amount of meta-data that goes along with a file upload (RefId, dependencies, BOM). So, we recommend letting the CAD plug-in do the upload of CAD data. It’s the same reason Vault Explorer doesn’t let you drag and drop CAD files into Vault.

 

Thanks,

Wayne

 

 

 

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 9 of 15

Anonymous
Not applicable

Hi Wayne,

 

Thanks for your prompt response!

 

It is an Inventor file. I am doing this because I have a bit of code that changes some of the iProperties of part and drawing (ipt and idw) files and checks it back in. I'm doing it through a VB.NET Add-In to Inventor.  Is there a way to automate the CAD plug in to check in Inventor files, or to verify the CAD meta-data before checking in? 

 

Regards,

Ben

 

 

0 Likes
Message 10 of 15

junyi_zhu
Autodesk
Autodesk

The error usually means missing RefId for some of the references. You can check your file associations to see if it's there before and after.

 

As Wayne said, it's best to leave check-in to the vault addin. You may consider Task Scheduler if you don't need an immediate check-in after updating the property.



Junyi Zhu

0 Likes
Message 11 of 15

wayne.brill
Collaborator
Collaborator

Hi,

 

There is not any API for the Vault Add-In. See this post on the Vault Idea station:

http://forums.autodesk.com/t5/vault-ideas/api-access-to-vault-inventor-add-in-and-other-cad-add-ins/...

 

In my tests if the ipt was already added to the vault by the Vault Inventor Add-In I could check it out and check it back using the Vault API. Maybe there is something different about the ipt you are having this problem with. I could test it. Let me know if you want to send me the file privately.

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 12 of 15

Anonymous
Not applicable

Hello, Ben!

 

To check in the file by FileManager.GetFileAssociationLites is the hard way. I had the same errors.

 

Firstly, you have to read two articles:

 

  1. http://justonesandzeros.typepad.com/blog/2009/09/file-associations-part-1.html
  2. http://justonesandzeros.typepad.com/blog/2009/10/file-associations-part-2.html

 

Secondly, I attach my code how to get FileAssocParam():

 

     

Dim i As Int16 = 0

' Get FileAssocArray with the required parameters ( child, parents etc. )
Dim fileAssocArray() As FileAssocArray = g_MyMng.DocumentService.GetLatestFileAssociationsByMasterIds({g_SelectedFile.MasterId}, FileAssociationTypeEnum.None, False, FileAssociationTypeEnum.Dependency, False, False, False, False)

' FileAssocParam
Dim fileAssocParametr() As FileAssocParam

If Not (fileAssocArray.Single().FileAssocs.IsNullOrEmpty) Then ' This case for assemblies

ReDim fileAssocParametr(fileAssocArray.Single().FileAssocs.Count() - 1)

For Each file In fileAssocArray.Single().FileAssocs
fileAssocParametr(i) = New FileAssocParam()
fileAssocParametr(i).CldFileId = file.CldFile.Id
fileAssocParametr(i).ExpectedVaultPath = file.ExpectedVaultPath
fileAssocParametr(i).RefId = file.RefId
fileAssocParametr(i).Source = file.Source
fileAssocParametr(i).Typ = file.Typ
i = i + 1
Next

Else '--- This case for details
fileAssocParametr = Nothing
End If

 

 

And fileAssocParametr will be contain associations!

 

Good luck!

 

Regards,

Alexander

Message 13 of 15

Anonymous
Not applicable

Then change a property.

 

 

Dim propWrite(0) As PropWriteReq

propWrite(0) = New PropWriteReq()
propWrite(0).CanCreate = False
propWrite(0).Moniker = "Part Number!{32853F0F-3444-11D1-9E93-0060B03C1CA6}!nvarchar"
propWrite(0).Val = "TEST"

 

Then upload in check in a file.

 

Dim results As PropWriteResults
Dim uploadTicket As Byte() = g_MyCnt.WebServiceManager.FilestoreService.CopyFile(g_DownloadTicket.Bytes, True, propWrite, results)

Dim newFile As File = g_MyCnt.WebServiceManager.DocumentService.CheckinUploadedFile(
  g_SelectedFile.MasterId,
  "Comment",
  False,
  DateTime.Now,
  fileAssocParametr, ' <------
  Nothing,
  True,
  g_SelectedFile.Name,
  g_SelectedFile.FileClass,
  g_SelectedFile.Hidden,
  uploadTicket.ToByteArray())

 

 

0 Likes
Message 14 of 15

Anonymous
Not applicable

Hey vaultMaster.Name,

 

Thanks for your help!

I have tried your solution (using the GetLatestFileAssociationsByMasterIds) but I get a bunch of Non-Unique Project File Name warnings when I try to open assemblies. The issue is that I have several files or assemblies with the same name in my project workspace and the files I check out/in using the VB.NET tool no longer know which associations to make. Sometimes this isn't an issue (easy to figure out which file), but other times it can be impossible (Bolted Connections). Here is the dialog window:

 

Non-unique.png

 

I can't figure out why it no longer has the correct connections, but if you have any suggestions on how to fix this issue, that would be great!

 

Thanks,

0 Likes
Message 15 of 15

daniel_pBED96
Observer
Observer

Is there any way to check out part file (.ipt) and drawing file (.idw), at the same time? Without the need to go into part file > Click "Open drawing from vault" > Check out (the drawing).

0 Likes