Exemplo n.º 1
0
        private void rowDelete(BOMView bomView, DataGridView _dgv)
        {
            bool remove = true;

            foreach (DataGridViewRow dgvr in _dgv.Rows)
            {
                if (dgvr.Cells[3].Value != null && dgvr.Cells[2].Value.ToString() != "")
                {
                    foreach (Inventor.BOMRow row in m_BOMView.BOMRows)
                    {
                        oCompDef = row.ComponentDefinitions[1];
                        oDoc     = (Inventor.Document)oCompDef.Document;
                        string partNumber = (string)oDoc.PropertySets[3][2].Value;
                        string desc       = (string)oDoc.PropertySets[3][14].Value;
                        string key        = (string)oDoc.PropertySets[1][4].Value.ToString();
                        string pos        = (string)row.ItemNumber;
                        partNumber = partNumber.Trim();
                        if (partNumber == dgvr.Cells[3].Value.ToString() && desc == dgvr.Cells[4].Value.ToString())
                        {
                            remove = false;
                            break;
                        }
                    }
                    if (remove && dgvr.Cells[4].Value.ToString().StartsWith("p"))
                    {
                        _dgv.Rows.Remove(dgvr);
                    }
                    remove = true;
                }
            }
        }
Exemplo n.º 2
0
        public static void saveData(AssemblyDocument m_AsmDoc)
        {
            XDocument xd = new XDocument();

            InvDoc.InvDocument <AssemblyDocument> iDoc = new InvDoc.InvDocument <AssemblyDocument>(m_AsmDoc);
            iDoc.doc = (Document)m_AsmDoc;
            string name = iDoc.path + iDoc.getProp("Part Number").Value + ".xml";
            //tbl.saveDataInXML(xd,"Data",name, false);
            BOM    m_BOM         = m_AsmDoc.ComponentDefinition.BOM;
            string partNumberAsm = m_AsmDoc.PropertySets[3][2].Value.ToString();

            m_BOM.StructuredViewEnabled = true;
            // if (!m_BOM.StructuredViewFirstLevelOnly)
            // m_BOM.StructuredViewFirstLevelOnly = true;
            if (m_BOM.StructuredViewFirstLevelOnly)
            {
                m_BOM.StructuredViewFirstLevelOnly = false;
            }
            BOMView  m_BOMView = m_BOM.BOMViews["Структурированный"];
            TableInv tbl       = null;

            tbl = new TableInv(m_AsmDoc, @"C:\ProgramData\Autodesk\Inventor Addins\Sequence.xml");
            tbl.addTable(m_BOMView);
            tbl.saveDataInXML(xd, "Data", name, false);
        }
Exemplo n.º 3
0
        public void BomAccess()
        {
            AssemblyDocument            oDoc = (AssemblyDocument)_InvApplication.ActiveDocument;
            AssemblyComponentDefinition oDef = oDoc.ComponentDefinition;

            BOM oBOM = default(BOM);

            oBOM = oDef.BOM;

            oBOM.StructuredViewEnabled = true;

            BOMView oBomView = oBOM.BOMViews["Structured"];

            int rowIdx = 0;

            for (rowIdx = 1; rowIdx <= oBomView.BOMRows.Count; rowIdx++)
            {
                BOMRow oRow = oBomView.BOMRows[rowIdx];

                Debug.Print("ItemNumber: " + oRow.ItemNumber + " TotalQuantity = " + oRow.TotalQuantity);

                ComponentDefinition oCompDef = oRow.ComponentDefinitions[1];

                PropertySet oDesignPropSet = default(PropertySet);
                oDesignPropSet = oCompDef.Document.PropertySets("Design Tracking Properties");
            }
        }
Exemplo n.º 4
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());
            }
        }
