I have imported 2000 items into Vault Item Master. Is there a way I can assign each item to a file (.dwg) using the API, if I have a database table with the correct mappings?
Or start from ReassignComponentsToDifferentItems method of Itemservice.
You can refer to Vault API SDK about use of ReassignComponentsToDifferentItems method.
ReassignComponentsToDifferentItems works well if there is a 1-to-1 mapping between files and items.
I don't recommend using it if you have 1-to-many or many-to-many relationships. In these cases, you need to have a BOM object on the file. Once that is done, the PromoteFile call will generate the items with the correct BOM structure.
Vault sdk has a sample copied as below.
using Autodesk.Connectivity.WebServices;
class VaultSDKSample {
public void AssignFileToItem(ItemService itemSvc, Item selectedItem, File selectedFile)
{
ItemsAndFiles promoteResult = null;
Item[] updatedItems = null;
try {
// first assign the file to a new item
// this example assumes that only 1 item will result from the promote
promoteResult = itemSvc.PromoteFiles(new long[] { selectedFile.Id });
// next reassign the file from the new item to the existing item
updatedItems = itemSvc.ReassignComponentsToDifferentItems( new long[] { promoteResult.ItemRevArray[0].Id }, new long[] { selectedItem.Id });
// commit the changes
itemSvc.UpdateAndCommitItems(updatedItems);
} catch { if (updatedItems != null && updatedItems.Length > 0) { long[] itemIds = new long[updatedItems.Length]; for (int i = 0; i < updatedItems.Length; i++) { itemIds[i] = updatedItems[i].Id; } itemSvc.UndoEditItems(itemIds); } } finally { if (promoteResult != null) { // clear out the promoted item itemSvc.DeleteUnusedItemNumbers(new long[] { promoteResult.ItemRevArray[0].MasterId }); itemSvc.UndoEditItems(new long[] { promoteResult.ItemRevArray[0].Id }); } } } }