public void DrawAxisLabel(ICanvas canvas, PlotConfig info, float size, float offset) { float xRight = info.DataRect.Right + size + offset; float yCenter = info.DataRect.VerticalCenter; Label.Draw(canvas, xRight, yCenter, 90, invert: true); }
public JsonFileConfig() { ComConfig = new ComConfig(); AlgorithmPara = new AlgorithmPara(); UiConfig = new UiConfig(); PlotConfig = new PlotConfig(); }
public void DrawAxisLabel(ICanvas canvas, PlotConfig info, float size, float offset) { float xCenter = info.DataRect.HorizontalCenter; float yTop = info.DataRect.Top - size - offset; Label.Draw(canvas, xCenter, yTop, HorizontalAlignment.Center, VerticalAlignment.Top); }
public void DrawAxisLabel(ICanvas canvas, PlotConfig info, float size, float offset) { float xCenter = info.DataRect.HorizontalCenter; float yBottom = info.DataRect.Bottom + size + offset; Label.Draw(canvas, xCenter, yBottom, HorizontalAlignment.Center, VerticalAlignment.Bottom); }
public void ShowDialog(uint dialogID) { if (dialogID == 0) { if (m_eState == State.ePlotBegin) { GameMatch match = GameSystem.Instance.mClient.mCurMatch; for (int i = 0; i < match.m_homeTeam.GetMemberCount(); ++i) { match.m_homeTeam.GetMember(i).m_InfoVisualizer.m_goPlayerInfo.SetActive(true); } for (int i = 0; i < match.m_awayTeam.GetMemberCount(); ++i) { match.m_awayTeam.GetMember(i).m_InfoVisualizer.m_goPlayerInfo.SetActive(true); } m_stateMachine.SetState(MatchState.State.eShowRule); } else if (m_eState == State.ePlotEnd) { //m_stateMachine.SetState(MatchState.State.eTipOff); plotUI.Hide(); OnEndResult(); } return; } PlotConfig config = null; for (int i = 0; i < m_plotConfig.Count; ++i) { if (m_plotConfig[i].dialog_id == dialogID) { config = m_plotConfig[i]; } } if (config == null) { if (m_eState == State.ePlotBegin) { m_stateMachine.SetState(MatchState.State.eShowRule); } else if (m_eState == State.ePlotEnd) { //m_stateMachine.SetState(MatchState.State.eTipOff); OnEndResult(); } return; } // if (config.icon == "self") { plotUI.Show(0, m_match.mainRole.m_roleInfo.id, config.content); } else { uint npcID = 0; uint.TryParse(config.icon, out npcID); plotUI.Show(1, npcID, config.content); } m_nextDialogID = config.next_dialog_id; }
public void DrawAxisLabel(ICanvas canvas, PlotConfig info, float size, float offset) { float xLeft = info.DataRect.Left - size - offset; float yCenter = info.DataRect.VerticalCenter; Label.Draw(canvas, xLeft, yCenter, -90); }
public void UpdatePaperListbox(ComboBox aCmbPlotDevice, ComboBox aCmbPaperSize, string aDeviceName) { aCmbPaperSize.Items.Clear(); if (aCmbPlotDevice.Text == "None" || string.IsNullOrEmpty(aCmbPlotDevice.Text)) { return; } try { PlotConfig pc = PlotConfigManager.SetCurrentConfig(aDeviceName); if (pc.IsPlotToFile || pc.PlotToFileCapability == PlotToFileCapability.MustPlotToFile || pc.PlotToFileCapability == PlotToFileCapability.PlotToFileAllowed) { aCmbPaperSize.Items.Add("Auto"); } foreach (string str in pc.CanonicalMediaNames) { if (CanonicalMediaNamesFilter.IsMatch(str)) { #if !bcad aCmbPaperSize.Items.Add(pc.GetLocalMediaName(str)); #else aCmbPaperSize.Items.Add(str); #endif } } aCmbPaperSize.Text = aCmbPaperSize.Items[0].ToString(); } catch (Exception Ex) { MessageBox.Show(Ex.Message + "\n" + Ex.Source + "\n" + Ex.StackTrace); } }
public void ParsePlotConfig() { string text = ResourceLoadManager.Instance.GetConfigText(name5); if (text == null) { Debug.LogError("LoadConfig failed: " + name5); return; } plotConfig.Clear(); dialogConfig.Clear(); //读取以及处理XML文本的类 XmlDocument xmlDoc = CommonFunction.LoadXmlConfig(GlobalConst.DIR_XML_PLOT, text); //解析xml的过程 XmlNodeList nodeList = xmlDoc.SelectSingleNode("Data").ChildNodes; foreach (XmlElement land in nodeList) { XmlNode comment = land.SelectSingleNode(GlobalConst.CONFIG_SWITCH_COLUMN); if (comment != null && comment.InnerText == GlobalConst.CONFIG_SWITCH) { continue; } PlotConfig config = new PlotConfig(); foreach (XmlElement xel in land) { uint value; if (xel.Name == "id") { uint.TryParse(xel.InnerText, out value); config.id = value; } else if (xel.Name == "dialog_id") { uint.TryParse(xel.InnerText, out value); config.dialog_id = value; } else if (xel.Name == "icon") { config.icon = xel.InnerText; } else if (xel.Name == "content") { config.content = xel.InnerText; } else if (xel.Name == "next_dialog_id") { uint.TryParse(xel.InnerText, out value); config.next_dialog_id = value; } } if (plotConfig.ContainsKey(config.id) == false) { plotConfig[config.id] = new List <PlotConfig>(); } plotConfig[config.id].Add(config); dialogConfig[config.dialog_id] = config.content; } }
private void AddDockPanel(IPlotControl control, string text, int height = 300) { if (CurrentReceiver == null) { return; } var xtraUC = control as XtraUserControl; xtraUC.Dock = DockStyle.Fill; var config = new PlotConfig() { Type = control.Type, ChCount = (CurrentReceiver as IGetterRcvProperty).ChannelCount, FMax = this.FMax, Columns = Items, KeyphasorMap = (CurrentReceiver as IKeyphasorMapper).KpMap }; control.ControlInit(config); DockPanel dockPanel = snapDockManager.AddPanel(DockingStyle.Top); dockPanel.Text = text + " - " + CurrentReceiver.ToString(); dockPanel.Controls.Add(xtraUC); dockPanel.HandleDestroyed += (s, de) => OpenedPlotControls.Remove(control); dockPanel.ClosedPanel += (s, de) => OpenedPlotControls.Remove(control); var heigh = control.GetType().CustomAttributes; heigh.GetType(); dockPanel.Height = height; OpenedPlotControls.Add(control); }
public void PlotJsonSerializeTest() { var plot = new Plot() { Coordinates = new PlotCoordinates(), Owner = new UUID(Guid.NewGuid().ToByteArray()), }; PlotConfig config = new PlotConfig() { Plots = new[] { plot } }; var settings = new JsonSerializerSettings { Formatting = Formatting.Indented, }; settings.Converters.Add(new UuidConverter()); string s = JsonConvert.SerializeObject(config, settings); Console.WriteLine(s); var test = JsonConvert.DeserializeObject <PlotConfig>(s, settings); Assert.AreEqual(plot.Owner, test.Plots[0].Owner); }
public Tick[] GenerateTicks(PlotConfig info) { return(Edge switch { Edge.Bottom => GetEvenlySpacedTicks(info.AxisLimits.XMin, info.AxisLimits.XMax, 25, Edge.Bottom), Edge.Left => GetEvenlySpacedTicks(info.AxisLimits.YMin, info.AxisLimits.YMax, 50, Edge.Left), _ => throw new NotImplementedException(), });
protected override PointF[] GetPoints(PlotConfig info) { PointF[] points = new PointF[Xs.Length]; for (int i = 0; i < points.Length; i++) { points[i] = info.GetPixel(Xs[i], Ys[i]).PointF; } return(points); }
public void DrawSpine(ICanvas canvas, PlotConfig config, float offset) { canvas.StrokeColor = SpineColor; canvas.StrokeSize = SpineLineWidth; canvas.DrawLine( config.DataRect.Left, config.DataRect.Top - offset, config.DataRect.Right, config.DataRect.Top - offset); }
public Tick[] GenerateTicks(PlotConfig info) { return(Edge switch { Edge.Bottom => RecalculatePositionsAutomaticNumeric(info, Edge.Bottom), Edge.Left => RecalculatePositionsAutomaticNumeric(info, Edge.Left), Edge.Top => RecalculatePositionsAutomaticNumeric(info, Edge.Top), Edge.Right => RecalculatePositionsAutomaticNumeric(info, Edge.Right), _ => throw new NotImplementedException($"Unsupported {nameof(Edge)}: {Edge}"), });
public void DrawTicks(ICanvas canvas, PlotConfig info, Tick[] ticks, float offset) { foreach (Tick tick in ticks) { float x = info.GetPixelX(tick.Position); PointF pt1 = new(x, info.DataRect.Top - offset); PointF pt2 = new(pt1.X, pt1.Y - tick.TickMarkLength); canvas.StrokeColor = tick.TickMarkColor; canvas.DrawLine(pt1, pt2); PointF pt3 = new(pt2.X, pt2.Y - tick.TextPadding); tick.Label.Draw(canvas, pt3.X, pt3.Y, HorizontalAlignment.Center, VerticalAlignment.Bottom); } }
public void DrawTicks(ICanvas canvas, PlotConfig info, Tick[] ticks, float offset) { foreach (Tick tick in ticks) { float y = info.GetPixelY(tick.Position); PointF pt1 = new(info.DataRect.Right + offset, y); PointF pt2 = new(pt1.X + tick.TickMarkLength, pt1.Y); canvas.StrokeColor = tick.TickMarkColor; canvas.DrawLine(pt1, pt2); PointF pt3 = new(pt2.X + tick.TextPadding, pt2.Y); tick.Label.Draw(canvas, pt3.X, pt3.Y, HorizontalAlignment.Left, VerticalAlignment.Center); } }
public void Test() { PlotSettingsValidator psv = PlotSettingsValidator.Current; var Text = new List <string>(); var editor = Acad.DocumentManager.MdiActiveDocument.Editor; System.Collections.Specialized.StringCollection vs = psv.GetPlotDeviceList(); foreach (var st in vs) { editor.WriteMessage(st.ToString() + Environment.NewLine); Text.Add(st.ToString()); } using (PlotSettings ps = new PlotSettings(false)) { foreach (var st in vs) { editor.WriteMessage("Текущий/Selected: " + st.ToString() + Environment.NewLine); Text.Add("Текущий/Selected: " + st.ToString()); if (st.ToString() == "AutoCAD PDF (High Quality Print).pc3") { PlotConfig config = PlotConfigManager.SetCurrentConfig(st.ToString()); PlotInfo info = new PlotInfo(); psv.SetPlotConfigurationName(ps, st.ToString(), null); psv.RefreshLists(ps); System.Collections.Specialized.StringCollection mediaName = psv.GetCanonicalMediaNameList(ps); foreach (var media in mediaName) { editor.WriteMessage("Формат/Media name " + media.ToString() + Environment.NewLine); Text.Add("Формат/Media name " + media.ToString()); MediaBounds bounds = config.GetMediaBounds(media.ToString()); editor.WriteMessage(Math.Round(bounds.PageSize.X).ToString() + Environment.NewLine); editor.WriteMessage(Math.Round(bounds.PageSize.Y).ToString() + Environment.NewLine); editor.WriteMessage(Math.Round(bounds.LowerLeftPrintableArea.X).ToString() + Environment.NewLine); editor.WriteMessage(Math.Round(bounds.UpperRightPrintableArea.Y).ToString() + Environment.NewLine); editor.WriteMessage(Math.Round(bounds.UpperRightPrintableArea.X).ToString() + Environment.NewLine); editor.WriteMessage(Math.Round(bounds.LowerLeftPrintableArea.Y).ToString() + Environment.NewLine); Text.Add(Math.Round(bounds.PageSize.X).ToString()); Text.Add(Math.Round(bounds.PageSize.Y).ToString()); Text.Add(Math.Round(bounds.LowerLeftPrintableArea.X).ToString()); Text.Add(Math.Round(bounds.UpperRightPrintableArea.Y).ToString()); Text.Add(Math.Round(bounds.UpperRightPrintableArea.X).ToString()); Text.Add(Math.Round(bounds.LowerLeftPrintableArea.Y).ToString()); } } } } System.IO.File.WriteAllLines("C:\\users\\dyn1\\desktop\\info.txt", Text); }
Stream(ArrayList data, PlotConfig info) { data.Add(new Snoop.Data.ClassSeparator(typeof(PlotConfig))); data.Add(new Snoop.Data.ObjectCollection("Canonical media names", info.CanonicalMediaNames)); data.Add(new Snoop.Data.String("Comment", info.Comment)); data.Add(new Snoop.Data.String("Default file extension", info.DefaultFileExtension)); data.Add(new Snoop.Data.String("Device name", info.DeviceName)); data.Add(new Snoop.Data.Int("Device type", info.DeviceType)); data.Add(new Snoop.Data.String("Driver name", info.DriverName)); data.Add(new Snoop.Data.String("Full path", info.FullPath)); data.Add(new Snoop.Data.String("Location name", info.LocationName)); data.Add(new Snoop.Data.Bool("Is plot to file", info.IsPlotToFile)); data.Add(new Snoop.Data.Int("Max device dots per inch", info.MaximumDeviceDotsPerInch)); data.Add(new Snoop.Data.String("Plot to file capability", info.PlotToFileCapability.ToString())); data.Add(new Snoop.Data.String("Port name", info.PortName)); data.Add(new Snoop.Data.String("Server name", info.ServerName)); data.Add(new Snoop.Data.String("Tag line", info.TagLine)); }
//public Extents2d Extents3dToExtents2d() //{ //Extents3d point3d = this.BlockPoint3d; //Point3d minPoint3dWcs = // new Point3d(this.BlockPoint3d.MinPoint[0], point3d.MinPoint[1], point3d.MinPoint[2]); //Point3d minPoint3d = Autodesk.AutoCAD.Internal.Utils.UcsToDisplay(minPoint3dWcs, false); //Point3d maxPoint3dWcs = new Point3d(point3d.MaxPoint[0], point3d.MaxPoint[1], point3d.MaxPoint[2]); //Point3d maxPoint3d = Autodesk.AutoCAD.Internal.Utils.UcsToDisplay(maxPoint3dWcs, false); //Extents2d points = new Extents2d(new Point2d(minPoint3d[0], minPoint3d[1]), // new Point2d(maxPoint3d[0], maxPoint3d[1])); //return points; //} //public bool IsFormatHorizontal() //{ // double minPointX = BlockPoint3d.MinPoint[0]; // double minPointY = BlockPoint3d.MinPoint[1]; // double maxPointX = BlockPoint3d.MaxPoint[0]; // double maxPointY = BlockPoint3d.MaxPoint[1]; // this.Width = maxPointX - minPointX; // this.Height = maxPointY - minPointY; // if (Height > Width) return false; // return true; //} private static string GetLocalNameByAtrrValue(string attrvalue = "А3") { StandartCopier standartCopier = new StandartCopier(); PlotConfig pConfig = PlotConfigManager.SetCurrentConfig(standartCopier.Pc3Location); string canonName = ""; foreach (var canonicalMediaName in pConfig.CanonicalMediaNames) { string localName = pConfig.GetLocalMediaName(canonicalMediaName); if (localName == attrvalue) { canonName = canonicalMediaName; } Active.Editor.WriteMessage("\n" + canonicalMediaName); } return(canonName); }
private static Dictionary <string, AxisInfo> MakeAxisOptions(PlotConfig plot) { var res = new Dictionary <string, AxisInfo>(); res["y"] = new AxisInfo() { independentTicks = true, drawGrid = true, includeZero = plot.LeftAxisStartFromZero, gridLinePattern = null }; res["y2"] = new AxisInfo() { independentTicks = true, drawGrid = true, includeZero = plot.RightAxisStartFromZero, gridLinePattern = new int[] { 2, 2 } }; return(res); }
public string GetCanonNameByExtents() { StandartCopier standartCopier = new StandartCopier(); PlotConfig pConfig = PlotConfigManager.SetCurrentConfig(standartCopier.Pc3Location); string pat = @"\d{1,}?\.\d{2}"; //double width = this.Width; //double height = this.Height; string canonName = ""; foreach (var line in pConfig.CanonicalMediaNames) { Regex pattern = new Regex(pat, RegexOptions.Compiled | RegexOptions.Singleline); //string str2 = Regex.Split(str, pattern); if (pattern.IsMatch(line)) { MatchCollection str2 = pattern.Matches(line, 0); string strWidth = str2[0].ToString(); string strheight = str2[1].ToString(); double strWidthD = Convert.ToDouble(strWidth, System.Globalization.CultureInfo.InvariantCulture); double strheightD = Convert.ToDouble(strheight, System.Globalization.CultureInfo.InvariantCulture); Console.WriteLine(strWidthD); //double strheight = Convert.ToDouble(str2[1]); if (strWidthD == this.Width & strheightD == this.Height) { Console.WriteLine("{0} ширина {1}-{2} высота {3}-{4}", line, strWidthD, this, strheightD, this.Height); canonName = line; break; } } } return(canonName); }
public void Draw(ICanvas canvas, PlotConfig plotInfo) { canvas.ClipRectangle(plotInfo.DataRect.RectangleF); PointF[] points = GetPoints(plotInfo); canvas.StrokeSize = LineWidth; canvas.StrokeColor = LineColor; for (int i = 0; i < points.Length - 1; i++) { canvas.DrawLine(points[i], points[i + 1]); } if (MarkerSize > 0 && MarkerColor != Colors.Transparent) { canvas.FillColor = MarkerColor; for (int i = 0; i < points.Length; i++) { canvas.FillCircle(points[i], MarkerSize); } } }
public string GetCanonNameByWidthAndHeight() { StandartCopier standartCopier = new StandartCopier(); PlotConfig pConfig = PlotConfigManager.SetCurrentConfig(standartCopier.Pc3Location); //паттерн для размера листов string pat = @"\d{1,}?\.\d{2}"; string canonName = ""; foreach (var line in pConfig.CanonicalMediaNames) { Regex pattern = new Regex(pat, RegexOptions.Compiled | RegexOptions.Singleline); if (pattern.IsMatch(line)) { var items = DivideStringToWidthAndHeight(pattern, line); double curWidth; double curHeight; if (IsFormatHorizontal()) { curWidth = Math.Round(Width / ScaleX); curHeight = Math.Round(Height / ScaleX); } else { curWidth = Math.Round(Height / ScaleX); curHeight = Math.Round(Width / ScaleX); } if (items.Item1 == curWidth & items.Item2 == curHeight) { canonName = line; break; } } } return(canonName); }
/// <summary> /// The BatchPublish. /// </summary> /// <param name="docsToPlot">The docsToPlot<see cref="List{string}"/>.</param> private static void BatchPublish(List <string> docsToPlot) { using (DsdEntryCollection collection = new DsdEntryCollection()) { Document doc = Application.DocumentManager.MdiActiveDocument; foreach (string filename in docsToPlot) { using (DocumentLock doclock = doc.LockDocument()) { using (Database db = new Database(false, true)) { db.ReadDwgFile(filename, System.IO.FileShare.Read, true, ""); System.IO.FileInfo fi = new FileInfo(filename); string docName = fi.Name.Substring(0, fi.Name.Length - 4); using (Transaction Tx = db.TransactionManager.StartTransaction()) { foreach (ObjectId layoutId in GeLayoutIds(db)) { Layout layout = Tx.GetObject(layoutId, OpenMode.ForRead) as Layout; if (!layout.ModelType) { var ids = layout.GetViewports(); if (ids.Count == 0) { doc.Editor.WriteMessage($"\n{layout.LayoutName} is not initialized, so no plottable sheets in the current drawing "); } } DsdEntry entry = new DsdEntry { DwgName = filename, Layout = layout.LayoutName, Title = docName + "_" + layout.LayoutName }; entry.NpsSourceDwg = entry.DwgName; entry.Nps = "Setup1"; collection.Add(entry); } Tx.Commit(); } } } } using (DsdData dsdData = new DsdData()) { dsdData.SheetType = SheetType.MultiPdf; dsdData.ProjectPath = rootDir; dsdData.SetDsdEntryCollection(collection); string dsdFile = dsdData.ProjectPath + "\\dsdData.dsd"; dsdData.WriteDsd(dsdFile); System.IO.StreamReader sr = new System.IO.StreamReader(dsdFile); string str = sr.ReadToEnd(); sr.Close(); str = str.Replace("PromptForDwfName=TRUE", "PromptForDwfName=FALSE"); string strToApped = "[PublishOptions]\nInitLayouts = TRUE"; str += strToApped; System.IO.StreamWriter sw = new System.IO.StreamWriter(dsdFile); sw.Write(str); sw.Close(); dsdData.ReadDsd(dsdFile); System.IO.File.Delete(dsdFile); PlotConfig plotConfig = Autodesk.AutoCAD.PlottingServices.PlotConfigManager.SetCurrentConfig("DWG To PDF.pc3"); Autodesk.AutoCAD.Publishing.Publisher publisher = Autodesk.AutoCAD.ApplicationServices.Core.Application.Publisher; try { publisher.PublishExecute(dsdData, plotConfig); } catch (Exception ex) { doc.Editor.WriteMessage($"Exeception: {ex.StackTrace}"); } } } //This is hack to prevent from not finding result.pdf foreach (var file in Directory.GetFiles(rootDir, "*.pdf")) { System.IO.FileInfo fi = new System.IO.FileInfo(file); // Check if file is there if (fi.Exists) { // Move file with a new name. Hence renamed. fi.MoveTo(Path.Combine(Directory.GetCurrentDirectory(), "result.pdf")); break; } } }
public static void PublishLayouts(string path, string hole) { var completepath = Path.ChangeExtension(path, "pdf"); var filename = Application.DocumentManager.MdiActiveDocument.Name; using (DsdEntryCollection dsdDwgFiles = new DsdEntryCollection()) { // Define the first layout using (DsdEntry dsdDwgFile1 = new DsdEntry()) { // Set the file name and layout dsdDwgFile1.DwgName = filename; dsdDwgFile1.Layout = "PGA-OUTPUT"; dsdDwgFile1.Title = "PGA TOUR AUTOGENERATED SURFACE"; // Set the page setup override dsdDwgFile1.Nps = ""; dsdDwgFile1.NpsSourceDwg = ""; dsdDwgFiles.Add(dsdDwgFile1); } #region Define Second Layout //// Define the second layout //using (DsdEntry dsdDwgFile2 = new DsdEntry()) //{ // // Set the file name and layout // dsdDwgFile2.DwgName = "C:\\AutoCAD\\Samples\\Sheet Sets\\Architectural\\A-02.dwg"; // dsdDwgFile2.Layout = "ELEVATIONS"; // dsdDwgFile2.Title = "A-02 ELEVATIONS"; // // Set the page setup override // dsdDwgFile2.Nps = ""; // dsdDwgFile2.NpsSourceDwg = ""; // dsdDwgFiles.Add(dsdDwgFile2); //} #endregion #region Define third layout //// Define the second layout using (DsdEntry dsdDwgFile2 = new DsdEntry()) { // Set the file name and layout dsdDwgFile2.DwgName = filename; dsdDwgFile2.Layout = "ELEVATIONS"; dsdDwgFile2.Title = "A-02 ELEVATIONS"; // Set the page setup override dsdDwgFile2.Nps = ""; dsdDwgFile2.NpsSourceDwg = @"C:\Users\m4800\AppData\Roaming\Autodesk\ApplicationPlugins\PGA-CivilTinSurf2016.bundle\Contents\Template\PGA_PRINT_TMPLT.dwg"; dsdDwgFiles.Add(dsdDwgFile2); } #endregion // Set the properties for the DSD file and then write it out using (DsdData dsdFileData = new DsdData()) { dsdFileData.PromptForDwfName = false; // Set the target information for publishing //dsdFileData.DestinationName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\PGA-Publish.pdf"; //dsdFileData.ProjectPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\"; dsdFileData.DestinationName = completepath; //PGA-Publish.pdf; dsdFileData.ProjectPath = Path.GetDirectoryName(completepath); dsdFileData.SheetType = SheetType.MultiPdf; // Set the drawings that should be added to the publication dsdFileData.SetDsdEntryCollection(dsdDwgFiles); // Set the general publishing properties //dsdFileData.LogFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\myBatch.txt"; dsdFileData.LogFilePath = Path.ChangeExtension(path, "txt"); // "\\myBatch.txt"; // Create the DSD file //dsdFileData.WriteDsd(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\batchdrawings2.dsd"); dsdFileData.WriteDsd(Path.ChangeExtension(path, "dsd")); //"\\batchdrawings2.dsd"); try { // Publish the specified drawing files in the DSD file, and // honor the behavior of the BACKGROUNDPLOT system variable using (DsdData dsdDataFile = new DsdData()) { //dsdDataFile.ReadDsd(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\batchdrawings2.dsd"); dsdDataFile.ReadDsd(Path.ChangeExtension(path, "dsd")); // + "\\batchdrawings2.dsd"); // Get the DWG to PDF.pc3 and use it as a // device override for all the layouts PlotConfig acPlCfg = PlotConfigManager.SetCurrentConfig("DWG to PDF.PC3"); Application.Publisher.PublishExecute(dsdDataFile, acPlCfg); } } catch (Autodesk.AutoCAD.Runtime.Exception es) { MessengerManager.MessengerManager.LogException(es); } } } }
// overload no scale factor or set the view - just make the layout public void LayoutAndViewport(Database db, string layoutName, out ObjectId rvpid, string deviceName, string mediaName, out ObjectId id) { // set default values rvpid = new ObjectId(); bool flagVp = false; // flag to create a new floating view port double viewSize = (double)Application.GetSystemVariable("VIEWSIZE"); double height = viewSize; double width = viewSize; Point2d loCenter = new Point2d(); // layout center point Point2d vpLowerCorner = new Point2d(); Point2d vpUpperCorner = new Point2d(); Document doc = Application.DocumentManager.MdiActiveDocument; LayoutManager lm = LayoutManager.Current; id = lm.CreateLayout(layoutName); using (Transaction tr = db.TransactionManager.StartTransaction()) { Layout lo = tr.GetObject(id, OpenMode.ForWrite, false) as Layout; if (lo != null) { lm.CurrentLayout = lo.LayoutName; // make it current! #region do some plotting settings here for the paper size... ObjectId loid = lm.GetLayoutId(lo.LayoutName); PlotInfo pi = new PlotInfo(); pi.Layout = loid; PlotSettings ps = new PlotSettings(false); PlotSettingsValidator psv = PlotSettingsValidator.Current; psv.RefreshLists(ps); psv.SetPlotConfigurationName(ps, deviceName, mediaName); psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Layout); psv.SetPlotPaperUnits(ps, PlotPaperUnit.Inches); psv.SetUseStandardScale(ps, true); psv.SetStdScaleType(ps, StdScaleType.ScaleToFit); // use this as default pi.OverrideSettings = ps; PlotInfoValidator piv = new PlotInfoValidator(); piv.Validate(pi); lo.CopyFrom(ps); PlotConfig pc = PlotConfigManager.CurrentConfig; // returns data in millimeters... MediaBounds mb = pc.GetMediaBounds(mediaName); Point2d p1 = mb.LowerLeftPrintableArea; Point2d p3 = mb.UpperRightPrintableArea; Point2d p2 = new Point2d(p3.X, p1.Y); Point2d p4 = new Point2d(p1.X, p3.Y); // convert millimeters to inches double mm2inch = 25.4; height = p1.GetDistanceTo(p4) / mm2inch; width = p1.GetDistanceTo(p2) / mm2inch; vpLowerCorner = lo.PlotOrigin; vpUpperCorner = new Point2d(vpLowerCorner.X + width, vpLowerCorner.Y + height); LineSegment2d seg = new LineSegment2d(vpLowerCorner, vpUpperCorner); loCenter = seg.MidPoint; #endregion if (lo.GetViewports().Count == 1) // Viewport was not created by default { // the create by default view ports on new layouts it // is off we need to mark a flag to generate a new one // in another transaction - out of this one flagVp = true; } else if (lo.GetViewports().Count == 2) // create Viewports by default it is on { // extract the last item from the collection // of view ports inside of the layout int i = lo.GetViewports().Count - 1; ObjectId vpId = lo.GetViewports()[i]; if (!vpId.IsNull) { Viewport vp = tr.GetObject(vpId, OpenMode.ForWrite, false) as Viewport; if (vp != null) { vp.Height = height; // change height vp.Width = width; // change width vp.CenterPoint = new Point3d(loCenter.X, loCenter.Y, 0.0); // change center //vp.ColorIndex = 1; // debug // zoom to the Viewport extents Zoom(new Point3d(vpLowerCorner.X, vpLowerCorner.Y, 0.0), new Point3d(vpUpperCorner.X, vpUpperCorner.Y, 0.0), new Point3d(), 1.0); rvpid = vp.ObjectId; // return the output ObjectId to out... } } } } tr.Commit(); } // end of transaction // we need another transaction to create a new paper space floating Viewport if (flagVp) { using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr_ps = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForWrite); Viewport vp = new Viewport(); vp.Height = height; // set the height vp.Width = width; // set the width vp.CenterPoint = new Point3d(loCenter.X, loCenter.Y, 0.0); // set the center //vp.ColorIndex = 2; // debug btr_ps.AppendEntity(vp); tr.AddNewlyCreatedDBObject(vp, true); vp.On = true; // make it accessible! // zoom to the Viewport extents Zoom(new Point3d(vpLowerCorner.X, vpLowerCorner.Y, 0.0), new Point3d(vpUpperCorner.X, vpUpperCorner.Y, 0.0), new Point3d(), 1.0); rvpid = vp.ObjectId; // return the ObjectId to the out... tr.Commit(); } // end of transaction } }
public void DrawGridLines(ICanvas canvas, PlotConfig info, Tick[] ticks) { DrawVerticalGridLines(canvas, info, ticks); }
static public void BatchPublish(System.Collections.Generic.List <string> docsToPlot) { DsdEntryCollection collection = new DsdEntryCollection(); Document doc = Application.DocumentManager.MdiActiveDocument; foreach (string filename in docsToPlot) { using (DocumentLock doclock = doc.LockDocument()) { Database db = new Database(false, true); db.ReadDwgFile( filename, System.IO.FileShare.Read, true, ""); System.IO.FileInfo fi = new System.IO.FileInfo(filename); string docName = fi.Name.Substring(0, fi.Name.Length - 4); using (Transaction Tx = db.TransactionManager.StartTransaction()) { foreach (ObjectId layoutId in getLayoutIds(db)) { Layout layout = Tx.GetObject(layoutId, OpenMode.ForRead) as Layout; DsdEntry entry = new DsdEntry { DwgName = filename, Layout = layout.LayoutName, Title = docName + "_" + layout.LayoutName }; entry.NpsSourceDwg = entry.DwgName; entry.Nps = "Setup1"; collection.Add(entry); } Tx.Commit(); } } } DsdData dsdData = new DsdData(); dsdData.SheetType = SheetType.MultiPdf; dsdData.ProjectPath = @"C:\Users\yusufzhon.marasulov\Desktop\test"; //Not used for "SheetType.SingleDwf" //dsdData.DestinationName = dsdData.ProjectPath + "\\output.dwf"; dsdData.SetDsdEntryCollection(collection); string dsdFile = dsdData.ProjectPath + "\\dsdData.dsd"; //Workaround to avoid promp for dwf file name //set PromptForDwfName=FALSE in dsdData //using StreamReader/StreamWriter if (System.IO.File.Exists(dsdFile)) { System.IO.File.Delete(dsdFile); } dsdData.WriteDsd(dsdFile); System.IO.StreamReader sr = new System.IO.StreamReader(dsdFile); string str = sr.ReadToEnd(); sr.Close(); str = str.Replace( "PromptForDwfName=TRUE", "PromptForDwfName=FALSE"); System.IO.StreamWriter sw = new System.IO.StreamWriter(dsdFile); sw.Write(str); sw.Close(); dsdData.ReadDsd(dsdFile); System.IO.File.Delete(dsdFile); PlotConfig plotConfig = Autodesk.AutoCAD.PlottingServices.PlotConfigManager.SetCurrentConfig("DWG_To_PDF_Uzle.pc3"); Autodesk.AutoCAD.Publishing.Publisher publisher = Autodesk.AutoCAD.ApplicationServices.Application.Publisher; publisher.PublishExecute(dsdData, plotConfig); }
static public void PublishAllLayouts() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; //put the plot in foreground short bgPlot = (short)Application.GetSystemVariable("BACKGROUNDPLOT"); Application.SetSystemVariable("BACKGROUNDPLOT", 0); //get the layout ObjectId List List <ObjectId> layoutIds = GetLayoutIds(db); string dwgFileName = (string)Application.GetSystemVariable("DWGNAME"); string dwgPath = (string)Application.GetSystemVariable("DWGPREFIX"); using (Transaction Tx = db.TransactionManager.StartTransaction()) { DsdEntryCollection collection = new DsdEntryCollection(); foreach (ObjectId layoutId in layoutIds) { Layout layout = Tx.GetObject(layoutId, OpenMode.ForRead) as Layout; if (layout.LayoutName != "Model") { DsdEntry entry = new DsdEntry(); entry.DwgName = dwgPath + dwgFileName; entry.Layout = layout.LayoutName; entry.Title = "Layout_" + layout.LayoutName; entry.NpsSourceDwg = entry.DwgName; entry.Nps = "Setup1"; collection.Add(entry); } //TODO have to think about creating collection depend of block view } dwgFileName = dwgFileName.Substring(0, dwgFileName.Length - 4); DsdData dsdData = new DsdData(); dsdData.SheetType = SheetType.MultiPdf; //SheetType.MultiPdf dsdData.ProjectPath = dwgPath; dsdData.DestinationName = $"{dsdData.ProjectPath}{dwgFileName}.pdf"; if (System.IO.File.Exists(dsdData.DestinationName)) { System.IO.File.Delete(dsdData.DestinationName); } dsdData.SetDsdEntryCollection(collection); string dsdFile = $"{dsdData.ProjectPath}{dwgFileName}.dsd"; //Workaround to avoid promp for dwf file name //set PromptForDwfName=FALSE in dsdData using //StreamReader/StreamWriter dsdData.WriteDsd(dsdFile); //System.IO.StreamReader sr = // new System.IO.StreamReader(dsdFile, Encoding.Default); //string str = sr.ReadToEnd(); //sr.Close(); //str = str.Replace( // "PromptForDwfName=TRUE", "PromptForDwfName=FALSE"); //System.IO.StreamWriter sw = // new System.IO.StreamWriter(dsdFile, true, Encoding.Default); //sw.Write(str); //sw.Close(); dsdData.ReadDsd(dsdFile); System.IO.File.Delete(dsdFile); PlotConfig plotConfig = Autodesk.AutoCAD.PlottingServices.PlotConfigManager.SetCurrentConfig("DWG_To_PDF_Uzle.pc3"); //PlotConfig pc = Autodesk.AutoCAD.PlottingServices. // PlotConfigManager.SetCurrentConfig("DWG To PDF.pc3"); Autodesk.AutoCAD.Publishing.Publisher publisher = Autodesk.AutoCAD.ApplicationServices.Application.Publisher; publisher.AboutToBeginPublishing += new Autodesk.AutoCAD.Publishing. AboutToBeginPublishingEventHandler( Publisher_AboutToBeginPublishing); dsdData.PromptForDwfName = false; publisher.PublishExecute(dsdData, plotConfig); Tx.Commit(); } //reset the background plot value Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot); }
static public void PublishViews2MultiSheet() { pwdWindow = new PasswordWindow(); pwdWindow.ShowDialog(); Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; StringCollection viewsToPlot = new StringCollection(); viewsToPlot.Add("Test1"); viewsToPlot.Add("Test2"); using (Transaction Tx = db.TransactionManager.StartTransaction()) { ObjectId layoutId = LayoutManager.Current.GetLayoutId(LayoutManager.Current.CurrentLayout); Layout layout = Tx.GetObject(layoutId, OpenMode.ForWrite) as Layout; foreach (String viewName in viewsToPlot) { PlotSettings plotSettings = new PlotSettings(layout.ModelType); plotSettings.CopyFrom(layout); PlotSettingsValidator psv = PlotSettingsValidator.Current; psv.SetPlotConfigurationName(plotSettings, "DWF6 ePlot.pc3", "ANSI_A_(8.50_x_11.00_Inches)"); psv.RefreshLists(plotSettings); psv.SetPlotViewName(plotSettings, viewName); psv.SetPlotType(plotSettings, Autodesk.AutoCAD.DatabaseServices.PlotType.View); psv.SetUseStandardScale(plotSettings, true); psv.SetStdScaleType(plotSettings, StdScaleType.ScaleToFit); psv.SetPlotCentered(plotSettings, true); psv.SetPlotRotation(plotSettings, PlotRotation.Degrees000); psv.SetPlotPaperUnits(plotSettings, PlotPaperUnit.Inches); plotSettings.PlotSettingsName = String.Format("{0}{1}", viewName, "PS"); plotSettings.PrintLineweights = true; plotSettings.AddToPlotSettingsDictionary(db); Tx.AddNewlyCreatedDBObject(plotSettings, true); psv.RefreshLists(plotSettings); layout.CopyFrom(plotSettings); } Tx.Commit(); } short bgPlot = (short)Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("BACKGROUNDPLOT"); Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("BACKGROUNDPLOT", 0); string dwgFileName = Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("DWGNAME") as string; string dwgPath = Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("DWGPREFIX") as string; using (Transaction Tx = db.TransactionManager.StartTransaction()) { DsdEntryCollection collection = new DsdEntryCollection(); ObjectId activeLayoutId = LayoutManager.Current.GetLayoutId(LayoutManager.Current.CurrentLayout); foreach (String viewName in viewsToPlot) { Layout layout = Tx.GetObject(activeLayoutId, OpenMode.ForRead) as Layout; DsdEntry entry = new DsdEntry(); entry.DwgName = dwgPath + dwgFileName; entry.Layout = layout.LayoutName; entry.Title = viewName; entry.NpsSourceDwg = entry.DwgName; entry.Nps = String.Format("{0}{1}", viewName, "PS"); collection.Add(entry); } dwgFileName = dwgFileName.Substring(0, dwgFileName.Length - 4); DsdData dsdData = new DsdData(); dsdData.SheetType = SheetType.MultiDwf; dsdData.ProjectPath = dwgPath; dsdData.DestinationName = dsdData.ProjectPath + dwgFileName + ".dwf"; /*Get password from user*/ dsdData.Password = pwdWindow.passwordBox.Password; if (System.IO.File.Exists(dsdData.DestinationName)) { System.IO.File.Delete(dsdData.DestinationName); } dsdData.SetDsdEntryCollection(collection); /*DsdFile */ string dsdFile = dsdData.ProjectPath + dwgFileName + ".dsd"; dsdData.WriteDsd(dsdFile); System.IO.StreamReader sr = new System.IO.StreamReader(dsdFile); string str = sr.ReadToEnd(); sr.Close(); str = str.Replace("PromptForDwfName=TRUE", "PromptForDwfName=FALSE"); /*Prompts User to Enter Password and Reconfirms*/ //str = str.Replace("PromptForPwd=FALSE", // "PromptForPwd=TRUE"); //str = str.Replace("PwdProtectPublishedDWF=FALSE", // "PwdProtectPublishedDWF=TRUE"); int occ = 0; int index = str.IndexOf("Setup="); int startIndex = 0; StringBuilder dsdText = new StringBuilder(); while (index != -1) { String str1 = str.Substring(startIndex, index + 6 - startIndex); dsdText.Append(str1); dsdText.Append(String.Format("{0}{1}", viewsToPlot[occ], "PS")); startIndex = index + 6; index = str.IndexOf("Setup=", index + 6); if (index == -1) { dsdText.Append(str.Substring(startIndex, str.Length - startIndex)); } occ++; } System.IO.StreamWriter sw = new System.IO.StreamWriter(dsdFile); sw.Write(dsdText.ToString()); sw.Close(); dsdData.ReadDsd(dsdFile); System.IO.File.Delete(dsdFile); PlotConfig plotConfig = PlotConfigManager.SetCurrentConfig("DWF6 ePlot.pc3"); Publisher publisher = Autodesk.AutoCAD.ApplicationServices.Core.Application.Publisher; publisher.PublishExecute(dsdData, plotConfig); Tx.Commit(); } Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot); }