- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I had an apprentice application that was working just fine, and then it stopped working out of nowhere. There have been no updates to Vault or Inventor. Really what this application does is just loop through the assembly structure and make a simple dictionary/BOM so I can use it later in the program.
In the 'iterateBOM' loop, I search for the latest component file and create a new instance of apprentice. I do this because without this, I get a COM error. This COM error is persistent until I instantiated a new instance of Inventor in each loop. Odd behavior - I have seen others just pass occurrences.suboccurrences or use other methods. I am unable to explain it.
What I have found is that it just simply cannot found any occurrences in apprenticeDocument.ComponentDefinition.Occurrences, so when it passes this into 'iterateBOM', an exception is thrown right at the line that says: foreach(ComponentOccurrence occurrence in occurrences) loop.
public static Dictionary<string, BomItem> createBOM(Connection connection, WebServiceManager mWsMgr, ACW.File selectedContextFile, Dictionary<string, BomItem> BOM)
{
//ApprenticeServerDocument apprenticeDocument = InstantiateAndOpenApprentice(selectedContextFile, connection, mWsMgr);
string mDocPath = AcquireFileForInventorAndGetPath(connection, mWsMgr, selectedContextFile);
ApprenticeServerComponent newApprentice = new ApprenticeServerComponent();
ApprenticeServerDocument apprenticeDocument = newApprentice.Open(mDocPath);
iterateBOM(apprenticeDocument.ComponentDefinition.Occurrences, connection, mWsMgr, BOM);
return BOM;
}
public static void iterateBOM(ComponentOccurrences occurrences, Connection connection, WebServiceManager mWsMgr, Dictionary<string, BomItem> BOM)
{
foreach (ComponentOccurrence occurrence in occurrences)
{
if (!occurrence.Suppressed)
{
if (occurrence.ReferencedDocumentDescriptor.ReferencedDocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
{
UpdateBomDictionary(occurrence, BOM);
string fileOccurrencePath = occurrence.ReferencedDocumentDescriptor.FullDocumentName;
string[] filePathParts = fileOccurrencePath.Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries);
string occurrenceName = filePathParts[filePathParts.Length - 1];
ACW.File[] occurrenceSearchResults = searchForFileNameInVault(mWsMgr, occurrenceName);
foreach (ACW.File resultsFile in occurrenceSearchResults)
{
if (resultsFile.Name.Contains(".iam") || resultsFile.Name.Contains(".ipt"))
{
if (!resultsFile.Name.Contains(".dwf"))
{
string mDocPath = AcquireFileForInventorAndGetPath(connection, mWsMgr, resultsFile);
ApprenticeServerComponent newApprentice = new ApprenticeServerComponent();
ApprenticeServerDocument apprenticeDocument = newApprentice.Open(mDocPath);
//ApprenticeServerDocument apprenticeDocument = InstantiateAndOpenApprentice(resultsFile, connection, mWsMgr);
iterateBOM(apprenticeDocument.ComponentDefinition.Occurrences, connection, mWsMgr, BOM);
}
}
}
}
else
{
MessageBox.Show(occurrence.Name, "Occurrence Part");
UpdateBomDictionary(occurrence, BOM);
}
}
}
}
public static void UpdateBomDictionary(ComponentOccurrence occurrence, Dictionary<string, BomItem> BOM)
{
string occurrencePath = occurrence.ReferencedDocumentDescriptor.FullDocumentName;
string[] filePathParts = occurrencePath.Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries);
string occurrenceName = filePathParts[filePathParts.Length - 1];
if (BOM.ContainsKey(occurrenceName) == false)
{
BomItem newItem = new BomItem();
newItem.FullFileName = occurrenceName;
newItem.Quantity = 1;
BOM.Add(occurrenceName, newItem);
}
else
{
BOM[occurrenceName].Quantity += 1;
}
}
public static string AcquireFileForInventorAndGetPath(Connection connection, WebServiceManager mWsMgr, ACW.File selectedContextFile)
{
VDF.Vault.Settings.AcquireFilesSettings mDownloadSettings = new VDF.Vault.Settings.AcquireFilesSettings(connection);
mDownloadSettings.OrganizeFilesRelativeToCommonVaultRoot = true;
mDownloadSettings.AddFileToAcquire(new VDF.Vault.Currency.Entities.FileIteration(connection, selectedContextFile), VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);
VDF.Vault.Results.AcquireFilesResults mDownLoadResult = connection.FileManager.AcquireFiles(mDownloadSettings);
VDF.Vault.Results.FileAcquisitionResult fileAcquisitionResult = mDownLoadResult.FileResults.Where(n => n.File.EntityName == selectedContextFile.Name).FirstOrDefault();
string mDocPath = fileAcquisitionResult.LocalPath.FullPath;
string mExt = System.IO.Path.GetExtension(mDocPath);
return mDocPath;
}
I am really not sure what is wrong if it was working one moment, not working another. Does anything appear wrong in my code? Anything else I might be missing?
Solved! Go to Solution.