/// <summary> /// Iterates through all schematic docs of the active project and /// changes the grid snap and aligns components based on parameters. /// </summary> /// <param name="SizeInMils">Desired grid size in mils.</param> /// <param name="AlignToGrid">True/False if components should be aligned to the new grid.</param> void ChangeGridSize(int SizeInMils, bool AlignToGrid = false) { try { IDXPWorkSpace CurrentWorkspace = DXP.GlobalVars.DXPWorkSpace; IDXPProject CurrentProject; int LogicalDocumentCount; int LoopIterator; IDXPDocument CurrentSheet; CurrentProject = CurrentWorkspace.DM_FocusedProject(); LogicalDocumentCount = CurrentProject.DM_LogicalDocumentCount(); ISch_Document SchDoc; 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. DXP.Utils.PercentInit("Updating Grid", LogicalDocumentCount); bool DocOpened = false; //Loop through each SCH document in project. for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++) { CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1); if (CurrentSheet.DM_DocumentKind() == "SCH") { DocOpened = false; SchDoc = CurrentSheet as ISch_Document; //Open document if not already open. 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); SetGrid(SizeInMils); //Set document grid size. ServerDoc.DoFileSave(""); //Save file. //Align parts to grid of active document. if (AlignToGrid) { this.AlignToGrid(); } if (!DocOpened & !AlignToGrid) { Client.CloseDocument(ServerDoc); } ServerDoc = null; } DXP.Utils.PercentUpdate(); } DXP.Utils.PercentFinish(); Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath())); return; } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return; } }
/// <summary> /// Updates base design parameters based on provided data. /// </summary> /// <param name="VarList">Parameter data</param> void SetBaseDesign(Var_Type VarList) { try { string RefDes; 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. Progress.Maximum = LogicalDocumentCount; Progress.Value = 0; UpdateLabel("Updating Variants"); bool DocOpened = false; //Iterate through all documents looking for scheatic docs. for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++) { CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1); if (CurrentSheet.DM_DocumentKind() == "SCH") { //Open document if not already open. DocOpened = false; 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; VarParam <string, string> CompVars = new VarParam <string, string>(); 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) { RefDes = Component.GetState_SchDesignator().GetState_Text(); if (VarList.Components.ContainsKey(Component.GetState_SchDesignator().GetState_Text())) { if (VarList.Components[Component.GetState_SchDesignator().GetState_Text()].Saved == false) { Component.UpdatePart_PreProcess(); CompVars = VarList.Components[Component.GetState_SchDesignator().GetState_Text()]; //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) { if (Param.GetState_Name().ToUpper() != null) { //Set parameter data in component if it is in the provided parameter data. //Param = null; if (CompVars.ContainsKey(Param.GetState_Name().ToUpper())) { if (Param.GetState_Text() == "x") { Param.SetState_Text(CompVars[Param.GetState_Name().ToUpper()]); } else if (OverwriteValue(Param.GetState_Text().ToUpper(), CompVars[Param.GetState_Name().ToUpper()], Component.GetState_SchDesignator().GetState_Text(), Param.GetState_Name().ToUpper())) { Param.SetState_Text(CompVars[Param.GetState_Name().ToUpper()]); } } } } Param = PIterator.NextSchObject() as ISch_Parameter; } Component.UpdatePart_PostProcess(); VarList.Components[Component.GetState_SchDesignator().GetState_Text()].Saved = true; } } Component = LibraryIterator.NextSchObject() as ISch_Component; } if (ServerDoc.GetModified()) { ServerDoc.DoFileSave(""); } if (!DocOpened) { Client.CloseDocument(ServerDoc); } ServerDoc = null; } Progress.Value += 1; UpdateLabel("Updating Variants"); } Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath())); return; } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return; } }