/// <summary> /// Get parameter data from an existing variant. /// </summary> /// <param name="VarList">Reference to the class that will store the gathered parameter data.</param> public void Get_Variants(ref Var_Type VarList) { try { IProject project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject() as IProject; IProjectVariant Variant; IComponentVariation CompVariant; IParameterVariation ParamVariant; VarParam <string, string> Parameters = new VarParam <string, string>(); string RefDes; int l = 0; for (int i = 0; i < project.DM_ProjectVariantCount(); i++) { l++; Variant = project.DM_ProjectVariants(i); //Find the variant that matches the one provided. if (project.DM_ProjectVariants(i).DM_Description().ToUpper() == VarList.VarName) { Progress.Maximum = Variant.DM_VariationCount(); Progress.Value = 0; UpdateLabel("Loading Variants"); for (int j = 0; j < Variant.DM_VariationCount(); j++) { CompVariant = Variant.DM_Variations(j); RefDes = CompVariant.DM_PhysicalDesignator(); //checking to make sure all components have a refdes assigned. if (RefDes.Contains("?")) { MessageBox.Show("Detected an un-annotated refdes. Please Annotate the project and try again."); VarList = null; return; } Parameters = new VarParam <string, string>(); //Iterate through all parameters for current component variant. for (int k = 0; k < CompVariant.DM_VariationCount(); k++) { if (CompVariant.DM_VariationKind() != TVariationKind.eVariation_NotFitted) { ParamVariant = CompVariant.DM_Variations(k); //Get values of matching parameters. if ("PE_ENG" == ParamVariant.DM_ParameterName().ToUpper() || ParamVariant.DM_ParameterName().ToUpper() == "PE_FLT") { string tmpVarValue = ParamVariant.DM_VariedValue() == null ? "x" : ParamVariant.DM_VariedValue(); Parameters.Add(ParamVariant.DM_ParameterName().ToUpper(), tmpVarValue); if (!tmpVarValue.EndsWith("_$")) { ParamVariant.DM_SetVariedValue(tmpVarValue + "_$"); } } } } l++; //Save collected data to VarList. if (Parameters.Count > 0) { VarList.Components.Add(RefDes, Parameters); } Progress.Value += 1; UpdateLabel("Loading Variants"); } } } } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return; } }
/// <summary> /// Get parameter data from the base design. /// </summary> /// <param name="VarList">Reference to the class that will store the gathered parameter data.</param> public void GetBaseVariants(ref Var_Type VarList) { try { IDXPWorkSpace CurrentWorkspace = DXP.GlobalVars.DXPWorkSpace; IDXPProject CurrentProject; int LogicalDocumentCount; int LoopIterator; IDXPDocument CurrentSheet; CurrentProject = CurrentWorkspace.DM_FocusedProject(); LogicalDocumentCount = CurrentProject.DM_LogicalDocumentCount(); ISch_ServerInterface SchServer = SCH.GlobalVars.SchServer; IClient Client = DXP.GlobalVars.Client; IServerDocument ServerDoc; IDXPDocument ActiveDoc = DXP.GlobalVars.DXPWorkSpace.DM_FocusedDocument(); //Save current open document so it can be reopened after process is done. VarParam <string, string> Parameters = new VarParam <string, string>(); string RefDes; bool DocOpened = false; Progress.Value = 0; Progress.Maximum = LogicalDocumentCount; UpdateLabel("Loading Variants"); //iterate through project documents. for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++) { CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1); //Check for schematic documents. if (CurrentSheet.DM_DocumentKind() == "SCH") { DocOpened = false; //Open documents if (Client.IsDocumentOpen(CurrentSheet.DM_FullPath())) { ServerDoc = Client.GetDocumentByPath(CurrentSheet.DM_FullPath()); DocOpened = true; } else { ServerDoc = Client.OpenDocument("SCH", CurrentSheet.DM_FullPath()); } //Client.ShowDocument(ServerDoc); ISch_Lib SchDoc; SchDoc = SchServer.LoadSchDocumentByPath(CurrentSheet.DM_FullPath()) as ISch_Lib; ISch_Iterator LibraryIterator, PIterator; ISch_Component Component; ISch_Parameter Param; if (SchDoc == null) { return; } //Iterate theough all components on the schematic. LibraryIterator = SchDoc.SchIterator_Create(); LibraryIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eSchComponent)); Component = LibraryIterator.FirstSchObject() as ISch_Component; while (Component != null) { if (Component.GetState_SchDesignator().GetState_Text().Contains("?")) { MessageBox.Show("Detected and un-annotated refdes. Please Annotate the project and try again."); VarList = null; return; } RefDes = Component.GetState_SchDesignator().GetState_Text(); Parameters = new VarParam <string, string>(); //Iterate theough all parameters in the component. PIterator = Component.SchIterator_Create(); PIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eParameter)); Param = PIterator.FirstSchObject() as ISch_Parameter; while (Param != null) { if (Param.GetState_Name() != null) { //Store specific parameter data. if ("PE_ENG" == Param.GetState_Name().ToUpper() || Param.GetState_Name().ToUpper() == "PE_FLT") { if (Param.GetState_Text() != "x") { Parameters.Add(Param.GetState_Name().ToUpper(), Param.GetState_CalculatedValueString()); } } } Param = PIterator.NextSchObject() as ISch_Parameter; } //Add stored parameter data to VarList. if (Parameters.Count > 0) { if (!VarList.Components.ContainsKey(RefDes)) { VarList.Components.Add(RefDes, Parameters); } } Component = LibraryIterator.NextSchObject() as ISch_Component; } //if (ServerDoc.GetModified()) // ServerDoc.DoFileSave(""); //Close opend documents. if (!DocOpened) { Client.CloseDocument(ServerDoc); } ServerDoc = null; } Progress.Value += 1; UpdateLabel("Loading Variants"); } Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath())); return; } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return; } }
/// <summary> /// Load parameter data from excel doc. /// </summary> /// <param name="Path">Path to excel doc.</param> /// <returns></returns> Var_Type GetPEData(string Path) { pbProgress.Value = 0; UpdateLabel("Opening Excel Doc"); Excel.Application xlApp; Excel.Workbook xlWorkBook = null; Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; if (Path == "") { return(null); } xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(Path, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Var_Type Output = new Var_Type(); VarParam <string, string> tmpParams; string PE_Flt, PE_Eng, LibRef; try { Output.VarName = "ModBOM"; pbProgress.Maximum = 3; UpdateLabel("Getting Column Headers"); //Get column letters for specific column names. PE_Eng = GetColumn("PE_ENG", ref xlWorkSheet); pbProgress.Value = 1; UpdateLabel("Getting Column Headers"); PE_Flt = GetColumn("PE_FLT", ref xlWorkSheet); pbProgress.Value = 2; UpdateLabel("Getting Column Headers"); LibRef = GetColumn("LIBREF", ref xlWorkSheet); pbProgress.Value = 3; UpdateLabel("Getting Column Headers"); if (PE_Eng == "" || PE_Flt == "" || LibRef == "") { MessageBox.Show("One or more parameters are missing from the BOM. Please try again with a different BOM."); xlWorkBook.Close(false, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); return(null); } int Row = 2; int cnt = 0; while (xlWorkSheet.Range[LibRef + Row].Value2 != null) { Row++; cnt++; } pbProgress.Maximum = cnt; pbProgress.Value = 0; UpdateLabel("Reading Data"); Row = 2; //Read parameter data. while (xlWorkSheet.Range[LibRef + Row].Value2 != null) { //if (xlWorkSheet.Range[PE_Flt + Row].Value2.ToString() != "x" || xlWorkSheet.Range[PE_Eng + Row].Value2.ToString() != "x") //{ if (Output.Components.ContainsKey(xlWorkSheet.Range[LibRef + Row].Value2.ToString())) { MessageBox.Show("Multiple library references for " + xlWorkSheet.Range[LibRef + Row].Value2.ToString() + " in this BOM. First instance is used."); } else { if (xlWorkSheet.Range[PE_Flt + Row].Value2 == null) { xlWorkSheet.Range[PE_Flt + Row].Value2 = "x"; } if (xlWorkSheet.Range[PE_Eng + Row].Value2 == null) { xlWorkSheet.Range[PE_Eng + Row].Value2 = "x"; } if (xlWorkSheet.Range[PE_Flt + Row].Value2.ToString() == "x") { xlWorkSheet.Range[PE_Flt + Row].Value2 = "z"; } if (xlWorkSheet.Range[PE_Eng + Row].Value2.ToString() == "x") { xlWorkSheet.Range[PE_Eng + Row].Value2 = "z"; } tmpParams = new VarParam <string, string>(); tmpParams.Add(new KeyValuePair <string, string>("PE_ENG", xlWorkSheet.Range[PE_Eng + Row].Value2.ToString().Replace("'", ""))); tmpParams.Add(new KeyValuePair <string, string>("PE_FLT", xlWorkSheet.Range[PE_Flt + Row].Value2.ToString().Replace("'", ""))); Output.Components.Add(new KeyValuePair <string, VarParam <string, string> >(xlWorkSheet.Range[LibRef + Row].Value2.ToString(), tmpParams)); } //} Row++; pbProgress.Value++; UpdateLabel("Reading Data"); } //xlWorkBook.Close(false, misValue, misValue); //xlApp.Quit(); //releaseObject(xlWorkSheet); //releaseObject(xlWorkBook); //releaseObject(xlApp); //return Output; } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); Output = null; } xlWorkBook.Close(false, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); return(Output); }