EPLAN API 入门系列- 实战篇(How to Change Properties in EPlan?)
2013-04-11 15:40
1131 查看
How to Change Properties in EPlan?
In general,I think there are tow ways:
1、Offline programe in Console Application
2、Online programe via EventListerner in Eplan.Action.Addin
EventListerner class:
Addin Class:
Action class:
if any question,welcome you to comment...
In general,I think there are tow ways:
1、Offline programe in Console Application
public void Execute() { Console.WriteLine("Update Article Properties Demo"); //Start P8 EplApplication eplApp = new EplApplication(); eplApp.Init("", true, true); Project prj = null; try { using (LockingStep ls = new LockingStep()) { // 1. Open a project Console.WriteLine("Opening project..."); eplApp.OpenProjectDlg(); ProjectManager prjMngr = new ProjectManager(); if (prjMngr.CurrentProject == null) { Console.WriteLine("No project is open. Finished."); return; } prj = prjMngr.CurrentProject; Console.WriteLine("Project '{0}' is open.", prj.ProjectFullName); // 2. Get all terminal strips in the project DMObjectsFinder fndr = new DMObjectsFinder(prj); TerminalStrip[] arrTermStrips = fndr.GetTerminalStrips(null); using (UndoStep us = (new UndoManager()).CreateUndoStep()) { // 3. Change a property Console.WriteLine("Modifying terminal strips..."); foreach (TerminalStrip ts in arrTermStrips) { if (ts.ManualPlacementType != DocumentTypeManager.DocumentType.Circuit && ts.ManualPlacementType != DocumentTypeManager.DocumentType.CircuitSingleLine) continue; string sNewValue = string.Format("{0} - Change at {1}", (new Random()).Next(), DateTime.Now.ToShortTimeString()); MessageBox.Show(sNewValue.ToString()); MultiLangString mls = new MultiLangString(); mls.AddString((new Languages()).GuiLanguage.GetNumber(), sNewValue); ts.Properties.FUNC_TEXT = mls; } // revert changes Console.WriteLine("Reverting changes in project..."); us.DoUndo(); } Console.WriteLine("Done."); } } catch (System.Exception ex) { Console.WriteLine("ERROR. " + ex.Message); } finally { if (prj != null) prj.Close(); GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine("Press any key."); Console.ReadKey(); eplApp.Exit(); } }
2、Online programe via EventListerner in Eplan.Action.Addin
EventListerner class:
public class SystemEventListerner { [DeclareEventHandler("onActionStart.String.*")] public long MyEventHandlerFunction(String strActionName) { try { System.Windows.Forms.MessageBox.Show("Action " + strActionName + " was started!", "MyEventHandler"); } catch (System.InvalidCastException exc) { String strExc = exc.Message; System.Windows.Forms.MessageBox.Show("Parameter error: " + strExc, "MyEventHandler"); } return 0; } }
Addin Class:
#region IEplAddIn Members public bool OnExit() { return true; } SystemEventListerner _lstnr = null; public bool OnInit() { _lstnr = new SystemEventListerner(); _lstnr.MyEventHandlerFunction(Action.NAME); return true; } public bool OnInitGui() { Menu m = new Menu(); uint id = m.GetPersistentMenuId("System messages"); //menu item id = m.AddMainMenu("Example", Menu.MainMenuName.eMainMenuUtilities, "Example #1", Action.NAME, Action.DESCR, 1); return true; } public bool OnRegister(ref bool bLoadOnStart) { //bLoadOnStart = false; // this prevents addin intialization (OnInit, OnInitGui) when P8 starts; not usefull return true; } public bool OnUnregister() { _lstnr = null; return true; } #endregion
Action class:
public bool Execute(ActionCallingContext oActionCallingContext) { try { using (LockingStep ls = new LockingStep()) { // 1. Get all terminal strips in the project SelectionSet oSelSet = new SelectionSet(); Project oProj = oSelSet.GetCurrentProject(true); DMObjectsFinder fndr = new DMObjectsFinder(oProj); TerminalStrip[] arrTermStrips = fndr.GetTerminalStrips(null); using (UndoStep us = (new UndoManager()).CreateUndoStep()) { // 2. Change a property Console.WriteLine("Modifying terminal strips..."); foreach (TerminalStrip ts in arrTermStrips) { if (ts.ManualPlacementType != DocumentTypeManager.DocumentType.Circuit && ts.ManualPlacementType != DocumentTypeManager.DocumentType.CircuitSingleLine) continue; string sNewValue = string.Format("{0} - Change at {1}", (new Random()).Next(), DateTime.Now.ToShortTimeString()); MessageBox.Show(sNewValue.ToString()); MultiLangString mls = new MultiLangString(); mls.AddString((new Languages()).GuiLanguage.GetNumber(), sNewValue); ts.Properties.FUNC_TEXT = mls; } // revert changes //Console.WriteLine("Reverting changes in project..."); us.DoUndo(); } Console.WriteLine("Done."); } } catch (System.Exception ex) { //Console.WriteLine("ERROR. " + ex.Message); } finally { //if (prj != null) prj.Close(); GC.Collect(); GC.WaitForPendingFinalizers(); //Console.WriteLine("Press any key."); //Console.ReadKey(); //eplApp.Exit(); } return true; }
if any question,welcome you to comment...
相关文章推荐
- EPLAN API 入门系列- 提高篇(How to get Symbol via Function)
- EPLAN API 入门系列- 提高篇(How to get PartProperty via partNo)
- EPLAN API 入门系列- 提高篇(How to Add/Remove GraphicalLayer?)
- EPLAN API 入门系列- 提高篇(How to get PropertyValue?)
- EPLAN API 入门系列- 提高篇(How to get all connections which are not in location box)
- Visual Studio: How to change ipch path in Visual Studio 2010 (.sdf, *.opensdf, ...)
- How to Change Hadoop Daemon log4j.properties
- XDB:How to change XDB in XE to enable remote listener.
- Windows - How to change default system font in Windows 10
- Understanding Object Ownership in sql 2000(how to change the schema table name in sql 2000)
- How to change Password Policy in Windows Server 2003
- How-To : Using EJB 3.0 and Java Persistence API with Spring in OC4J
- 深入理解iOS API系列(一) textField:shouldChangeCharactersInRange:replacementString:
- How to Change Password Complexity Requirements in Windows XP
- How to Change Timezone in your Linux System
- How to change max_allowed_packet value in mysql?
- How to change the character case in ksh?
- prjGetWriteINIFile - How to Read-Write INI file using VB & API - 读取/写入INI文件 - VB6 + API - SourceCode - HackerJLY
- How To Get Properties Data in Spring
- Post Goods Issue error .How to Change Current Period In Material Master ?