田草博客

互联网田草博客


网友交流QQ群:11740834 需注明申请加入原因

微信 公众号:ByCAD

邮箱:tiancao1001x126.com
ByCAD,微信公众号
首页 | 普通 | 电脑 | AutoCAD | VB/VB.NET | FLash | 结构 | 建筑 | 电影 | BIM | 规范 | 软件 | ID
-随机-|-分布-
-博客论坛-|-﨣﨤﨧﨨-
-网站导航-|-规范下载-
-BelovedFLash欣赏-

用户登陆
用户:
密码:
 

站点日历
73 2024 - 12 48
1234567
891011121314
15161718192021
22232425262728
293031


站点统计

最新评论



VB .net 获取AutoCAD2006安装路径 vb.net AutoCAD 导出wmf
未知 VB.net AutoCAD 打印窗口打印   [ 日期:2009-11-18 ]   [ 来自:本站原创 ]  HTML
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.PlottingServices

Public Class class1
    <CommandMethod("PlotTest")> _
    Public Sub PlotTest()
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            Dim acLayoutMgr As LayoutManager
            acLayoutMgr = LayoutManager.Current
            Dim acLayout As Layout
            acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), _
                                         OpenMode.ForRead)
            Dim acPlInfo As PlotInfo = New PlotInfo()
            acPlInfo.Layout = acLayout.ObjectId

            Dim acPlSet As PlotSettings = New PlotSettings(acLayout.ModelType)
            acPlSet.CopyFrom(acLayout)

            Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current


            '' 打印比例
            acPlSetVdr.SetUseStandardScale(acPlSet, True)
            acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit) '充满图纸

            '' 居中打印
            acPlSetVdr.SetPlotCentered(acPlSet, True)


            '' 打印设备和图纸
            acPlSetVdr.SetPlotConfigurationName(acPlSet, "PublishToWeb JPG.pc3", _
                                                "User-1")
            '先GetPoint然后再GetCorner
            Dim pPtRes As PromptPointResult
            Dim pPtOpts As PromptPointOptions = New PromptPointOptions("")
            pPtOpts.Message = vbLf & "请选择其中一个角点: "
            pPtRes = acDoc.Editor.GetPoint(pPtOpts)
            Dim PT1 As Point3d = pPtRes.Value
            Dim pCnOpts As PromptCornerOptions = New PromptCornerOptions("请选择一个对角点:", PT1)
            pPtRes = acDoc.Editor.GetCorner(pCnOpts)
            Dim PT2 As Point3d = pPtRes.Value

            '设置打印窗口
            Dim minX As Double = System.Math.Min(PT1.X, PT2.X)
            Dim minY As Double = System.Math.Min(PT1.Y, PT2.Y)
            Dim maxX As Double = System.Math.Max(PT1.X, PT2.X)
            Dim maxY As Double = System.Math.Max(PT1.Y, PT2.Y)

            Dim E2d As Extents2d = New Extents2d(minX, minY, maxX, maxY)


            acPlSetVdr.SetPlotWindowArea(acPlSet, E2d)
            acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Window)

            acPlInfo.OverrideSettings = acPlSet

            Dim acPlInfoVdr As PlotInfoValidator = New PlotInfoValidator()
            acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
            acPlInfoVdr.Validate(acPlInfo)

            If PlotFactory.ProcessPlotState = Autodesk.AutoCAD.PlottingServices. _
                                                  ProcessPlotState.NotPlotting Then
                Using acPlEng As PlotEngine = PlotFactory.CreatePublishEngine()

                    Dim acPlProgDlg As PlotProgressDialog = New PlotProgressDialog(False, _
                                                                                   1, _
                                                                                   True)
                    Using (acPlProgDlg)
                        acPlProgDlg.PlotMsgString(PlotMessageIndex.DialogTitle) = "打印进度"
                        acPlProgDlg.PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage) = "取消打印"
                        acPlProgDlg.PlotMsgString(PlotMessageIndex.SheetProgressCaption) ="打印进度"

                        acPlProgDlg.LowerPlotProgressRange = 0
                        acPlProgDlg.UpperPlotProgressRange = 100
                        acPlProgDlg.PlotProgressPos = 0
                        acPlProgDlg.OnBeginPlot()
                        acPlProgDlg.IsVisible = True

                        acPlEng.BeginPlot(acPlProgDlg, Nothing)

                        acPlEng.BeginDocument(acPlInfo, _
                                              acDoc.Name, _
                                              Nothing, _
                                              1, _
                                              True, _
                                              "c:\PlotTest")

                        acPlProgDlg.PlotMsgString(PlotMessageIndex.Status) = _
                                                      "正在打印 " & acDoc.Name & _
                                                      " - " & acLayout.LayoutName

                        acPlProgDlg.OnBeginSheet()
                        acPlProgDlg.LowerSheetProgressRange = 0
                        acPlProgDlg.UpperSheetProgressRange = 100
                        acPlProgDlg.SheetProgressPos = 0

                        Dim acPlPageInfo As PlotPageInfo = New PlotPageInfo()
                        acPlEng.BeginPage(acPlPageInfo, _
                                          acPlInfo, _
                                          True, _
                                          Nothing)

                        acPlEng.BeginGenerateGraphics(Nothing)
                        acPlEng.EndGenerateGraphics(Nothing)

                        acPlEng.EndPage(Nothing)
                        acPlProgDlg.SheetProgressPos = 100
                        acPlProgDlg.OnEndSheet()

                        acPlEng.EndDocument(Nothing)

                        acPlProgDlg.PlotProgressPos = 100
                        acPlProgDlg.OnEndPlot()
                        acPlEng.EndPlot(Nothing)
                    End Using
                End Using
            End If
        End Using
    End Sub
End Class




暂时没有评论
发表评论 - 不要忘了输入验证码哦!
作者: 用户:  密码:   注册? 验证:  防止恶意留言请输入问题答案:2*9=?  
评论:

禁止表情
禁止UBB
禁止图片
识别链接
识别关键字

字体样式 文字大小 文字颜色
插入粗体文本 插入斜体文本 插入下划线
左对齐 居中对齐 右对齐
插入超级链接 插入邮件地址 插入图像
插入 Flash 插入代码 插入引用
插入列表 插入音频文件 插入视频文件
插入缩进符合
点击下载按钮 下标 上标
水平线 简介分割标记
表  情
 
Tiancao Blog All Rights Reserved 田草博客 版权所有
Copyright ©