- 积分
- 302
- 明经币
- 个
- 注册时间
- 2012-8-1
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2022-11-11 16:01:12
|
显示全部楼层
修改后的程序
''Public Const acWindow As Integer = 4
'Public Const acMillimeter As Integer = 1
'Public Const ac0degrees As Integer = 0
'Public Const ac90degrees As Integer = 1
'Public Const acScaleToFi As Integer = 0
'Public Const acAllViewports As Integer = 1
'Public Const acModelSpace As Integer = 1
'简单说明一下打印函数
'cadDoc - 打开的cad文件
'kuainame - 打印图框名称
'PrinterName -打印机名称
'Styles -样式表名称
'MediaName -纸张大小
'AutoMedia -自动纸张开关
'AutoRotate -自动旋转, 纵向 / 横向
Function PlotFunction(cadDoc As Object, kuainame As String, PrinterName As String, Styles As String, MediaName As String, AutoMedia As Boolean, AutoRotate As Boolean)
On Error Resume Next
cadDoc.Application.ZoomAll
Rem 根据图框位置排序后进行打印
Dim sel_block As Object
Set sel_block = add_ss(cadDoc, "sel_block") '调用函数,创建选择集
'根据图块名称多少,调用BuildFilter,构建图元表过滤表达式,指定不同的图元过滤表达式
Dim tknum
If InStr(1, kuainame, ";") Then
matches = Split(kuainame, ";")
tknum = UBound(matches)
Select Case tknum
Case 1
BuildFilter pType1, pData1, -4, "<OR", 2, matches(0), 2, matches(1), -4, "OR>"
Case 2
BuildFilter pType1, pData1, -4, "<OR", 2, matches(0), 2, matches(1), 2, matches(2), -4, "OR>"
Case 3
BuildFilter pType1, pData1, -4, "<OR", 2, matches(0), 2, matches(1), 2, matches(2), 2, matches(3) - 4, "OR>"
End Select
Else
BuildFilter pType1, pData1, 2, kuainame
End If
sel_block.Select acSelectionSetAll, , , pType1, pData1
On Error Resume Next
Dim blockarry() As BlockArray
Dim blocknow As BlockArray
Dim inPt As Variant '获取块的插入位置坐标
Dim i As Integer
i = 0
For Each t In sel_block
inPt = t.InsertionPoint
With blocknow
Set .blockObj = t
.blockX = inPt(0)
.blockY = inPt(1)
End With
i = i + 1
ReDim Preserve blockarry(1 To i)
With blockarry(i)
Set .blockObj = blocknow.blockObj
.blockX = blocknow.blockX
.blockY = blocknow.blockY
'Debug.Print blockarry(1).blockObj.Name
End With
Call MaopaoBlockArry(blockarry())
Next t
'Dim Ent As Object
'Dim PlotCount As Integer
'Application.ScreenUpdating = False
'打印参数设置
''环境参数设置
' Dim Osmode As Integer
' Osmode = cadDoc.GetVariable("osmode")
' cadDoc.SetVariable "osmode", 0
'
' Dim Blipmode As Integer
' Blipmode = cadDoc.GetVariable("blipmode")
' cadDoc.SetVariable "blipmode", 0
'
' Dim Cmdecho As Integer
' Cmdecho = cadDoc.GetVariable("cmdecho")
' cadDoc.SetVariable "cmdecho", 0
Dim ptMin As Variant, ptMax As Variant
' 检查当时空间是否为模型空间
'If objDoc.ActiveSpace = acPaperSpace Then
' objDoc.MSpace = True
' objDoc.ActiveSpace = acModelSpace
'End If
'Set objLayout = cadDoc.Layouts.Item("模型")
Set objLayout = cadDoc.Layouts.Item("Model") '打印空白的内容
'Set ActiveLayout = cadDoc.Layouts.Item("Model") 'ActiveLayout对应的旋转命令有效
'Set ActiveLayout = objDoc.ModelSpace.Layout
'Set ActiveLayout = cadDoc.Layouts.Item("模型") '使用图纸默认的模型布局,而且后面的选择无效
Set objPlot = cadDoc.Plot
cadDoc.Application.ZoomExtents
'
'
' 设置打印机
If Not Trim(PrinterName) = "" Then
objLayout.ConfigName = PrinterName
'ActiveLayout.ConfigName = PrinterName
Else
Exit Function
End If
' 设置打印样式表
If Not Trim(Styles) = "" Then
objLayout.StyleSheet = Styles
'ActiveLayout.StyleSheet = Styles
Else
objLayout.StyleSheet = "acad.ctb"
'ActiveLayout.StyleSheet = "acad.ctb"
End If
' 设置图纸尺寸
If AutoMedia Then
objLayout.CanonicalMediaName = "A4"
'ActiveLayout.CanonicalMediaName = "A4"
Else
If Not Trim(MediaName) = "" Then
objLayout.CanonicalMediaName = MediaName
'ActiveLayout.CanonicalMediaName = MediaName
Else
objLayout.CanonicalMediaName = "A4"
'ActiveLayout.CanonicalMediaName = "A4"
End If
End If
' 设置图纸单位
objLayout.PaperUnits = acMillimeters
'ActiveLayout.PaperUnits = acMillimeters
' 设置默认图纸打印方向
'objLayout.PlotRotation = ac0degrees '纵向
objLayout.PlotRotation = ac90degrees '横向
'ActiveLayout.PlotRotation = ac90degrees
' 设置图纸打印比例
objLayout.StandardScale = acScaleToFit
'ActiveLayout.StandardScale = acScaleToFit
objLayout.UseStandardScale = True '使用标准打印比例
'ActiveLayout.UseStandardScale = True
'objLayout.UseStandardScale = False '使用自定义打印比例
' 设置自定义打印比例
'objLayout.SetCustomScale txtNumerator.Value, txtDenominator.Value
' 设置图纸是否居中打印
objLayout.CenterPlot = True
'ActiveLayout.CenterPlot = True
' 打印时使用图形文件中的线宽
objLayout.PlotWithLineweights = True
'ActiveLayout.PlotWithLineweights = True
' 设置是否应用打印样式
objLayout.PlotWithPlotStyles = True
'ActiveLayout.PlotWithPlotStyles = True
' 打印时隐藏图纸空间对象
objLayout.PlotHidden = False
'ActiveLayout.PlotHidden = False
' 设置图纸打印份数
objPlot.NumberOfCopies = 1
' 将打印错误报告切换为静默错误模式,以便不间断地执行打印任务
objPlot.QuietErrorMode = True
' 设置前台打印,使打印任务按打印顺序依次发送到打印机
cadDoc.SetVariable "BACKGROUNDPLOT", 0
' 重新生成当前图形
cadDoc.Regen acAllViewports
' 根据图块的左下角及右上角坐标设置打印窗口
Dim a, b, c As Integer
a = 0
' b = 0
' c = 1
For a = 1 To i
blockarry(a).blockObj.GetBoundingBox ptMin, ptMax
Debug.Print blockarry(a).blockObj.Name
' ReDim Preserve ptMin(0 To 1) ' 将三维点转化为二维点坐标
' ReDim Preserve ptMax(0 To 1)
Debug.Print ptMin(0) & "--" & ptMin(1)
Debug.Print ptMax(0) & "--" & ptMax(1)
' 设置打印窗口
' objLayout.SetWindowToPlot ptMin, ptMax
' ActiveLayout.SetWindowToPlot ptMin, ptMax
' cadDoc.acModelSpace.SetWindowToPlot ptMin, ptMax
objLayout.SetWindowToPlot ptMin, ptMax
' ActiveLayout.SetWindowToPlot ptMin, ptMax
Dim pptMin As Variant, pptMax As Variant
objLayout.GetWindowToPlot pptMin, pptMax
Debug.Print pptMin(0) & "--" & pptMin(1)
Debug.Print pptMax(0) & "--" & pptMax(1)
objLayout.PlotType = acWindow
' ActiveLayout.PlotType = acWindow'起作用会导致选区为空
' objLayout.PlotType = acExtents
If Abs(ptMax(0) - ptMin(0)) < Abs(ptMax(1) - ptMin(1)) And AutoRotate Then '纵图不旋转
objLayout.PlotRotation = ac0degrees
' ActiveLayout.PlotRotation = ac90degrees
Else
objLayout.PlotRotation = ac90degrees '旋转命令无效
' ActiveLayout.PlotRotation = ac0degrees '旋转命令有效
End If
' objDoc.Plot.DisplayPlotPreview acFullPreview ' 完全预览并提示打印
' objDoc.Plot.SetLayoutsToPlot = objLayout
objPlot.PlotToDevice
' objPlot.PlotToDevice 'objLayout.ConfigName
Next a
If Err <> 0 Then
Err.Clear
End If
On Error GoTo 0
'Application.ScreenUpdating = True
End Function
|
|