Historically we have included views of parts on our assembly drawings. Now when we come to itemise the parts we are getting 100+ drawings referenced to the item as tertiary links. I want to write a little routine to do this but can't get the UpdateandCommitItem action to work. I am asusming its something to do with the last parameter (active inputs)
here's the function. I have used active input values of 0,1,2 and 4 to no avail
/// <summary> /// Remove the unwanted tertiary linked files. These are extracted when a part is explicitly referenced in a Drawing /// </summary> /// <param name="itemId"></param> public void RemoveUnwantedTertiaryLinks(long itemId) { Item selItem = m_itemSvc.GetItemsByIds(new long[] { itemId })[0]; //Get the primary linked file ItemFileAssoc primaryFile = m_itemSvc.GetItemFileAssociationsByItemIds(new long[] { selItem.Id }, ItemFileLnkTypOpt.Primary)[0]; //Get all the tertiary assocs for the item ItemFileAssoc[] itemFileAssocs = m_itemSvc.GetItemFileAssociationsByItemIds(new long[] { selItem.Id }, ItemFileLnkTypOpt.Tertiary); IEnumerable<long> fileIds = from fileassoc in itemFileAssocs select fileassoc.CldFileId; File[] files = m_docSvc.GetFilesByIds(fileIds.ToArray<long>()); File drawingFile = null; //now match the drawing name to the primary fiule name and remove all the others foreach (File fle in files) { //If the filename matches either the item number or the primary linked filename then keep it if (System.IO.Path.GetFileNameWithoutExtension(fle.Name).ToLower() == System.IO.Path.GetFileNameWithoutExtension(primaryFile.FileName).ToLower() || System.IO.Path.GetFileNameWithoutExtension(fle.Name).ToLower() == selItem.ItemNum.ToLower()) { drawingFile = fle; break; } if (drawingFile != null) break; } //now edit the item to update links Item editItem = m_itemSvc.EditItem(selItem.RevId); Item updateItem = m_itemSvc.UpdateAndCommitItem(editItem, primaryFile.CldFileId, false, null, null, null, null, null, new long[] { drawingFile.Id }, 1); }
Any one got any pointers?
Solved! Go to Solution.
Solved by Redmond.D. Go to Solution.
You are correct, it's related to the "active inputs" parameter. Unfortunately, you have run into another documentation bug. The CHM doesn't mention that 8 is the bit value for making the 'tertLinks' input active.
In the code you showed, 'secondary' is the only active field because you pass in 1. If you want both 'secondary' and 'tertLinks' to be active, pass in 9.
After you have deleted those links don't you have problem that they return on each Item update?
Hello,
How does one, without a coding background, insert & run this code?
Better yet, where is the secret, non-divulged setting that stops vault from linking every tertiary drawing to an item, when the item is assigned, or updated?
The current process of removal is to edit the item, RMB on the tertiary link, click Remove, accept the prompt, and click save (Vault will not allow a bulk removal). This is a mind-numbing operation when you have upwards of 100 unwanted links.
And to add insult to injury, all of the removed tertiary links will reappear when the item is updated.
I have heard that this is "By Design" but is this really the most efficient strategy, without allowing users the option to disable it?
TIA... Hopefully...