cad打印代码(6)

2019-09-01 11:09

'设置是否居中打印

chkCenterPlot.Value = objOriginalPC.CenterPlot '设置打印偏移

If Not chkCenterPlot.Value Then Dim ptPlotOrigin As Variant '读取打印偏移

ptPlotOrigin = objOriginalPC.PlotOrigin '设置打印偏移

'图形方向为“横向”时宽高互调

OffsetX = IIf(optVertical.Value, ptPlotOrigin(0), ptPlotOrigin(1)) OffsetY = IIf(optVertical.Value, ptPlotOrigin(1), ptPlotOrigin(0)) txtOffsetX.Text = OffsetX txtOffsetY.Text = OffsetY End If

'设置图纸打印份数

txtNumber.Text = objPlot.NumberOfCopies

'设置“打印到文件”是否选中 chkPlotToFile.Value = False '禁用“打印到文件”组各控件 lbPlotPath.Enabled = False cboPlotPath.Enabled = False cmdBrowse2.Enabled = False

'设置打印选项

chkPlotWithPlotStyles.Value = objOriginalPC.PlotWithPlotStyles

chkPlotWithLineweights.Enabled = Not (chkPlotWithPlotStyles.Value) chkPlotWithLineweights.Value = objOriginalPC.PlotWithLineweights chkPlotHidden.Value = objOriginalPC.PlotHidden

' 显示AutoCAD中当前可用的图块 Call ListBlock

' 显示AutoCAD中当前可用的图层 Call ListLayer

End Sub

Public Sub GetPlotRotation()

Dim PaperWidth As Double, PaperHeight As Double, t As Double '取得图纸尺寸信息

objOriginalPC.GetPaperSize PaperWidth, PaperHeight '设置图纸方向

If PaperWidth < PaperHeight Then

Select Case objOriginalPC.PlotRotation Case ac0degrees

optVertical.Value = True chkReverse.Value = False Case ac90degrees

optHorizontal.Value = True chkReverse.Value = False Case ac180degrees

optVertical.Value = True chkReverse.Value = True Case ac270degrees

optHorizontal.Value = True chkReverse.Value = True End Select Else

Select Case objOriginalPC.PlotRotation Case ac0degrees

optHorizontal.Value = True chkReverse.Value = False Case ac90degrees

optVertical.Value = True chkReverse.Value = False Case ac180degrees

optHorizontal.Value = True chkReverse.Value = True Case ac270degrees

optVertical.Value = True chkReverse.Value = True End Select End If

End Sub

Public Sub SetPlotRotation()

Dim PaperWidth As Double, PaperHeight As Double, t As Double '取得图纸尺寸信息

objPlotConfiguration.GetPaperSize PaperWidth, PaperHeight ' 设置图纸打印方向

If PaperWidth < PaperHeight Then If optVertical.Value = True Then

If chkReverse.Value = False Then

objPlotConfiguration.PlotRotation = ac0degrees Else

objPlotConfiguration.PlotRotation = ac180degrees End If Else

If chkReverse.Value = False Then

objPlotConfiguration.PlotRotation = ac90degrees Else

objPlotConfiguration.PlotRotation = ac270degrees End If End If Else

If optVertical.Value = True Then

If chkReverse.Value = False Then

objPlotConfiguration.PlotRotation = ac90degrees Else

objPlotConfiguration.PlotRotation = ac270degrees End If Else

If chkReverse.Value = False Then

objPlotConfiguration.PlotRotation = ac0degrees Else

objPlotConfiguration.PlotRotation = ac180degrees End If End If End If

End Sub

Public Sub SetPlotConfiguration()

'因有些选项会相互影响,打印前再应用一次打印配置以确保打印成功 '设置打印机配置

objPlotConfiguration.ConfigName = cboPrintersName.Text ' 设置打印样式表

objPlotConfiguration.StyleSheet = cboPlotStyleTableNames.Text ' 设置图纸尺寸 objPlotConfiguration.CanonicalMediaName = paperSizes(cboPaperSize.ListIndex) '设置图纸单位 objPlotConfiguration.PaperUnits = IIf(optMillimeters.Value, acMillimeters, acInches)

Dim Q1

'定义组合框索引到打印比例枚举值的映射

Q1 = Array(100, 0, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, _

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) ' 设置图纸打印比例

If cboPlotScale.ListIndex <> 0 Then '使用标准打印比例

objPlotConfiguration.UseStandardScale = True '设置标准打印比例

objPlotConfiguration.StandardScale = Q1(cboPlotScale.ListIndex) Else

'使用自定义打印比例

objPlotConfiguration.UseStandardScale = False '设置自定义打印比例

objPlotConfiguration.SetCustomScale Numerator, Denominator End If

' 设置图纸打印方向 Call SetPlotRotation

' 设置图纸是否居中打印

If chkCenterPlot.Value Then

objPlotConfiguration.CenterPlot = True Else

'设置自定义打印偏移

Dim ptPlotOrigin(0 To 1) As Double '图形方向为“横向”时宽高互调

ptPlotOrigin(0) = IIf(optVertical.Value, OffsetX, OffsetY) ptPlotOrigin(1) = IIf(optVertical.Value, OffsetY, OffsetX) objPlotConfiguration.CenterPlot = False

objPlotConfiguration.PlotOrigin = ptPlotOrigin End If

'设置是否应用打印样式

objPlotConfiguration.PlotWithPlotStyles = chkPlotWithPlotStyles.Value chkPlotWithLineweights.Enabled = Not (chkPlotWithPlotStyles.Value) '设置是否打印对象线宽

If Not objPlotConfiguration.PlotWithPlotStyles Then _ objPlotConfiguration.PlotWithLineweights = chkPlotWithLineweights.Value '设置是否隐藏图纸空间对象 If Not objPlotConfiguration.ModelType Then objPlotConfiguration.PlotHidden = chkPlotHidden.Value

'设置打印类型

objPlotConfiguration.PlotType = acWindow

'设置图纸打印份数

objPlot.NumberOfCopies = txtNumber.Value

'将打印错误报告切换为静默错误模式,以便不间断地执行打印任务 objPlot.QuietErrorMode = True

End Sub

Private Sub BatchPlotByBlock(strBlockReferenceName As String) On Error Resume Next '如果列表框中未存在任何元素

If lstPlotFiles.ListCount = 0 Then

MsgBox \请先向列表框中添加文件!\ Exit Sub End If

'将控制权交给AutoCAD frmBatchPlot.Hide

' 对第i个图形的每一个打印区域进行打印 Dim ptMin As Variant, ptMax As Variant Dim ent As AcadEntity

Dim i As Integer, n As Integer

For i = 0 To lstPlotFiles.ListCount - 1 n = 1

'检查文件是否存在

If Len(Dir(lstPlotFiles.List(i))) = 0 Then

MsgBox \文件\不存在!\ End If

'打开或激活第i个图形文件

Call OpenFile(lstPlotFiles.List(i))

Set objDoc = ThisDrawing.Application.ActiveDocument '实现范围缩放

ThisDrawing.Application.ZoomExtents ' 确保当前布局是模型空间

Set objLayout = objDoc.Layouts.Item(\ Set objPlot = objDoc.Plot ' 设置打印选项

Call SetPlotConfiguration ' 将打印设置应用到当前图形

objLayout.CopyFrom objPlotConfiguration '重新生成当前图形

objDoc.Regen acAllViewports

' 确保AutoCAD在前台进行打印,这样后一次打印会在前一次打印完成之后才开始,避免出现错误

objDoc.SetVariable \


cad打印代码(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:杭州市2018年中考数学真题试题(含答案)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: