/// <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() { try { IDXPWorkSpace CurrentWorkspace = DXP.GlobalVars.DXPWorkSpace; IDXPProject CurrentProject; int LogicalDocumentCount; int LoopIterator; Dictionary <string, IComponentVariation> FltCompVar, EngCompVar; 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; IParameterVariation TempVar; int Matches; bool DocOpened = false; FltCompVar = Get_Variants("VAR_FLT"); EngCompVar = Get_Variants("VAR_ENG"); if (FltCompVar == null || EngCompVar == null) { return; } //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 SchIterator, PIterator; ISch_Component Component; ISch_Implementation Footprint; ISch_Parameter Param; if (SchDoc == null) { return; } //Iterate theough all components on the schematic. SchIterator = SchDoc.SchIterator_Create(); SchIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eSchComponent)); Component = SchIterator.FirstSchObject() as ISch_Component; while (Component != null) { Matches = 0; if (Component.GetState_SchDesignator().GetState_Text().Contains("?")) { MessageBox.Show("Detected and un-annotated refdes. Please Annotate the project and try again."); return; } RefDes = Component.GetState_SchDesignator().GetState_Text(); //Iterate theough all parameters in the component. PIterator = Component.SchIterator_Create(); PIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eImplementation)); Footprint = PIterator.FirstSchObject() as ISch_Implementation; if (FltCompVar.ContainsKey(RefDes)) { if (FltCompVar[RefDes].DM_AlternateLibraryLink().DM_Footprint() != Footprint.GetState_ModelName()) { TempVar = FltCompVar[RefDes].DM_FindParameterVariation("ClassName"); if (TempVar != null) { TempVar.DM_SetVariedValue("Stencil_Flt"); } Matches++; } } if (EngCompVar.ContainsKey(RefDes)) { if (EngCompVar[RefDes].DM_AlternateLibraryLink().DM_Footprint() != Footprint.GetState_ModelName()) { TempVar = EngCompVar[RefDes].DM_FindParameterVariation("ClassName"); if (TempVar != null) { TempVar.DM_SetVariedValue("Stencil_Eng"); } Matches++; } } //?Param.GetState_ModelName() //"FIDUCIAL_SMD" //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() == "ClassName") { if (Matches == 2) { Param.SetState_Text("Stencil_Base"); } else { Param.SetState_Text(""); } Component.UpdatePart_PostProcess(); break; } Param = PIterator.NextSchObject() as ISch_Parameter; } Component = SchIterator.NextSchObject() as ISch_Component; } //if (ServerDoc.GetModified()) // ServerDoc.DoFileSave(""); //Close opend documents. if (!DocOpened) { Client.CloseDocument(ServerDoc); } ServerDoc = null; } } Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath())); return; } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return; } }