解决方案 | 获取所有的打印输出的图纸尺寸的名称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
复制代码

 

posted @   IssacNew  阅读(82)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示