- UID
- 727391
- 积分
- 12
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2014-3-8
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2014-9-17 13:26:31
|
显示全部楼层
本帖最后由 quwang2000 于 2014-9-17 13:33 编辑
'模型空间PDF打印设置(不启动打印进度跟踪框)
Public Sub PDFPlotmodle(ByRef cldoc As Document, ByRef tukuanghao As String, ByRef acplextents As Extents2d, ByRef tuzhifilename As String, ByRef bili As Double)
Dim acCurDb As Database = cldoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' 引用布局管理器LayoutManager
Dim acLayoutMgr As LayoutManager
acLayoutMgr = LayoutManager.Current
'' 获取当前布局,在命令行窗口显示布局名字
Dim acLayout As Layout
acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForRead)
'' 从布局中获取PlotInfo
Dim acPlInfo As PlotInfo = New PlotInfo()
acPlInfo.Layout = acLayout.ObjectId
'' 复制布局中的PlotSettings
Dim acPlSet As PlotSettings = New PlotSettings(acLayout.ModelType)
acPlSet.CopyFrom(acLayout)
'' 更新PlotSettings对象
Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current
'' 设置打印区域(以下两句顺序不能反)
acPlSetVdr.SetPlotWindowArea(acPlSet, acplextents)
acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Window)
'' 设置打印比例
acPlSetVdr.SetUseStandardScale(acPlSet, True)
acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit)
'' 居中打印
acPlSetVdr.SetPlotCentered(acPlSet, True)
'' 设置使用的打印设备
Select Case tukuanghao
Case "A4"
'' 设置打印方向
acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000)
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", "ISO_A4_(210.00_x_297.00_MM)")
Case "A3"
'' 设置打印方向
acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000)
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", "ISO_A3_(420.00_x_297.00_MM)")
Case "A2"
'' 设置打印方向
acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000)
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", "ISO_A2_(594.00_x_420.00_MM)")
Case "A1"
'' 设置打印方向
acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000)
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", "ISO_A1_(841.00_x_594.00_MM)")
Case "A0"
'' 设置打印方向
acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees270)
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", "ISO_A0_(841.00_x_1189.00_MM)")
End Select
'刷新设备列表(重要,不刷新不能正确设置打印样式)
acPlSetVdr.RefreshLists(acPlSet)
'设置打印尺寸单位(mm)
acPlSetVdr.SetPlotPaperUnits(acPlSet, PlotPaperUnit.Millimeters)
'' 设置打印样式
acPlSetVdr.SetCurrentStyleSheet(acPlSet, "monochrome.ctb")
'' 用上述设置信息覆盖PlotInfo对象,
'' 不会将修改保存回布局
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()
acPlEng.BeginPlot(Nothing, Nothing)
'' 定义打印输出
Dim File As String = cldoc.Name
Dim fileinfo As FileInfo = New FileInfo(File)
Dim path As String = fileinfo.DirectoryName
Dim outtuzhifilename As String = Replace(tuzhifilename, "/", "-")
If Not Directory.Exists(path & "pdf图纸") Then
FileIO.FileSystem.CreateDirectory(path & "pdf图纸")
End If
Dim outfilename As String = path & "pdf图纸\" & outtuzhifilename
If FileIO.FileSystem.FileExists(outfilename & ".pdf") Then
cmfilecount += 1
outfilename = outfilename & "(" & cmfilecount.ToString() & ")"
acPlEng.BeginDocument(acPlInfo, cldoc.Name, Nothing, 1, True, outfilename)
Else
acPlEng.BeginDocument(acPlInfo, cldoc.Name, Nothing, 1, True, outfilename)
End If
'' 打印第一张图/布局
Dim acPlPageInfo As PlotPageInfo = New PlotPageInfo()
acPlEng.BeginPage(acPlPageInfo, acPlInfo, True, Nothing)
acPlEng.BeginGenerateGraphics(Nothing)
acPlEng.EndGenerateGraphics(Nothing)
'' 结束第一张图/布局的打印
acPlEng.EndPage(Nothing)
'' 结束文档局的打印
acPlEng.EndDocument(Nothing)
'' 打印结束
acPlEng.EndPlot(Nothing)
End Using
End If
acTrans.Commit()
'释放资源
acPlInfo.Dispose()
acPlSet.Dispose()
End Using
End Sub
|
|