public bool AddLog(string message) { try { COMS.AddLog(message); } catch (Exception) { throw; } return(true); }
public static void AsyncDXFCall(string originalname, string filename, string coursecode, string hole, bool Is2013DXF, Autodesk.AutoCAD.DatabaseServices.Database db) { if (String.IsNullOrEmpty(filename)) { throw new ArgumentNullException(nameof(filename)); } if (String.IsNullOrEmpty(coursecode)) { throw new ArgumentNullException(nameof(coursecode)); } string name = ""; var doc = Application.DocumentManager.MdiActiveDocument; //Autodesk.AutoCAD.DatabaseServices.Database db = // Application.DocumentManager.MdiActiveDocument.Database; try { //Todo: A possible bug in IsZDrawing DXF //Todo: originalname to name ? if (IsZDrawing(filename)) { name = string.Format("z_{0}_{1}.dxf", coursecode, hole); filename = Path.Combine(Path.GetDirectoryName(filename), name); COMS.AddLog("Creating file Z-Surface DXF: " + name); originalname = filename; } else { COMS.AddLog("Creating file S-Surface DXF: " + name); } if (!Is2013DXF) { db.DxfOut(originalname.Replace(".DWG", ".dxf"), 16, DwgVersion.Current); } else { db.DxfOut(originalname.Replace(".DWG", ".dxf"), 16, DwgVersion.AC1027); } } catch (System.Exception ex) { PGA.MessengerManager.MessengerManager.LogException(ex); } }
public void WriteReport(List <Logs> errors) { try { COMS.AddLog("*****************Batch Errors********************"); errors.All(p => { COMS.AddLog(String.Format("{0}: {1}", p.Source ?? "No Source Drawing Information", p.Issue)); return(true); }); COMS.AddLog("*****************Batch Errors********************"); } catch (Exception ex) { COMS.LogException(ex); } }
public static void SynchExportDWGs() { List <ExportToCADStack> allExportToCadRecords = null; using (DatabaseCommands commands = new DatabaseCommands()) { allExportToCadRecords = commands.GetAllExportToCadRecords(); bool Is2013Version = false; foreach (var file in allExportToCadRecords) { Is2013Version = commands.IsDXFVersionByDate ((DateTime)file.DateStamp); COMS.AddLog(string.Format ("Set the DXF file to version 2013: {0}", Is2013Version)); if (!commands.IsDWGStartedEprtToCad(file.Id) && !commands.IsDXFStartedExportToCad(file.Id) && !commands.IsCompletedExportToCad(file.Id)) { commands.SetStartFlagExportToCad(file.Id); if (!GolfHoles.IsWithinLimits((int)file.Hole)) { return; } var c = commands.GetSettingsCourseNumByDate ((DateTime)file.DateStamp); var shole = GolfHoles.GetHoles((int)file.Hole); if (File.Exists(file.CompletePath)) { #region Use this if reading file var doc = Application.DocumentManager.Open (file.CompletePath, true); Application.DocumentManager.MdiActiveDocument = doc; var db = doc.Database; #endregion PGA.DrawingManager.Commands. CloseAllButActiveDocuments(); using (doc.LockDocument()) { var name = ""; if (IsZDrawing(file.CompletePath)) { name = GetDWGPrefix(file.CompletePath, file.Hole); } else { name = GetDWGPrefix(file.CompletePath, file.Hole); } LoopSurfaces(file.CompletePath, name, c.ToString(), shole, Is2013Version); } } } commands.SetDXFFlagExportToCad(file.Id); commands.SetCompletedFlagExportToCad(file.Id); } commands.DeleteAllExportToCadRecords(); } }
public static void AsyncExportDXFs() { List <ExportToCADStack> allExportToCadRecords = null; try { using (DatabaseCommands commands = new DatabaseCommands()) { allExportToCadRecords = commands.GetAllExportToCadRecords(); if (allExportToCadRecords != null) { Application.SetSystemVariable("FILEDIA", 0); bool Is2013Version = false; bool SkipSDxf = false; foreach (var file in allExportToCadRecords) { if (!commands.IsDXFStartedExportToCad(file.Id) && !commands.IsCompletedExportToCad(file.Id)) { commands.SetDXFFlagExportToCad(file.Id); commands.LockFileExportToCad(file.Id); var s = commands.GetSettingsByDate((DateTime)file.DateStamp); SkipSDxf = commands.IsSkipDXFByDate ((DateTime)file.DateStamp); Is2013Version = commands.IsDXFVersionByDate ((DateTime)file.DateStamp); COMS.AddLog(string.Format ("Set the DXF file to version 2013: {0}", Is2013Version)); if (!GolfHoles.IsWithinLimits((int)file.Hole)) { return; } var c = commands.GetSettingsCourseNumByDate ((DateTime)file.DateStamp); var shole = GolfHoles.GetHoles((int)file.Hole); var modifiedname = ModifyDwgName(file.CompletePath); // Skip DXF if (SkipSDxf) { if (!(IsZDrawing(file.CompletePath))) { COMS.AddLog("Skip DXF! Omitting S-Surface DXF."); commands.SetCompletedFlagExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } } if (File.Exists(modifiedname)) { var doc = Application.DocumentManager.Open (modifiedname, true); Application.DocumentManager.MdiActiveDocument = doc; var db = doc.Database; using (doc.LockDocument()) { //PGA.DrawingManager.Commands. //CloseAllButActiveDocuments(); if (IsZDrawing(modifiedname)) { AsyncDXFCall(file.CompletePath, modifiedname, c.ToString(), shole, Is2013Version, db); COMS.AddLog("Done with file Z-Surface DXF: " + modifiedname); commands.SetCompletedFlagExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } else { if (!SkipSDxf) { if (s.SportVision == true) { var _modifiedname = ""; if (!String.IsNullOrEmpty(_modifiedname = (CheckAndCreateDirectory(file.CompletePath, shole, c, s.TourCode)))) { AsyncDXFCall(_modifiedname, file.CompletePath, c, shole, Is2013Version, db); COMS.AddLog("Done with file S-Surface DXF: " + _modifiedname); } } else { AsyncDXFCall(file.CompletePath, file.CompletePath, c.ToString(), shole, Is2013Version, db); } } commands.SetCompletedFlagExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } } } } } } } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { PGA.MessengerManager.MessengerManager.LogException(ex); } catch (System.Exception ex) { PGA.MessengerManager.MessengerManager.LogException(ex); } }
public static void AsyncExportDWGs() { List <ExportToCADStack> allExportToCadRecords = null; try { using (DatabaseCommands commands = new DatabaseCommands()) { allExportToCadRecords = commands.GetAllExportToCadRecords(); if (allExportToCadRecords != null) { Application.SetSystemVariable("FILEDIA", 0); foreach (var file in allExportToCadRecords) { if (!commands.IsDWGStartedEprtToCad(file.Id) && !commands.IsDXFStartedExportToCad(file.Id) && !commands.IsCompletedExportToCad(file.Id)) { commands.SetStartFlagExportToCad(file.Id); commands.LockFileExportToCad(file.Id); if (!GolfHoles.IsWithinLimits((int)file.Hole)) { return; } var c = commands.GetSettingsCourseNumByDate ((DateTime)file.DateStamp); var shole = GolfHoles.GetHoles((int)file.Hole); var SkipSDxf = commands.IsSkipDXFByDate ((DateTime)file.DateStamp); bool DwgInsert = false; if (file.Function != null) { DwgInsert = file.Function.Contains("INSERT"); } COMS.AddLog("DwgInsert=" + DwgInsert); if (DwgInsert) { ExportToAutoCADCurrentDWG(file.CompletePath, file.Hole); commands.SetCompletedFlagDWGExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } // Skip DXF and ACAD if (SkipSDxf) { if (!(IsZDrawing(file.CompletePath))) { commands.SetCompletedFlagDWGExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } } if (File.Exists(file.CompletePath)) { var doc = Application.DocumentManager.Open (file.CompletePath, true); Application.DocumentManager.MdiActiveDocument = doc; var db = doc.Database; using (doc.LockDocument()) { try { //PGA.MessengerManager.MessengerManager.AddLog("Starting Snapshot!"); // try // { // PGA.PlotManager.PrintCommands.PublishLayouts(file.CompletePath, // file.Hole.ToString()); // } // catch (System.Exception ex) // { // PGA.MessengerManager.MessengerManager.AddLog(ex.Message); // } // try // { // PGA.PlotManager.PlotCommands.SnapshotToFile( // Path.ChangeExtension(file.CompletePath, "png"), // VisualStyleType.Wireframe2D); // PGA.PlotManager.PlotCommands.SnapShotFromPrintScreen( // Path.ChangeExtension(file.CompletePath, "jpg")); // } // catch (System.Exception ex) // { // PGA.MessengerManager.MessengerManager.AddLog(ex.Message); // } // PGA.MessengerManager.MessengerManager.AddLog("Ending Snapshot!"); } catch (System.Exception ex) { COMS.LogException(ex); } if (IsZDrawing(file.CompletePath)) { ExportZToAutoCADCurrentDWG(file.CompletePath, file.Hole); commands.SetCompletedFlagDWGExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } else { if (!SkipSDxf) { ExportToAutoCADCurrentDWG(file.CompletePath, file.Hole); } commands.SetCompletedFlagDWGExportToCad(file.Id); commands.UnLockFileExportToCad(file.Id); break; } } } } } } } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { PGA.MessengerManager.MessengerManager.LogException(ex); } catch (System.Exception ex) { PGA.MessengerManager.MessengerManager.LogException(ex); } }