public static void CreateDXFs() { List <ExportToCADStack> allExportToCadRecords = null; using (DatabaseCommands commands = new DatabaseCommands()) { allExportToCadRecords = commands.GetAllExportToCadRecords(); foreach (var file in allExportToCadRecords) { if (!GolfHoles.IsWithinLimits((int)file.Hole)) { return; } var s = commands.GetSettingsByDate((DateTime)file.DateStamp); var c = commands.GetSettingsCourseNumByDate ((DateTime)file.DateStamp); var year = DateTime.Now.Year; var TOUR_Code = String.IsNullOrEmpty(s.TourCode) ? "R": s.TourCode; var sv_filename = TOUR_Code + year + c + ".dwg"; var shole = GolfHoles.GetHoles((int)file.Hole); var modifiedpath = ModifyDwgName(file.CompletePath); if (File.Exists(modifiedpath)) { var doc = Application.DocumentManager.Open (modifiedpath, true); Application.DocumentManager.MdiActiveDocument = doc; var db = doc.Database; using (doc.LockDocument()) { var name = Path.GetFileName (file.CompletePath); var dir = Path.GetDirectoryName (file.CompletePath); if (IsZDrawing(file.CompletePath)) { name = string.Format("z_{0}_{1}.dwg", c, shole); } else if (s.SportVision == true) { name = sv_filename; } else { name = "ACAD-" + name; } name = Path.GetFileNameWithoutExtension(name); name = name + ".dxf"; var completepath = Path.Combine (dir, name); db.DxfOut(completepath, 16, DwgVersion.Current); } } } } }
public void CancelCommandExecuted() { if (_isEditMode) { MapChangedDataAfterRefresh(EventGolf.EventGolf, EventGolfOriginal.EventGolf); EventGolf.Golf = Golfs.FirstOrDefault(p => p.ID == EventGolfOriginal.Golf.ID); EventGolf.GolfHole = GolfHoles.FirstOrDefault(p => p.ID == EventGolfOriginal.GolfHole.ID); EventGolf.Refresh(); } else { _eventDataUnit.RevertChanges(); } }
public static string GetDWGPrefix(string filename, long?hole) { var doc = Application.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; using (doc.LockDocument()) { var name = Path.GetFileName(filename); var dir = Path.GetDirectoryName(filename); var shole = GolfHoles.GetHoles((int)hole); name = "ACAD-" + name; var completepath = Path.Combine(dir, name); return(completepath); } }
public static void ExportToAutoCADCurrentDWG(string filename, long?hole) { var doc = Application.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; using (doc.LockDocument()) { var name = Path.GetFileName(filename); var dir = Path.GetDirectoryName(filename); var shole = GolfHoles.GetHoles((int)hole); name = "ACAD-" + name; var completepath = Path.Combine(dir, name); doc.SendStringToExecute("ExportToAutoCAD " + completepath + "\n", true, false, false); } }
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); } }