Esempio n. 1
0
        /// <summary>
        /// Show a list of materials used. Doesn't seem overly useful.
        /// TODO: Make this button cool
        /// </summary>
        /// <param name="sender">Who clicked?</param>
        /// <param name="e">Any args?</param>
        private void btnMatList_Click(object sender, EventArgs e)
        {
            DataDisplay dd   = new DataDisplay();
            ModelDoc2   doc  = (ModelDoc2)PropertySet.SwApp.ActiveDoc;
            CutlistData cd   = PropertySet.CutlistData;
            string      name = string.Empty;

            swTableType.swTableType st;

            try {
                st = new swTableType.swTableType(doc, Redbrick.MasterHashes);
                cd.IncrementOdometer(CutlistData.Functions.MaterialList);
                DataTable stp = (DataTable)DictToPartList(st.GetParts(), cd);

                if (doc != null)
                {
                    name    = doc.GetPathName();
                    dd.Text = "Materials/Edges used in " + System.IO.Path.GetFileNameWithoutExtension(name);
                }

                var q = (from a in stp.AsEnumerable()
                         group a by a.Field <string>("Material") into x
                         orderby x.Key
                         select new { Material = x.Key, Count = x.Count() });

                var r = (from a in stp.AsEnumerable()
                         group a by a.Field <string>("EdgeFront") into x
                         where x.Key != string.Empty
                         orderby x.Key
                         select new { Edging = x.Key, Count = x.Count() });

                var s = (from a in stp.AsEnumerable()
                         group a by a.Field <string>("EdgeBack") into x
                         where x.Key != string.Empty
                         orderby x.Key
                         select new { Edging = x.Key, Count = x.Count() });

                var t = (from a in stp.AsEnumerable()
                         group a by a.Field <string>("EdgeLeft") into x
                         where x.Key != string.Empty
                         orderby x.Key
                         select new { Edging = x.Key, Count = x.Count() });

                var u = (from a in stp.AsEnumerable()
                         group a by a.Field <string>("EdgeRight") into x
                         where x.Key != string.Empty
                         orderby x.Key
                         select new { Edging = x.Key, Count = x.Count() });

                var v = (from a in q select a.Material)
                        .Union
                            (from b in r select b.Edging)
                        .Union
                            (from c in s select c.Edging)
                        .Union
                            (from d in t select d.Edging)
                        .Union
                            (from f in u select f.Edging);

                dd.Grid.DataSource = ListToDataTable(v.ToList());
                // heheheehe!
                dd.ColorRows((rw) => { return(rw.Cells["Material"].Value.ToString().Contains("TBD")); },
                             Color.Yellow,
                             Color.Red);
                dd.ShowDialog();
            } catch (NullReferenceException nre) {
                if (comboBox1.SelectedValue != null)
                {
                    Redbrick.InsertBOM(_swApp, (int)comboBox1.SelectedValue);
                }
                else
                {
                    Redbrick.InsertBOM(_swApp);
                }
                btnLookup_Click(this, new EventArgs());
            } catch (ArgumentOutOfRangeException aoore) {
                PropertySet.SwApp.SendMsgToUser2(@"No acceptable parts in BOM.",
                                                 (int)swMessageBoxIcon_e.swMbStop,
                                                 (int)swMessageBoxBtn_e.swMbOk);
            } catch (Exception ex) {
                PropertySet.SwApp.SendMsgToUser2(ex.Message, (int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk);
            }
        }
        /// <summary>
        /// Show a list of materials used. Doesn't seem overly useful.
        /// TODO: Make this button cool
        /// </summary>
        /// <param name="sender">Who clicked?</param>
        /// <param name="e">Any args?</param>
        private void btnMatList_Click(object sender, EventArgs e)
        {
            DataDisplay dd = new DataDisplay();
              ModelDoc2 doc = (ModelDoc2)PropertySet.SwApp.ActiveDoc;
              CutlistData cd = PropertySet.CutlistData;
              string name = string.Empty;
              swTableType.swTableType st;

              try {
            st = new swTableType.swTableType(doc, Redbrick.MasterHashes);
            cd.IncrementOdometer(CutlistData.Functions.MaterialList);
            DataTable stp = (DataTable)DictToPartList(st.GetParts(), cd);

            if (doc != null) {
              name = doc.GetPathName();
              dd.Text = "Materials/Edges used in " + System.IO.Path.GetFileNameWithoutExtension(name);
            }

            var q = (from a in stp.AsEnumerable()
                 group a by a.Field<string>("Material") into x
                 orderby x.Key
                 select new { Material = x.Key, Count = x.Count() });

            var r = (from a in stp.AsEnumerable()
                 group a by a.Field<string>("EdgeFront") into x
                 where x.Key != string.Empty
                 orderby x.Key
                 select new { Edging = x.Key, Count = x.Count() });

            var s = (from a in stp.AsEnumerable()
                 group a by a.Field<string>("EdgeBack") into x
                 where x.Key != string.Empty
                 orderby x.Key
                 select new { Edging = x.Key, Count = x.Count() });

            var t = (from a in stp.AsEnumerable()
                 group a by a.Field<string>("EdgeLeft") into x
                 where x.Key != string.Empty
                 orderby x.Key
                 select new { Edging = x.Key, Count = x.Count() });

            var u = (from a in stp.AsEnumerable()
                 group a by a.Field<string>("EdgeRight") into x
                 where x.Key != string.Empty
                 orderby x.Key
                 select new { Edging = x.Key, Count = x.Count() });

            var v = (from a in q select a.Material)
              .Union
              (from b in r select b.Edging)
              .Union
              (from c in s select c.Edging)
              .Union
              (from d in t select d.Edging)
              .Union
              (from f in u select f.Edging);

            dd.Grid.DataSource = ListToDataTable(v.ToList());
            // heheheehe!
            dd.ColorRows((rw) => { return rw.Cells["Material"].Value.ToString().Contains("TBD"); },
              Color.Yellow,
              Color.Red);
            dd.ShowDialog();
              } catch (NullReferenceException nre) {
            Redbrick.InsertBOM(_swApp);
            btnLookup_Click(this, new EventArgs());
              } catch (ArgumentOutOfRangeException aoore) {
            PropertySet.SwApp.SendMsgToUser2(@"No acceptable parts in BOM.",
              (int)swMessageBoxIcon_e.swMbStop,
              (int)swMessageBoxBtn_e.swMbOk);
              } catch (Exception ex) {
            PropertySet.SwApp.SendMsgToUser2(ex.Message, (int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk);
              }
        }
Esempio n. 3
0
        //private void insert_BOM() {
        //  ModelDoc2 md = (ModelDoc2)SwApp.ActiveDoc;
        //  DrawingDoc dd = (DrawingDoc)SwApp.ActiveDoc;
        //  ModelDocExtension ex = (ModelDocExtension)md.Extension;
        //  int bom_type = (int)swBomType_e.swBomType_PartsOnly;
        //  int bom_numbering = (int)swNumberingType_e.swNumberingType_Flat;
        //  int bom_anchor =(int)swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft;
        //  SolidWorks.Interop.sldworks.View v = GetFirstView(SwApp);

        //  if (dd.ActivateView(v.Name)) {
        //    v.InsertBomTable4(
        //      false,
        //      Properties.Settings.Default.BOMLocationX, Properties.Settings.Default.BOMLocationY,
        //      bom_anchor,
        //      bom_type,
        //      v.ReferencedConfiguration,
        //      Properties.Settings.Default.BOMTemplatePath,
        //      false,
        //      bom_numbering,
        //      false);
        //  }
        //}

        /// <summary>
        /// Show what will be uploaded to the as a cutlist, only with hardware and other oddments filtered out.
        /// </summary>
        /// <param name="sender">Who clicked?</param>
        /// <param name="e">Any args?</param>
        private void btnLookup_Click(object sender, EventArgs e)
        {
            DataDisplay dd = new DataDisplay();

            dd.swApp = _swApp;
            ModelDoc2   doc  = (ModelDoc2)PropertySet.SwApp.ActiveDoc;
            CutlistData cd   = PropertySet.CutlistData;
            string      name = string.Empty;

            swTableType.swTableType st;

            try {
                st = new swTableType.swTableType(doc, Redbrick.MasterHashes);
                cd.IncrementOdometer(CutlistData.Functions.ExamineBOM);
                DataTable stp = (DataTable)DictToPartList(st.GetParts(Redbrick.BOMFilter), cd);
                dd.PathIndex = st.PathList;
                if (doc != null)
                {
                    name    = doc.GetPathName();
                    dd.Text = System.IO.Path.GetFileNameWithoutExtension(name) + " cutlist BOM...";
                }

                dd.Grid.DataSource = stp;

                dd.ColorRows(
                    // λ! Wooo!
                    (r) => {
                    if (r.Cells["Update"].Value != null)
                    {
                        return(r.Cells["Update"].Value.ToString().ToUpper() == "YES");
                    }
                    else
                    {
                        return(false);
                    }
                },
                    Color.Red,
                    Color.Yellow
                    );

                dd.ShowDialog();
            } catch (NullReferenceException nre) {
                if (comboBox1.SelectedValue != null)
                {
                    Redbrick.InsertBOM(_swApp, (int)comboBox1.SelectedValue);
                }
                else
                {
                    Redbrick.InsertBOM(_swApp);
                }
                btnLookup_Click(this, new EventArgs());
            } catch (ArgumentOutOfRangeException aoore) {
                PropertySet.SwApp.SendMsgToUser2(@"No acceptable parts in BOM.",
                                                 (int)swMessageBoxIcon_e.swMbStop,
                                                 (int)swMessageBoxBtn_e.swMbOk);
            } catch (Exception ex) {
                PropertySet.SwApp.SendMsgToUser2(ex.Message,
                                                 (int)swMessageBoxIcon_e.swMbStop,
                                                 (int)swMessageBoxBtn_e.swMbOk);
            }
        }
        /// <summary>
        /// Show what will be uploaded to the as a cutlist, only with hardware and other oddments filtered out.
        /// </summary>
        /// <param name="sender">Who clicked?</param>
        /// <param name="e">Any args?</param>
        private void btnLookup_Click(object sender, EventArgs e)
        {
            DataDisplay dd = new DataDisplay();
              dd.swApp = _swApp;
              ModelDoc2 doc = (ModelDoc2)PropertySet.SwApp.ActiveDoc;
              CutlistData cd = PropertySet.CutlistData;
              string name = string.Empty;
              swTableType.swTableType st;

              try {
            st = new swTableType.swTableType(doc, Redbrick.MasterHashes);
            cd.IncrementOdometer(CutlistData.Functions.ExamineBOM);
            DataTable stp = (DataTable)DictToPartList(st.GetParts(Redbrick.BOMFilter), cd);
            dd.PathIndex = st.PathList;
            if (doc != null) {
              name = doc.GetPathName();
              dd.Text = System.IO.Path.GetFileNameWithoutExtension(name) + " cutlist BOM...";
            }

            dd.Grid.DataSource = stp;

            dd.ColorRows(
              // λ! Wooo!
              (r) => { return r.Cells["Update"].Value.ToString().ToUpper() == "YES"; },
              Color.Red,
              Color.Yellow
              );

            dd.ShowDialog();
              } catch (NullReferenceException nre) {
            Redbrick.InsertBOM(_swApp);
            btnLookup_Click(this, new EventArgs());
              } catch (ArgumentOutOfRangeException aoore) {
            PropertySet.SwApp.SendMsgToUser2(@"No acceptable parts in BOM.",
              (int)swMessageBoxIcon_e.swMbStop,
              (int)swMessageBoxBtn_e.swMbOk);
              } catch (Exception ex) {
            PropertySet.SwApp.SendMsgToUser2(ex.Message,
              (int)swMessageBoxIcon_e.swMbStop,
              (int)swMessageBoxBtn_e.swMbOk);
              }
        }