public bool DetermineDocumentType(ValidDocumentType validDocumentType, UpdateProgressBar updateProgressBar) { DocumentTypeEnum currentDocumentType; try { currentDocumentType = thisApplication.ActiveDocument.DocumentType; if (DocumentInfo.IsAssemblyDocument(currentDocumentType)) { topLevel.TraverseAssembly((AssemblyDocument)thisApplication.ActiveDocument, 0); validDocumentType(true); return(true); } else if ((DocumentInfo.IsPartDocument(currentDocumentType))) { validDocumentType(false); return(false); } else { validDocumentType(false); return(false); } } catch (Exception e) { validDocumentType(false); updateProgressBar(true); EventLogger.CreateLogEntry(e.Message + " " + e.StackTrace); return(false); } }
//Builds the Assembly, Part and Sheetmetal part objects using recursion public void TraverseAssembly(AssemblyDocument currentAsmDocument, int parentID) { int currentID = GetAssemblyID(); //to stop instantiating a new instance of Assembly with a null AssemblyDocument - should never happen anyway if (currentAsmDocument == null) { return; } Assembly assembly = NewAssembly(currentAsmDocument, parentID, currentID); EventLogger.CreateLogEntry($"Processing assembly document {assembly.AssemblyDocument.DisplayName}"); AssemblyList.Add(assembly); ComponentOccurrences occurrences = currentAsmDocument.ComponentDefinition.Occurrences; noOccurrences += occurrences.Count; EventLogger.CreateLogEntry($"Current part count {noOccurrences}"); foreach (ComponentOccurrence occurrence in occurrences) { //the UI layer is listening for this Event to increment the progress bar IncrementProgressBar(); if (DocumentInfo.IsPartDocument(occurrence.DefinitionDocumentType)) { PartDocument partDocument = (PartDocument)occurrence.Definition.Document; EventLogger.CreateLogEntry($"processing part document {partDocument.DisplayName}"); if (DocumentInfo.IsSheetMetalPart(partDocument.SubType)) { assembly.SheetmetalPartList.Add(NewSheetMetalPart(partDocument)); } else { assembly.PartList.Add(NewPart(partDocument)); } } if (DocumentInfo.IsAssemblyDocument(occurrence.DefinitionDocumentType)) { AssemblyDocument subAssemblyDocument = (AssemblyDocument)occurrence.Definition.Document; TraverseAssembly(subAssemblyDocument, assembly.ID); } } }