CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

相关分类

查询和设置布局设置 (.NET)

2023-1-1 09:43| 发布者: admin| 查看: 280| 评论: 0|来自: AutoCAD

以下示例演示如何查询和更改当前布局的设备。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.PlottingServices
 
' Changes the plot settings for a layout directly
<CommandMethod("ChangeLayoutPlotSettings")> _
Public Shared Sub ChangeLayoutPlotSettings()
    ' Get the current document and database, and start a transaction
    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
    Dim acCurDb As Database = acDoc.Database

    Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
        ' Reference the Layout Manager
        Dim acLayoutMgr As LayoutManager = LayoutManager.Current

        ' Get the current layout and output its name in the Command Line window
        Dim acLayout As Layout = _
            acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), _
                              OpenMode.ForRead)

        ' Output the name of the current layout and its device
        acDoc.Editor.WriteMessage(vbLf & "Current layout: " & _
                                  acLayout.LayoutName)

        acDoc.Editor.WriteMessage(vbLf & "Current device name: " & _
                                  acLayout.PlotConfigurationName)

        ' Get a copy of the PlotSettings from the layout
        Using acPlSet As PlotSettings = New PlotSettings(acLayout.ModelType)
            acPlSet.CopyFrom(acLayout)

            ' Update the PlotConfigurationName property of the PlotSettings object
            Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current
            acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", _
                                                "ANSI_B_(11.00_x_17.00_Inches)")

            ' Zoom to show the whole paper
            acPlSetVdr.SetZoomToPaperOnUpdate(acPlSet, True)

            ' Update the layout
            acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForWrite)
            acLayout.CopyFrom(acPlSet)
        End Using

        ' Output the name of the new device assigned to the layout
        acDoc.Editor.WriteMessage(vbLf & "New device name: " & _
                                  acLayout.PlotConfigurationName)

        ' Save the new objects to the database
        acTrans.Commit()
    End Using

    ' Update the display
    acDoc.Editor.Regen()
End Sub

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.PlottingServices;
 
// Changes the plot settings for a layout directly
[CommandMethod("ChangeLayoutPlotSettings")]
public static void ChangeLayoutPlotSettings()
{
    // Get the current document and database, and start a transaction
    Document acDoc = Application.DocumentManager.MdiActiveDocument;
    Database acCurDb = acDoc.Database;

    using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
    {
        // Reference the Layout Manager
        LayoutManager acLayoutMgr = LayoutManager.Current;

        // Get the current layout and output its name in the Command Line window
        Layout acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout),
                                            OpenMode.ForRead) as Layout;

        // Output the name of the current layout and its device
        acDoc.Editor.WriteMessage("\nCurrent layout: " + acLayout.LayoutName);

        acDoc.Editor.WriteMessage("\nCurrent device name: " + acLayout.PlotConfigurationName);

        // Get a copy of the PlotSettings from the layout
        using (PlotSettings acPlSet = new PlotSettings(acLayout.ModelType))
        {
            acPlSet.CopyFrom(acLayout);

            // Update the PlotConfigurationName property of the PlotSettings object
            PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
            acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", "ANSI_B_(11.00_x_17.00_Inches)");

            // Zoom to show the whole paper
            acPlSetVdr.SetZoomToPaperOnUpdate(acPlSet, true);

            // Update the layout
            acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForWrite);
            acLayout.CopyFrom(acPlSet);
        }

        // Output the name of the new device assigned to the layout
        acDoc.Editor.WriteMessage("\nNew device name: " + acLayout.PlotConfigurationName);

        // Save the new objects to the database
        acTrans.Commit();
    }

    // Update the display
    acDoc.Editor.Regen();
}

VBA/ActiveX 代码参考

Public Sub ChangePlotSetting()
    Dim layoutObj As AcadLayout
    Set layoutObj = ThisDrawing.ActiveLayout
 
    ' Output the name of the current layout and its device
    ThisDrawing.Utility.Prompt vbLf & "Current layout: " & layoutObj.Name
    ThisDrawing.Utility.Prompt vbLf & "Current device name: " & _
                               layoutObj.ConfigName
 
    ' Change the name of the output device for the current layout
    layoutObj.RefreshPlotDeviceInfo
    layoutObj.ConfigName = "DWF6 ePlot.pc3"
    layoutObj.CanonicalMediaName = "ANSI_A_(8.50_x_11.00_Inches)"
 
    ' Output the name of the new device assigned to the layout
    ThisDrawing.Utility.Prompt vbLf & "Current device name: " & _
                               layoutObj.ConfigName & vbLf
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:09

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部