예제 #1
0
    public void Collect()
    {
        string      fullpath = (SwApp.ActiveDoc as ModelDoc2).GetPathName();
        SWTableType swt      = null;
        ModelDoc2   md       = (ModelDoc2)SwApp.ActiveDoc;

        try {
            swt = new SWTableType(md, Hashes);
        } catch (SWTableTypeException te) {
            OnAppend(new AppendEventArgs(string.Format("{0} {1}", te.Message, md.GetTitle())));
            System.Diagnostics.Debug.WriteLine(te.Message);
        } catch (Exception e) {
            OnAppend(new AppendEventArgs(e.Message));
            System.Diagnostics.Debug.WriteLine(e.Message);
        }
        FileInfo fi = new FileInfo(fullpath);

        create_dwg(fi);
        OnAppend(new AppendEventArgs(string.Format("Added {0}...", fi.Name)));
        FileInfo top_level = d.GetPath(Path.GetFileNameWithoutExtension(fullpath));

        lfi.Add(top_level);
        OnAppend(new AppendEventArgs(string.Format(@"Using {0}...", swt.found_bom.Name)));
        collect_drwgs(md, swt, 1);
        OnDone(EventArgs.Empty);
    }
예제 #2
0
 private string find_part_column(SWTableType swt)
 {
     foreach (string s in swt.Columns)
     {
         if (s.ToUpper().Contains("PART"))
         {
             return(s);
         }
     }
     return("PART NUMBER");
 }
예제 #3
0
    private void collect_drwgs(ModelDoc2 md, SWTableType swt, int lvl)
    {
        string title = md.GetTitle();

        List <FileInfo> ss = new List <FileInfo>();

        if (swt != null)
        {
            string part = string.Empty;
            bool   in_lfi;
            bool   in_nf;
            for (int i = 1; i < swt.RowCount; i++)
            {
                string          ap_arg_ = string.Format(@"item: {0} ({1})", part, swt.GetProperty(i, @"DESCRIPTION"));
                AppendEventArgs a_      = new AppendEventArgs(ap_arg_);
                OnAppend(a_);
                part = swt.GetProperty(i, swt.PartColumn);
                if (!part.StartsWith("0"))
                {
                    FileInfo partpath = swt.get_path2(part);
                    string   t        = string.Empty;
                    try {
                        t = partpath.FullName.ToUpper();
                    } catch (NullReferenceException) {
                        // it's OK
                    }
                    string ext = Path.GetExtension(t).ToUpper();
                    if (t.Length < 1)
                    {
                        continue;
                    }
                    FileInfo dwg = new FileInfo(t.Replace(ext, ".SLDDRW"));
                    FileInfo fi  = new FileInfo(t.Replace(ext, targetExt));
                    if (!dwg.Exists)
                    {
                        string   filename  = Path.GetFileNameWithoutExtension(t);
                        FileInfo maybe_md_ = new FileInfo(t.Replace(filename, part));
                        if (maybe_md_.Exists)
                        {
                            dwg = new FileInfo(maybe_md_.FullName.Replace(ext, ".SLDDRW"));
                        }
                    }
                    if (dwg.Exists && !fi.Exists)
                    {
                        create_dwg(dwg);
                        fi = new FileInfo(fi.FullName);
                        SwApp.CloseDoc(dwg.FullName);
                    }
                    in_lfi = is_in(part, lfi);
                    in_nf  = is_in(part, nf);
                    if (dwg != null)
                    {
                        if (!in_lfi && fi.Exists)
                        {
                            ss.Add(fi);
                            OnAppend(new AppendEventArgs(string.Format("Added {0}", fi.Name)));
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (!in_nf)
                        {
                            nf.Add(new KeyValuePair <string, string>(part, title));
                            OnAppend(new AppendEventArgs(string.Format("{0} NOT found", part)));
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Skipping " + part);
                }
            }

            lfi.AddRange(ss);
        }
        string indent = string.Empty;

        if (Recurse)
        {
            foreach (FileInfo f in ss)
            {
                for (int i = 0; i < lvl; i++)
                {
                    indent = indent + " > ";
                }
                if (f != null)
                {
                    string doc = f.FullName.ToUpper().Replace(targetExt, ".SLDDRW");
                    OnAppend(new AppendEventArgs(string.Format("{0} Opening '{1}'...", indent, doc)));
                    SwApp.OpenDoc(doc, (int)swDocumentTypes_e.swDocDRAWING);
                    SwApp.ActivateDoc(doc);
                    ModelDoc2   m        = (ModelDoc2)SwApp.ActiveDoc;
                    SWTableType innerswt = null;
                    try {
                        innerswt = new SWTableType(m, Hashes);
                        OnAppend(new AppendEventArgs(string.Format("{0} Found table: {1}", indent, innerswt.found_bom.Name)));
                    } catch (Exception e) {
                        System.Diagnostics.Debug.WriteLine(e.Message);
                    }
                    System.Diagnostics.Debug.WriteLine("ss   : " + f.Name);
                    System.Diagnostics.Debug.WriteLine(doc);
                    collect_drwgs(m, innerswt, ++lvl);
                    OnAppend(new AppendEventArgs(string.Format("{0} Closing '{1}'...", indent, doc)));
                    indent = string.Empty;
                    --lvl;
                    SwApp.CloseDoc(doc);
                }
            }
        }
    }