Exemplo n.º 5
0
        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());
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        public void UpdateMaterial(Document bomItem)
        {
            AssemblyDocument asmDoc;

            if (bomItem.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
            {
                asmDoc = (AssemblyDocument)bomItem;

                AssemblyComponentDefinition compDef = asmDoc.ComponentDefinition;
                BOM bom = compDef.BOM;
                bom.StructuredViewFirstLevelOnly = true;

                bom.StructuredViewEnabled = true;

                BOMView bomView = bom.BOMViews["Structured"];

                QueryBOM(bomView.BOMRows);
            }
        }
Exemplo n.º 8
0
        //public TableData Load()
        //{
        //    var loginUser = _auth.GetCurrentUser();


        //    IQueryable<TF_BOM> query = UnitWork.Find<TF_BOM>(null);

        //    var userOrgs = from user in query
        //                   join relevance in UnitWork.Find<Relevance>(u => u.Key == "UserOrg")
        //                       on user.Id equals relevance.FirstId into temp
        //                   from r in temp.DefaultIfEmpty()
        //                   join org in UnitWork.Find<Org>(null)
        //                       on r.SecondId equals org.Id into orgtmp
        //                   from o in orgtmp.DefaultIfEmpty()
        //                   select new
        //                   {
        //                       user.Account,
        //                       user.Name,
        //                       user.Id,
        //                       user.Sex,
        //                       user.Status,
        //                       user.BizCode,
        //                       user.CreateId,
        //                       user.CreateTime,
        //                       user.TypeId,
        //                       user.TypeName,
        //                       r.Key,
        //                       r.SecondId,
        //                       OrgId = o.Id,
        //                       OrgName = o.Name
        //                   };

        //    //如果请求的orgId不为空
        //    if (!string.IsNullOrEmpty(request.orgId))
        //    {
        //        var org = loginUser.Orgs.SingleOrDefault(u => u.Id == request.orgId);
        //        var cascadeId = org.CascadeId;

        //        var orgIds = loginUser.Orgs.Where(u => u.CascadeId.Contains(cascadeId)).Select(u => u.Id).ToArray();

        //        //只获取机构里面的用户
        //        userOrgs = userOrgs.Where(u => u.Key == Define.USERORG && orgIds.Contains(u.OrgId));
        //    }
        //    else  //todo:如果请求的orgId为空,即为跟节点,这时可以额外获取到机构已经被删除的用户,从而进行机构分配。可以根据自己需求进行调整
        //    {
        //        var orgIds = loginUser.Orgs.Select(u => u.Id).ToArray();

        //        //获取用户可以访问的机构的用户和没有任何机构关联的用户(机构被删除后,没有删除这里面的关联关系)
        //        userOrgs = userOrgs.Where(u => (u.Key == Define.USERORG && orgIds.Contains(u.OrgId)) || (u.OrgId == null));
        //    }



        //    var userViews = userOrgs.ToList().GroupBy(b => b.Account).Select(u => new UserView
        //    {
        //        Id = u.First().Id,
        //        Account = u.Key,
        //        Name = u.First().Name,
        //        Sex = u.First().Sex,
        //        Status = u.First().Status,
        //        CreateTime = u.First().CreateTime,
        //        CreateUser = u.First().CreateId,
        //        OrganizationIds = string.Join(",", u.Select(x => x.OrgId))
        //        ,
        //        Organizations = string.Join(",", u.Select(x => x.OrgName))

        //    });

        //    return new TableData
        //    {
        //        count = userViews.Count(),
        //        data = userViews.OrderBy(u => u.Name)
        //            .Skip((request.page - 1) * request.limit)
        //            .Take(request.limit),
        //    };
        //}


        public List <BOMView> ConvertToSelectModel(DataTable dt)
        {
            // 定义集合
            List <BOMView> ts = new List <BOMView>();

            if (dt == null)
            {
                return(ts);
            }

            // 获得此模型的类型
            Type   type     = typeof(BOMView);
            string tempName = "";

            foreach (DataRow dr in dt.Rows)
            {
                BOMView t = new BOMView();
                // 获得此模型的公共属性
                PropertyInfo[] propertys = t.GetType().GetProperties();
                foreach (PropertyInfo pi in propertys)
                {
                    tempName = pi.Name;  // 检查DataTable是否包含此列

                    if (dt.Columns.Contains(tempName))
                    {
                        // 判断此属性是否有Setter
                        if (!pi.CanWrite)
                        {
                            continue;
                        }

                        object value = dr[tempName];
                        if (value != DBNull.Value)
                        {
                            pi.SetValue(t, value.ToString(), null);
                        }
                    }
                }
                ts.Add(t);
            }
            return(ts);
        }
 private void RenumberFrame(Component component)
 {
     try
     {
         AssemblyDocument assembly = (AssemblyDocument)inventorApp.Documents.Open(component.FullFileName, false);
         // Get BOM
         BOM bom = assembly.ComponentDefinition.BOM;
         bom.StructuredViewFirstLevelOnly = false;
         bom.StructuredViewEnabled        = true;
         // Set a reference to the "Structured" BOMView
         BOMView bomView = bom.BOMViews["Структурированный"];
         // Get component of Frame
         component.Level = 1;
         SetPartNumbersInFrameRecursive(bomView.BOMRows, component);
         componentsToReplace.Add(component);
     }
     catch (Exception ex)
     {
         System.Windows.MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK);
     }
 }
