private void collect_drwgs(ModelDoc2 md) { SWTableType swt = null; string title = md.GetTitle(); try { swt = new SWTableType(md, Properties.Settings.Default.TableHashes); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } 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++) { System.Diagnostics.Debug.WriteLine("table: " + swt.GetProperty(i, "PART NUMBER")); part = swt.GetProperty(i, "PART NUMBER"); if (!part.StartsWith("0")) { FileInfo fi = d.GetPath(part); in_lfi = is_in(part, lfi); in_nf = is_in(part, nf); if (fi != null) { if (!in_lfi) { ss.Add(fi); } else { break; } } else { if (!in_nf) { nf.Add(new KeyValuePair <string, string>(part, title)); } else { break; } } } else { System.Diagnostics.Debug.WriteLine("Skipping " + part); } } lfi.AddRange(ss); } if (ss.Count > 0) { foreach (FileInfo f in ss) { if (f != null) { string doc = f.FullName.ToUpper().Replace(@"K:\", @"G:\").Replace(".PDF", ".SLDDRW"); SwApp.OpenDoc(doc, (int)swDocumentTypes_e.swDocDRAWING); SwApp.ActivateDoc(doc); ModelDoc2 m = (ModelDoc2)SwApp.ActiveDoc; System.Diagnostics.Debug.WriteLine("ss : " + f.Name); System.Diagnostics.Debug.WriteLine(doc); collect_drwgs(m); SwApp.CloseDoc(doc); } } } }
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); } } } }