离碎 发表于 2024-8-6 22:47:42

获取打印机纸张的大小

我已经获取了打印机,及对应打印的纸张名称,如何获得对应纸张的大小,用于打印时判断图形是否需要旋转

badboy518 发表于 2024-8-7 08:18:42

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.PlottingServices;


namespace XyCadTools.print
{
    public class PrintHelper
    {
      /// <summary>
      /// 获取布局的打印设备列表(含实体打印机和虚拟打印机)
      /// </summary>
      /// <returns>布局打印设备字符串列表</returns>
      public static List<string> GetPlotDeviceList()
      {
            var psv = PlotSettingsValidator.Current;
            var plotDeviceList = psv.GetPlotDeviceList().Cast<string>().ToList();
            return plotDeviceList;
      }

      /// <summary>
      /// 获取布局设备打印机的纸张列表
      /// </summary>
      /// <returns>布局打印设备字符串列表</returns>
      public static List<string> GetPlotDevicePageNameList(string plotDeviceName)
      {
            PlotConfig plotConfig = PlotConfigManager.SetCurrentConfig(plotDeviceName);
            plotConfig.RefreshMediaNameList();
            return plotConfig.CanonicalMediaNames.Cast<string>().ToList();
      }



      public static void test()
      {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            var dList = GetPlotDeviceList();
            foreach (string deviceName in dList)
            {
                var pageNameList = GetPlotDevicePageNameList(deviceName);
                var dt = DateTime.Now;
                foreach (string pageName in pageNameList) {
                  ed.WriteMessage($"{dt:yyyy-M-d dddd}{deviceName}包含的纸张:{pageName}\n");
                }
               
            }
      }
      
    }
}

离碎 发表于 2024-8-7 11:37:41

本帖最后由 离碎 于 2024-8-7 11:39 编辑

你上面的代码是获取打印机,及对应打印机下面的纸张名,我需要的是对因该纸张的尺寸,比如纸张A4,他有可能是210X297的纸,也有可能是297X210的,我要怎么才能知道纸张是横向还是竖向的,CAD自带的打印机纸张有ISO_A4_(297.00_x_210.00_MM),也有ISO_A4_(210.00_x_297.00_MM),主要就是知道纸张的是横竖向的,我打印时好判断图纸是否需要旋转

离碎 发表于 2024-8-7 12:23:49

已解决
'设置打印方向
Autodesk.AutoCAD.PlottingServices.PlotConfigManager.SetCurrentConfig(ComboBox6.Text)
Dim plotConfig As PlotConfig = Autodesk.AutoCAD.PlottingServices.PlotConfigManager.CurrentConfig
plotConfig.RefreshMediaNameList()
plotConfig.GetMediaBounds(ComboBox7.Text)
Dim PaperSize As Point2d = plotConfig.GetMediaBounds(ComboBox7.Text).PageSize
Dim MinPt As Point2d = DyArea.Area.MinPoint, MaxPt As Point2d = DyArea.Area.MaxPoint
Dim X As Double = Math.Abs(MaxPt.X - MinPt.X), Y As Double = Math.Abs(MaxPt.Y - MinPt.Y)
Select Case comboBox4.Text'打印方向
   Case "自动"
         If PaperSize.Y > PaperSize.X Then
             If X > Y Then acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees090)
         Else
             If Y > X Then acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees090)
         End If
   Case "纵向"
         If X > Y Then acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees090)
   Case "横向"
         If Y > X Then acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees090)
End Select

羊羊羊 发表于 2024-9-5 11:24:29

能设置加长图纸吗

你有种再说一遍 发表于 2024-9-5 20:33:32

羊羊羊 发表于 2024-9-5 11:24
能设置加长图纸吗

那么多年了,都没有看过我博客吗?

羊羊羊 发表于 2024-9-8 00:59:42

看过么,好复杂
页: [1]
查看完整版本: 获取打印机纸张的大小