Updating a part property using the API adds assemblies to the "Uses" tab

Updating a part property using the API adds assemblies to the "Uses" tab

ron_m
Enthusiast Enthusiast
448 Views
7 Replies
Message 1 of 8

Updating a part property using the API adds assemblies to the "Uses" tab

ron_m
Enthusiast
Enthusiast

I have a Vault Add-on the lookups up the current part description from an ERP system and updates the part's description property. 

ron_m_0-1738176180990.png

The function is based on the example from justonesandzeros. 

http://justonesandzeros.typepad.com/blog/2015/02/another-way-to-update-properties.html

The code has been recently updated from Vault 2022 to 2024.

CheckIn:

File newFile = mgr.DocumentService.CheckinUploadedFile(
selectedFile.MasterId, "Update from PAI JCS: " + UpdateMessage, false, DateTime.Now,
GetFileAssociations(selectedFile, connection), null, true, selectedFile.Name, selectedFile.FileClass,
selectedFile.Hidden, uploadTicket.ToByteArray());

 

Using the following for file associations.

/// <summary>
/// Return list of file associations for given file.
/// http://adndevblog.typepad.com/manufacturing/2013/09/vault-2014-api-example-that-adds-a-file-and-asso...
/// </summary>
/// <param name="selectedFile">Selected file.</param>
/// <param name="connection">Current Vault Connection.</param>
/// <returns>Array of file association paramiters</returns>
private FileAssocParam[] GetFileAssociations(File selectedFile, VDF.Vault.Currency.Connections.Connection connection)
{
// Settings used in GetFileAssociationLites()
VDF.Vault.Settings.FileRelationshipGatheringSettings myFileRelationshipSettings = new VDF.Vault.Settings.FileRelationshipGatheringSettings();

myFileRelationshipSettings.IncludeAttachments = true;
myFileRelationshipSettings.IncludeChildren = true;
myFileRelationshipSettings.IncludeParents = true;
myFileRelationshipSettings.IncludeRelatedDocumentation = true;
// added to get DWF references
myFileRelationshipSettings.IncludeHiddenEntities = true;
myFileRelationshipSettings.IncludeLibraryContents = true;

// Current associations for file
System.Collections.Generic.IEnumerable<FileAssocLite> myColOfFileAssocLite =
connection.FileManager.GetFileAssociationLites(selectedFile.Id.ToSingleArray(), myFileRelationshipSettings);

// Go though each FileAssocLite to add to list
List<FileAssocParam> fileAssocParams = new List<FileAssocParam>();
if (myColOfFileAssocLite != null)
{
foreach (FileAssocLite myFileAssocLite in myColOfFileAssocLite)
{
// skip self dependency
if (!(myFileAssocLite.Typ == AssociationType.Dependency &&
myFileAssocLite.CldFileId == selectedFile.Id))
{
FileAssocParam par = 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);
}
}
}

return fileAssocParams.ToArray();
}

 

Should I set IncludeChildren to false if the file is a part?

0 Likes
Accepted solutions (1)
449 Views
7 Replies
Replies (7)
Message 2 of 8

Markus.Koechl
Autodesk
Autodesk
Accepted solution

Part files can have a parent-child relationship: a derived part can derive from an assembly or a part file. So, if part file derives another part, a property update must not lose the relationship. An alternate approach to updating property values without the overhead of managing the associations is to use the IExplorerUtil.UpdateFileProperties() method. You can find an implementation sample here: https://github.com/koechlm/iLogic-Vault/blob/895d9a4e5098064a61ea06f7e9d24a2b6fb7f46c/iLogic-Vault-Q...



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 3 of 8

ron_m
Enthusiast
Enthusiast

Thank you for your input.

 

The JustOnesAndZeros document from 2015 listed that as an option but stated that IExplorerUtil.UpdateFileProperties was "prone to failure" when used though the API. Has this changed since then? I am using his alternative to the 2 "Sucky Options".

 

From the article

"Sucky option 2 is to use IExplorerUtil.UpdateFileProperties in the Vault API.  On paper, this is a great function.  It loads up core pieces of Vault Explorer libraries and executes the Edit Properties command just as if a user had done it through the UI.  It even handles the checkout/checkin.  The problem is that it’s a bulky operation and prone to failure.  Vault Explorer simply wasn’t meant to be invoked from the API.  IExplorerUtil was always indented to be a temporary solution until something better came along.  And that something better is here...."

 

 

0 Likes
Message 4 of 8

Markus.Koechl
Autodesk
Autodesk

I agree that the IExplorerUtil might not be the best choice for large batches, as internally, it is a cascading process. However, this API call is widely used and has been stabilized over the years, so it is a valid option with pros and cons. @ron_m: As you already implemented and just asked about the option to include/exclude children, I don't see why you need to change the strategy. Nevertheless, the community following this thread should know that - from a coding perspective - there is an alternate option. So, thank you for adding the citations, which added the details that each approach has its characteristics.



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 5 of 8

ron_m
Enthusiast
Enthusiast

 

I haven't implemented the IExplorerUtil.UpdateFileProperties codeI will be looking into it and possible addition to the add-on as an option being as it's only handling 1 file at a time.

 

The end of my original post is asking about a possible fix using my current code.

 

"Should I set IncludeChildren to false if the file is a part?"

 

 

0 Likes
Message 6 of 8

Markus.Koechl
Autodesk
Autodesk

I already answered your question, but the discussion about the alternate option overlayed it: Yes, I recommend including children. If there are none, then it's no problem, but if there are (as explained in my first answer, a part file can have a child relationship), you will lose them if IncludeChildren is set to false.



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 7 of 8

ron_m
Enthusiast
Enthusiast

So, setting it False will cause problems for parts that do have child relationships. 

 

The part my user contacted me about did not have any child relationships. He showed that using my vault add-on to update the description, the add-on somehow added child relationships to some assemblies. Obviously, this is a bug in the add-on.  To fix it he opened the part in Inventor, checked it out, saved it, checked it in. After that process, vault showed the part correctly with no child relationships.

 

I was hoping to figure out the bug in my code. As noted, we recently update from 2022 to 2024. The Add-On was updated to use the new 2024 API and version code, [assembly: Autodesk.Connectivity.Extensibility.Framework.ApiVersion("17.0")].

 

In the past I had problems after updating to 2022 where an add-on for our ERP system that import bills from the vault failed. I was using the un-documented file bill and thin client which now fails because the file IDs changed in the vault with the update. Ended up using a much slower process utilizing temporary Item bills and thick client.

0 Likes
Message 8 of 8

ron_m
Enthusiast
Enthusiast

Switch to the UpdateFileProperties method.

Still don't know why my previous method failed but the new one works and is simpler.

0 Likes