解决方案 | 获取所有的打印输出的图纸尺寸的名称GetCanonicalMediaNames返回为空的原因竟然是官方帮助文件给我带来了误导-CAD VBA
巨大的坑,该代码来自于acadauto_2014--AutoCAD2014 ActiveX Reference Guide.chm 但是存在一个巨大的bug。
'获取所有的打印输出的图纸尺寸的名称 ,但是事前必须设置【打印机对象】也就是 Layouts("Model").ConfigName = "DWF Classic.pc3" 这样的代码,否则返回为空。
也就是说,必须先设置打印机,才能知道可打印图纸的尺寸。这个逻辑才是对的。这里是采用的vba ,其他的语言比如Python也是一样的
Sub Example_GetCanonicalMediaNames() '获取所有的打印输出的图纸尺寸的名称 ,但是事前必须设置【打印机对象】也就是 Layouts("Model").ConfigName = "DWF Classic.pc3" 这样的代码,否则返回为空 ' This example gets the current plot device information ' and then displays the list of plot device names, ' media names, localized media names, and plot style ' table entries. Dim Layout As ACADLayout Set Layout = ThisDrawing.ModelSpace.Layout ' Refresh the current plot information for ' this session. Layout.RefreshPlotDeviceInfo ' List all the valid device names for the system Dim plotDevices As Variant plotDevices = Layout.GetPlotDeviceNames() Dim x As Integer For x = LBound(plotDevices) To UBound(plotDevices) MsgBox plotDevices(x) Next ' List all the media names, and their localized version Dim mediaNames As Variant mediaNames = Layout.GetCanonicalMediaNames() For x = LBound(mediaNames) To UBound(mediaNames) MsgBox mediaNames(x) MsgBox Layout.GetLocaleMediaName(mediaNames(x)) Next ' List all the entries in the plot style table Dim styleNames As Variant styleNames = Layout.GetPlotStyleTableNames() For x = LBound(styleNames) To UBound(styleNames) MsgBox styleNames(x) Next End Sub
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)