/// <summary> /// Starts the application without Gui /// </summary> private void Start() { if (!IsRunning) { try { EplApplication eplApplication = new EplApplication(); eplApplication.EplanBinFolder = BinPath; if (!string.IsNullOrEmpty(SystemConfiguration)) { eplApplication.SystemConfiguration = SystemConfiguration; } if (!string.IsNullOrEmpty(LicenseFile)) { eplApplication.LicenseFile = LicenseFile; // Set specific licence } eplApplication.QuietMode = EplApplication.QuietModes.ShowAllDialogs; eplApplication.Init("", true, true); Application = eplApplication; } catch { Application = null; } } }
public void SetMainForm(IntPtr f) { starter.SetFrame(f); app = starter.APP; starter.SetFrame(f); this.app = starter.APP; Manager = new ProjectManager(); Locker = new LockingStep(); }
public void SetFrame(IntPtr f) { APP = new EplApplication { EplanBinFolder = FindEplan.Find() }; APP.Init(""); APP.SetMainFrame(f); }
public static MDPart SelectPartWithGui() { EplApplication eplanApplication = new EplApplication(); MDPartsManagement partsManagement = new MDPartsManagement(); string partnNumber = string.Empty; string partVariant = string.Empty; eplanApplication.ShowPartSelectionDialog(ref partnNumber, ref partVariant); MDPartsDatabase partsDatabase = partsManagement.OpenDatabase(); MDPart part = partsDatabase.GetPart(partnNumber, partVariant); return(part); }
/// <summary> /// Release all objects /// <note type="caution"> /// Needed for eplan runtime exceptions, there is a known issue (T1094381), EPLAN says Microsoft should fix this problem /// Workaround: Enable native code debugging in visual studio /// </note> /// </summary> public void Close() { // T1094381: There is a known problem with console applications, that visual studio not quit the debugging session, workaround: enable native code debugging in project if (Application != null) { try { Application.Exit(); } finally { Application = null; } } }
public static MDPart CreateOrUpdatePart(ArticleReference articleReference, bool updateFunctionTemplate) { // Need to lock project var project = articleReference.Project; project.SmartLock(); //if (articleReference.ParentObject != null) articleReference.ParentObject.SmartLock(); articleReference.SmartLock(); // Init var partsDatabase = new MDPartsManagement().OpenDatabase(); //var articleReference = function.ArticleReferences.First(); articleReference.SmartLock(); var partNr = articleReference.PartNr; var partVariant = articleReference.VariantNr; MDPart part = partsDatabase.GetPart(partNr, partVariant); // Check if article is in project and remove, because the eplan action to create is not possible var existingArticle = project.Articles .FirstOrDefault(obj => obj.PartNr.Equals(partNr) && obj.VariantNr.Equals(partVariant) ); if (existingArticle != null) { existingArticle.SmartLock(); existingArticle.Remove(); } // Need to focus again if its lost if (articleReference.ParentObject is Placement placementToBringInFront) { new Edit().BringToFront(placementToBringInFront); } // Create new part if (part == null) { // LockingVector is needed because of locking exception from EPLAN action (no catch possible) using (new LockingUtility.SeplaLockingVector()) { new CommandLineInterpreter().Execute("XPameCreateType"); } partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part part = partsDatabase.GetPart(partNr, partVariant); } // Existing part else { // Check if pro panel, because there is no update possible bool isProPanel = articleReference.ParentObject is Component; string partNrTemp = partNr; if (!isProPanel) { // Rename part string suffix = "_temp"; partNrTemp = part.PartNr + suffix; try { articleReference.PartNr = partNrTemp; articleReference.ParentObject.SmartLock(); articleReference.StoreToObject(); // Quiet create temp part var application = new EplApplication(); var quiteMode = application.QuietMode; application.QuietMode = EplApplication.QuietModes.ShowNoDialogs; using (new LockingUtility.SeplaLockingVector()) { new CommandLineInterpreter().Execute("XPameCreateType"); } application.QuietMode = quiteMode; } finally { // Rename back articleReference.PartNr = partNr; articleReference.StoreToObject(); } // Copy FunctionTemplate if (updateFunctionTemplate) { partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part MDPart partDuplicate = partsDatabase.GetPart(partNrTemp, partVariant); foreach (var partFunctionTemplatePosition in part.FunctionTemplatePositions) { part.RemoveFunctionTemplatePosition(partFunctionTemplatePosition); } foreach (var partDuplicateFunctionTemplatePosition in partDuplicate.FunctionTemplatePositions) { part.AddFunctionTemplatePosition(partDuplicateFunctionTemplatePosition); } partsDatabase.RemovePart(partDuplicate); } } // Check if article is in project var existingTempArticle = project.Articles .FirstOrDefault(obj => obj.PartNr.Equals(partNrTemp) && obj.VariantNr.Equals(partVariant) ); if (existingTempArticle != null) { existingTempArticle.SmartLock(); existingTempArticle.Remove(); } } // Load data var article = project.Articles .FirstOrDefault(obj => obj.PartNr.Equals(partNr) && obj.VariantNr.Equals(partVariant) ); if (article != null) { article.SmartLock(); article.LoadFromMasterdata(); } return(part); }