internal static List<Component2> GetConfigComponents(SwAddin swAddin, ModelDoc2 model, int configNumber) { List<Component2> outComps = new List<Component2>(); List<string> compsNames = GetComponentsNamesOnConfiguration(swAddin, model, configNumber); LinkedList<Component2> modelComponents = new LinkedList<Component2>(); swAddin.GetComponents(model.IGetActiveConfiguration().IGetRootComponent2(), modelComponents, true, false); foreach (var component in modelComponents) { if (component.IsSuppressed()) continue; string compName = Path.GetFileNameWithoutExtension(swAddin.GetModelNameWithoutSuffix(component.GetPathName())); foreach (string name in compsNames) { if (compName.Contains(name)) { outComps.Add(component); break; } } } return outComps; }
private static List<string> GetComponentsNamesOnConfiguration(SwAddin _mSwAddin, ModelDoc2 parentModel, int configNumber) { List<string> elems = new List<string>(); OleDbConnection oleDb; if (_mSwAddin.OpenModelDatabase(parentModel, out oleDb)) { using (oleDb) { OleDbCommand cm = new OleDbCommand("SELECT * FROM decors WHERE Number = " + configNumber, oleDb); OleDbDataReader rd = cm.ExecuteReader(); while (rd.Read()) { elems.Add((string)rd["Element"]); } rd.Close(); } } AssemblyDoc pmAssembly = parentModel as AssemblyDoc; if (pmAssembly != null) { var comps = new LinkedList<Component2>(); _mSwAddin.GetComponents(parentModel.IGetActiveConfiguration().IGetRootComponent2(), comps, true, false); foreach (Component2 comp in comps) { ModelDoc2 model = comp.IGetModelDoc(); AssemblyDoc aDoc = model as AssemblyDoc; if (aDoc != null) elems.AddRange(GetComponentsNamesOnConfiguration(_mSwAddin, model, configNumber)); } } return elems; }
internal static List<ModelDoc2> GetAllModelsWithMdb(SwAddin mSwAddin, ModelDoc2 swModel) { UserProgressBar pb; mSwAddin.SwApp.GetUserProgressBar(out pb); var list = new List<ModelDoc2>(); var outComps = new LinkedList<Component2>(); var faulsMod = new List<ModelDoc2>(); if (mSwAddin.GetComponents(swModel.IGetActiveConfiguration().IGetRootComponent2(), outComps, true, false)) { pb.Start(0, outComps.Count, "Перебор деталей"); int i = 0; foreach (var component in outComps) { if (component.IsSuppressed()) { i++; pb.UpdateProgress(i); continue; } var inModel = component.IGetModelDoc(); if (list.Contains(inModel)) { i++; pb.UpdateProgress(i); continue; } var comp = component; int errCount = 0; while ((inModel == null || mSwAddin.GetModelDatabaseFileName(inModel) == "") && errCount < 10) { if (comp != null) { comp = comp.GetParent(); if (comp != null && !comp.IsSuppressed()) { inModel = comp.IGetModelDoc(); } } errCount++; } if (errCount == 10 && inModel != null) { i++; pb.UpdateProgress(i); continue; } if (inModel != null && Path.GetFileNameWithoutExtension(inModel.GetPathName()).Contains("#"/* + mSwAddin.GetXNameForAssembly()*/) && !list.Contains(inModel) && !faulsMod.Contains(inModel)) CheckMdbForDecors(mSwAddin, inModel, list, comp, faulsMod); i++; pb.UpdateProgress(i); } pb.End(); } return list; }