Exemplo n.º 10
0
        public void ExportBOM()
        {
            AssemblyDocument            oDoc = (AssemblyDocument)_InvApplication.ActiveDocument;
            AssemblyComponentDefinition oDef = oDoc.ComponentDefinition;

            BOM oBOM = oDef.BOM;

            // Set the structured view to 'all levels'
            oBOM.StructuredViewFirstLevelOnly = false;

            // Make sure that the structured view is enabled.
            oBOM.StructuredViewEnabled = true;

            // Set a reference to the "Structured" BOMView
            BOMView oStructuredBOMView = default(BOMView);

            oStructuredBOMView = oBOM.BOMViews["Structured"];

            // Export the BOM view to an Excel file
            oStructuredBOMView.Export("C:\\Temp\\BOM-StructuredAllLevels.xls", FileFormatEnum.kMicrosoftExcelFormat);
        }
        /// <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;
            }
        }
Exemplo n.º 12
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);
            }
        }
        private void SearchSheetMetalKits(Component component)
        {
            try
            {
                AssemblyDocument assembly = (AssemblyDocument)inventorApp.Documents.Open(component.FullFileName, false);
                // Get BOM
                BOM bom = assembly.ComponentDefinition.BOM;
                bom.StructuredViewFirstLevelOnly = false;
                bom.StructuredViewEnabled        = true;
                // Set a reference to the "Structured" BOMView
                BOMView bomView = bom.BOMViews["Структурированный"];

                foreach (BOMRow row in bomView.BOMRows)
                {
                    ComponentDefinition componentDefinition = row.ComponentDefinitions[1];
                    if (!(componentDefinition is VirtualComponentDefinition))
                    {
                        if (componentDefinition is AssemblyComponentDefinition)
                        {
                            AssemblyDocument locAssembly = (AssemblyDocument)componentDefinition.Document;
                            string           filePath    = locAssembly.FullFileName;
                            // Check whether assembly in casing subdirectory
                            if (filePath.IndexOf(casingDirectory) >= 0)
                            {
                                ReNumberSheetMetalKit(locAssembly, row.ChildRows);
                            }
                        }
                    }
                }
                assembly.Close();
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// returns BOMQuantity of specified document in the assembly document.
        /// BOMQuantity gives you access to quantity units and such.
        /// </summary>
        /// <param name="targetDoc">Target document to be queried should be non-phantom, non-reference</param>
        /// <param name="assembly">assembly where the document resides</param>
        /// <param name="bomViewType">type of bom view defined in inventor assembly environment</param>
        /// <returns>BOMQuantity</returns>
        public BOMQuantity GetBomQuantity(Document targetDoc, AssemblyDocument assembly, BOMViewTypeEnum bomViewType)
        {
            if (targetDoc == null)
            {
                throw new ArgumentNullException(nameof(targetDoc), "Null argument");
            }
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly), "Null argument");
            }

            if (targetDoc.DocumentType == DocumentTypeEnum.kUnknownDocumentObject)
            {
                throw new ArgumentException(nameof(targetDoc), "Unknown document");
            }

            //Get the ActiveLevelOfDetailRepresentation Name
            string MyLOD_Name;

            MyLOD_Name = assembly.ComponentDefinition.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name;

            if (MyLOD_Name != "Master")
            {
                //activate master because only it can do the trick
                assembly.ComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations[1].Activate();
            }

            //Get Bom Object
            var oBOM = assembly.ComponentDefinition.BOM;
            //define a bomView object
            BOMView bomView = assembly.ComponentDefinition.BOM.BOMViews["Structured"];

            switch (bomViewType)
            {
            case BOMViewTypeEnum.kModelDataBOMViewType:
                break;

            case BOMViewTypeEnum.kStructuredBOMViewType:
                //Make sure structured view is enabled
                oBOM.StructuredViewEnabled        = true;
                oBOM.StructuredViewFirstLevelOnly = true;
                bomView = assembly.ComponentDefinition.BOM.BOMViews["Structured"];
                break;

            case BOMViewTypeEnum.kPartsOnlyBOMViewType:
                //Make sure parts only view is enabled
                oBOM.PartsOnlyViewEnabled = true;
                bomView = assembly.ComponentDefinition.BOM.BOMViews["Parts Only"];
                break;

            default:
                break;
            }
            //look for the targetDoc in assembly
            foreach (BOMRow row in bomView.BOMRows)
            {
                if (row.ComponentDefinitions[1].Document == targetDoc)
                {
                    return(row.ComponentDefinitions[1].BOMQuantity);
                }
            }
            //at this stage the targetDoc is not found int the assembly
            return(null);
        }
