Beispiel #1
0
        /// <summary>
        /// it create a JSON file with BOM Data
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="eBomViewType"></param>
        public void GetBom(Document doc, BOMViewTypeEnum eBomViewType)
        {
            doc.Update();

            try
            {
                string                      viewType     = "Structured";
                AssemblyDocument            assemblyDoc  = doc as AssemblyDocument;
                AssemblyComponentDefinition componentDef = assemblyDoc.ComponentDefinition;

                LogTrace("Create BOM Object");
                BOM bom = componentDef.BOM;

                if (eBomViewType == BOMViewTypeEnum.kStructuredBOMViewType)
                {
                    bom.StructuredViewEnabled        = true;
                    bom.StructuredViewFirstLevelOnly = false;
                }
                else
                {
                    bom.PartsOnlyViewEnabled = true;
                    viewType = "Parts Only";
                }

                LogTrace("Create BOM Views");
                BOMViews bomViews = bom.BOMViews;

                LogTrace("Create BOM View");
                BOMView structureView = bomViews[viewType];

                JArray bomRows = new JArray();

                LogTrace("Get BOM Rows to Json");
                BOMRowsEnumerator rows = structureView.BOMRows;

                LogTrace("Start to generate BOM data ...");
                GetBomRowProperties(structureView.BOMRows, bomRows);

                LogTrace("Writing out bomRows.json");
                File.WriteAllText(currentDirectory + "/bomRows.json", bomRows.ToString());
                GetListOfDirectory(currentDirectory);
            }
            catch (Exception e)
            {
                LogError("Bom failed: " + e.ToString());
            }
        }
        public void GetBom(Document doc)
        {
            try
            {
                if (doc.DocumentType == DocumentTypeEnum.kPartDocumentObject)
                {
                    LogTrace("Part Document");
                    // Parts don't have a BOM
                    LogTrace("Writing out empty bomRows.json");
                    File.WriteAllText("bomRows.json", "No BOM");
                }
                else if (doc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
                {
                    LogTrace("Assembly Document");
                    AssemblyComponentDefinition assemblyComponentDef = ((AssemblyDocument)doc).ComponentDefinition;
                    BOM      bom           = assemblyComponentDef.BOM;
                    BOMViews bomViews      = bom.BOMViews;
                    BOMView  structureView = bomViews["Structured"];

                    JArray bomRows = new JArray();
                    GetBomRowProperties(structureView.BOMRows, bomRows);

                    LogTrace("Writing out bomRows.json");
                    File.WriteAllText("bomRows.json", bomRows.ToString());
                }
                else
                {
                    LogTrace("Unknown Document");
                    // unsupported doc type, throw exception
                    throw new Exception("Unsupported document type: " + doc.DocumentType.ToString());
                }

                ////BOM bom = componentDef.BOM;
                //BOMViews bomViews = bom.BOMViews;
                //BOMView structureView = bomViews["Structured"];

                //JArray bomRows = new JArray();
                //GetBomRowProperties(structureView.BOMRows, bomRows);

                //LogTrace("Writing out bomRows.json");
                //File.WriteAllText("bomRows.json", bomRows.ToString());
            }
            catch (Exception e)
            {
                LogError("Bom failed: " + e.ToString());
            }
        }
Beispiel #3
0
        private ExtractedBOM ProcessAssembly(AssemblyDocument doc)
        {
            using (new HeartBeat())
            {
                var extractedBOM = new ExtractedBOM
                {
                    Columns = new[]
                    {
                        new Shared.Column {
                            Label = "Row Number"
                        },
                        new Shared.Column {
                            Label = "Part Number"
                        },
                        new Shared.Column {
                            Label = "Quantity", Numeric = true
                        },
                        new Shared.Column {
                            Label = "Description"
                        },
                        new Shared.Column {
                            Label = "Material"
                        }
                    },
                };
                var rows = new List <object[]>();

                AssemblyComponentDefinition assemblyComponentDef = doc.ComponentDefinition;
                BOM      bom      = assemblyComponentDef.BOM;
                BOMViews bomViews = bom.BOMViews;

                // enable structured view in case of iAssembly
                if (assemblyComponentDef.IsiAssemblyFactory && bom.StructuredViewEnabled == false)
                {
                    bom.StructuredViewEnabled = true;
                }

                BOMView structureView = bomViews["Structured"];

                GetBomRowProperties(structureView.BOMRows, rows);

                extractedBOM.Data = rows.ToArray();

                return(extractedBOM);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Gets the BOM view associated with the specified name.
        /// </summary>
        /// <param name="views">The <see cref="BOMViews"/> instance that this extension method affects.</param>
        /// <param name="viewName">The name of the view to get.</param>
        /// <param name="value">When this method returns, contains the BOM view associated with the specified name,
        /// if the name is found; otherwise, the default value of the <paramref name="value"/> parameter.</param>
        /// <returns><c>true</c> if <paramref name="views"/> contains a view with the specified
        /// <paramref name="viewName"/>; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="views"/> is <c>null</c>.</exception>
        public static bool TryGetValue(this BOMViews views, String viewName, out BOMView value)
        {
            if (views == null)
            {
                throw new ArgumentNullException(nameof(views));
            }

            try
            {
                value = views[viewName];
                return(true);
            }
            catch (ArgumentException)
            {
                value = default(BOMView);
                return(false);
            }
            catch (COMException)
            {
                value = default(BOMView);
                return(false);
            }
        }