Exemplo n.º 15
0
        private DataTable GetDataTable(Component specComponent)
        {
            DataTable resultTable = new DataTable();

            // Format table
            resultTable.Columns.Add("VPNumber", typeof(string));             // Code from purchase roll
            resultTable.Columns.Add("PartNumber", typeof(string));
            resultTable.Columns.Add("Description", typeof(string));
            resultTable.Columns.Add("Quantity", typeof(string));
            resultTable.Columns.Add("IsConsumable", typeof(bool));
            resultTable.Columns.Add("UnitOfMeasure", typeof(string));
            try
            {
                AssemblyDocument assembly = (AssemblyDocument)inventorApp.Documents.Open(specComponent.FullFileName, false);
                // Get BOM
                BOM bom = assembly.ComponentDefinition.BOM;
                bom.StructuredViewFirstLevelOnly = false;
                bom.StructuredViewEnabled        = true;
                // Get merge settings
                bool     mergeEnabled     = false;
                string[] mergeExcludeList = new string[] { "жопа" };
                bom.GetPartNumberMergeSettings(out mergeEnabled, out mergeExcludeList);
                // Set merge settings to false temporarily
                bom.SetPartNumberMergeSettings(false, mergeExcludeList);
                // Set a reference to the "Structured" BOMView
                BOMView bomView = bom.BOMViews["Структурированный"];


                foreach (BOMRow BOMrow in bomView.BOMRows)
                {
                    DataRow             row = resultTable.NewRow();
                    ComponentDefinition componentDefinition = BOMrow.ComponentDefinitions[1];
                    Document            locDoc   = (Document)componentDefinition.Document;
                    PropertySet         oPropSet = locDoc.PropertySets["Design Tracking Properties"];
                    row["PartNumber"]  = oPropSet["Part Number"].Value.ToString();
                    row["Description"] = oPropSet["Description"].Value.ToString();
                    oPropSet           = locDoc.PropertySets["Inventor User Defined Properties"];
                    if (Library.HasInventorProperty(oPropSet, "Расходник"))
                    {
                        row["IsConsumable"] = oPropSet["Расходник"].Value;
                    }
                    else
                    {
                        row["IsConsumable"] = false;
                    }
                    row["Quantity"] = BOMrow.TotalQuantity;
                    // Add row
                    resultTable.Rows.Add(row);
                }

                // Restore BOM merge settings
                bom.SetPartNumberMergeSettings(mergeEnabled, mergeExcludeList);
                if (specComponent.FullFileName != mainComponent.FullFileName)
                {
                    assembly.Close();
                }
                return(resultTable);
            }

            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK);
                return(null);
            }
        }