CADVBA批量打印
更新时间:2023-11-14 23:38:01 阅读量: 教育文库 文档下载
- cadVBA批量更改图纸推荐度:
- 相关推荐
CAD/VBA批量打印
打印图纸,不折不扣的体力活。最多一次打了600多张图,打印机都因\体力不支\中途休息了几次,如果不是用程序批打,估计我也得累个半死。
下面贴出打印过程的代码,加个for循环就可以批打了。简单说明一下打印函数 PrinterName - 打印机名称 Styles - 样式表名称 MediaName - 纸张大小 Copies - 打印份数
AutoMedia - 自动纸张开关
AutoRotate - 自动旋转,纵向/横向 AutoClose - 打印完毕关闭文档 AutoFrame - 自动判断图框,主要针对图框为块的情形 打印过程并没有提供全部的AUTO CAD打印选项,因为我一般用不到,比如\打印偏移\、\打印到文件\我从来不用的,如果需要可以添加进去。
程序会根据指定块名查找图框,也可以根据块的纵横比例自动判断是否为图框,然后按块打印,一张图纸中允许有多个图框;
对于编组(Group)形式的图框,指定编组名即可
如果没有找到任何图框块或编组时,按图纸范围打印
另外,打印时会先预览,然后由用户选择是否打印,避免打错。 [代码如下] Sub QuickPlot()
Call PlotFunction(\Sub Plot2PDF()
Call PlotFunction(\4()
Call PlotFunction(\'快速打印/批量打印
Public Sub PlotFunction(PrinterName As String, Styles As String, MediaName As String, Copies As Integer, _
AutoMedia As Boolean, AutoRotate As Boolean, AutoClose As Boolean, AutoFrame As Boolean)
On Error Resume Next
Dim ptMin As Variant, ptMax As Variant Dim Ent As AcadEntity Dim PlotCount As Integer
Set objDoc = ThisDrawing.Application.ActiveDocument Set objLayout = objDoc.Layouts.Item(\
Set objPlot = objDoc.Plot
ThisDrawing.Application.ZoomExtents
' 设置打印机
If Not Trim(PrinterName) = \
objLayout.ConfigName = PrinterName Else Exit Sub End If ' 设置打印样式表
If Not Trim(Styles) = \ objLayout.StyleSheet = \ ' 设置图纸尺寸 If AutoMedia Then
objLayout.CanonicalMediaName = \ If Not Trim(MediaName) = \
objLayout.CanonicalMediaName = MediaName Else
objLayout.CanonicalMediaName = \ ' 设置图纸单位
objLayout.PaperUnits = acMillimeters 'objLayout.PaperUnits = acInches ' 设置默认图纸打印方向
'objLayout.PlotRotation = ac0degrees '向 'objLayout.PlotRotation = ac180degrees objLayout.PlotRotation = ac90degrees '向 'objLayout.PlotRotation = ac270degrees ' 设置图纸打印比例
objLayout.StandardScale = acScaleToFit objLayout.UseStandardScale = True '使用标准例 'objLayout.UseStandardScale = False '使用自定义打印比例 ' 设置自定义打印比例
'objLayout.SetCustomScale txtNumerator.Value, txtDenominator.Value ' 设置图纸是否居中打印
objLayout.CenterPlot = True ' 打印时使用图形文件中的线宽
objLayout.PlotWithLineweights = True ' 设置是否应用打印样式
objLayout.PlotWithPlotStyles = True
' 打印时隐藏图纸空间对象 objLayout.PlotHidden = False ' 设置图纸打印份数 If Copies >= 1 Then objPlot.NumberOfCopies = CInt(Copies) Else objPlot.NumberOfCopies = 1 End If
' 将打印错误报告切换为静默错误模式,以便不间断地执行打印任务 objPlot.QuietErrorMode = True ' 重新生成当前图形
objDoc.Regen acAllViewports
' 设置前台打印,使打印任务按打印顺序依次发送到打印机 objDoc.SetVariable \ PlotCount = 0 '打印计数 For Each Ent In objDoc.ModelSpace
If TypeOf Ent Is AcadBlockReference Then
If IsFrame(Ent, AutoFrame) = True And objDoc.Blocks(Ent.Name).count > 0 Then Ent.GetBoundingBox ptMin, ptMax
Debug.Print Ent.Name & \ ' 将三维点转化为二维点坐标 ReDim Preserve ptMin(0 To 1) ReDim Preserve ptMax(0 To 1) ' 设置打印窗口
ThisDrawing.ActiveLayout.SetWindowToPlot ptMin, ptMax
纵横
打印比
objLayout.PlotType = acWindow
If Abs(ptMax(0) - ptMin(0)) < Abs(ptMax(1) - ptMin(1)) Then If AutoMedia Then objLayout.CanonicalMediaName = \ac0degrees End If
' 完全预览并提示打印
objPlot.DisplayPlotPreview acFullPreview
UserSel = MsgBox(\是否打印预览? \打印到:\
\大小:\方式:acWindow(\
Chr(13) & Chr(13) & \选择[取消]退出程序!\打印选项\
objPlot.PlotToDevice objLayout.ConfigName PlotCount = PlotCount + 1 ElseIf UserSel = vbCancel Then Exit For End If End If End If Next Ent
' 图框为编组(Group)对时 Dim FrmGrp As AcadGroup Dim TptMin, TptMax As Variant ' 按编组名称查找图框编组对象
For Each FrmGrp In ThisDrawing.Groups
If IsFrame(FrmGrp, False) And FrmGrp.count > 0 Then
Debug.Print FrmGrp.Name & \
象
' 得到图框边界点坐标
FrmGrp.Item(0).GetBoundingBox ptMin, ptMax For i = 1 To FrmGrp.count - 1
FrmGrp.Item(i).GetBoundingBox TptMin, TptMax ReDim Preserve TptMin(0 To 1) ReDim Preserve TptMax(0 To 1) For j = 0 To 1
If TptMin(j) < ptMin(j) Then ptMin(j) = TptMin(j) End If If TptMax(j) > ptMax(j) Then ptMax(j) = TptMax(j)
End If Next j i = i + 1 Next ' 将三维点转化为二维点坐标 ReDim Preserve ptMin(0 To 1) ReDim Preserve ptMax(0 To 1) ' 设置打印窗口
ThisDrawing.ActiveLayout.SetWindowToPlot ptMin, ptMax objLayout.PlotType = acWindow
If Abs(ptMax(0) - ptMin(0)) < Abs(ptMax(1) - ptMin(1)) Then If AutoMedia Then objLayout.CanonicalMediaName = \ End If
' 完全预览并提示打印
objPlot.DisplayPlotPreview acFullPreview
UserSel = MsgBox(\是否打印预览? \打印到:\ \大小:\方式:
acWindow(\
Chr(13) & Chr(13) & \选择[取消]退出程序!\打印选项\
objPlot.PlotToDevice objLayout.ConfigName ElseIf UserSel = vbCancel Then Exit For End If End If Next FrmGrp
' 没有找到图框时按范围打印
If PlotCount = 0 And objDoc.ModelSpace.count > 0 Then ptMax = ThisDrawing.GetVariable(\
' 图形范围内无实体则退出
If ptMax(0) = ptMin(0) Or ptMax(1) = ptMin(1) Then Exit Sub End If ' 设置范围打印
objLayout.PlotType = acExtents ' 对纵向的图纸设置
If Abs(ptMax(0) - ptMin(0)) < Abs(ptMax(1) - ptMin(1)) Then If AutoMedia Then objLayout.CanonicalMediaName = \ End If
' 完全预览并提示打印
objPlot.DisplayPlotPreview acFullPreview
UserSel = MsgBox(\是否打印预览? \打印到:\ \大小:\方式:acExtents(\
Chr(13) & Chr(13) & \选择[取消]退出程序!\打印选项\
objPlot.PlotToDevice objLayout.ConfigName ElseIf UserSel = vbCancel Then Exit Sub End If End If
' 关闭文档 False 为不保存修改
If AutoClose Then objDoc.Close False, ThisDrawing.Name End Sub
Public Function IsFrame(entobj As Object, AutoMode As Boolean) As Boolean '判断是否为图框
On Error Resume Next IsFrame = False Dim i As Integer Dim FrmNameList As Variant
FrmNameList = \图框块、编组名列表 FrmNameList = Split(FrmNameList, \rmNameList(i) Then IsFrame = True Exit For End If Next
'块名不符时由大小比例判断是否为图框(可能会误判,不过几率不高)
If IsFrame = False And AutoMode And entobj.ObjectName = \bj.GetBoundingBox ptMin, ptMax
Debug.Print ptMin(0) & \
If Abs((ptMax(1) - ptMin(1)) / (ptMax(0) - ptMin(0)) - 1.414) < 0.01 Or Abs((ptMax(1) - ptMin(1)) / (ptMax(0) - ptMin(0)) - 0.707) < 0.01 Then IsFrame = True End If End If End Function
Function SNA11x17()
Dim objPS As AcadPlotConfiguration
Set objPS = ThisDrawing.PlotConfigurations.Add(“SNA-AZTU-11x17”, False)
objPS.ConfigName = “\\\\SERVER2\\SAVIN 4035 PCL 6” objPS.CanonicalMediaName = “Tabloid” objPS.CenterPlot = True
objPS.PaperUnits = acInches objPS.PlotHidden = False
objPS.PlotRotation = ac90degrees objPS.PlotType = acExtents
objPS.PlotViewportBorders = False objPS.PlotViewportsFirst = True objPS.PlotWithLineweights = True objPS.PlotWithPlotStyles = True objPS.ScaleLineweights = False objPS.ShowPlotStyles = False
objPS.StandardScale = acScaleToFit objPS.StyleSheet = “SNA-11X17.ctb” objPS.UseStandardScale = True 二
Public Sub SetupAndPlot(ByRef Plotter As String, CTB As String, SIZE As String, PSCALE As String
, ROT As String) Dim Layout As AcadLayout On Error GoTo Err_Control Set Layout = ThisDrawing.ActiveLayout Layout.RefreshPlotDeviceInfo
Layout.ConfigName = Plotter ' CALL PLOTTER Layout.PLOTTYPE = acExtents
Layout.PlotRotation = ROT ' CALL ROTATION Layout.StyleSheet = CTB ' CALL CTB FILE Layout.PlotWithPlotStyles = True
Layout.CanonicalMediaName = SIZE ' CALL SIZE Layout.PaperUnits = acInches Layout.StandardScale = PSCALE 'CALL PSCALE Layout.ShowPlotStyles = False ThisDrawing.Plot.NumberOfCopies = 1 Layout.CenterPlot = True Layout.ScaleLineweights = False
Layout.RefreshPlotDeviceInfo
ThisDrawing.Regen acAllViewports ZoomExtents
Set Layout = Nothing ThisDrawing.Save Exit_Here: Exit Sub Err_Control:
Select Case Err.Number Case \
MsgBox \
MsgBox \TPSTYLES command\ Case Else
MsgBox \三
Sub PcsMM()
Dim pC As AcadPlotConfiguration Dim PCs As AcadPlotConfigurations Dim oLayout As AcadLayout Dim oLayouts As AcadLayouts Dim PlotOrig(1) As Double Dim Orig Set oLayouts = ThisDrawing.Layouts
Set PCs = ThisDrawing.PlotConfigurations Set oLayout = ThisDrawing.PaperSpace.Layout PlotOrig(0) = 18.542: PlotOrig(1) = 12.192
Set pC = PCs.Add(\ .PlotType = acExtents
.CanonicalMediaName = \ .ConfigName = \\\\DESIGNSERVER\\HPDJ
.PlotOrigin = PlotOrig
.PlotRotation = ac180degrees .StandardScale = ac1_1 End With PcTyp pC oLayout.CopyFrom pC
PlotOrig(0) = 19.01: PlotOrig(1) = 12.68 Set pC = PCs.Add(\ .PlotType = acLayout
.CanonicalMediaName = \
.ConfigName = \gin = PlotOrig
.PlotRotation = ac180degrees .StandardScale = ac1_1 End With PcTyp pC oLayout.CopyFrom pC
PlotOrig(0) = 1.31: PlotOrig(1) = 4.48 Set pC = PCs.Add(\
.PlotType = acExtents .CenterPlot = True
.ConfigName = \ PlotOrig
.PlotRotation = ac270degrees .StandardScale = ac1_2
'.CanonicalMediaName = \PcTyp pC 'ModelSpace
Set oLayout = ThisDrawing.ModelSpace.Layout
Set pC = PCs.Add(\
.ConfigName = \ .CanonicalMediaName = \ .PlotRotation = ac180degrees End With PCAdds pC
Set pC = PCs.Add(\
.ConfigName = \ .CanonicalMediaName = \ .PlotRotation = ac180degrees End With PcTyp pC
Set pC = PCs.Add(\
Orig = ThisDrawing.GetVariable(\h pC
.ConfigName = \mScale 1, 1
.CanonicalMediaName = \ .PlotOrigin = PlotOrig
.PlotRotation = ac270degrees End With PcTyp pC oLayout.CopyFrom pC
'Pc.RefreshPlotDeviceInfo ThisDrawing.Regen 0 End Sub
Function PcTyp(pC As AcadPlotConfiguration)
With pC
.PaperUnits = acMillimeters .PlotHidden = False
.PlotViewportBorders = False .PlotViewportsFirst = True .PlotWithLineweights = True .PlotWithPlotStyles = True
.StyleSheet = \End Function
正在阅读:
CADVBA批量打印11-14
入党申请书自我介绍11-17
与银行联合营销思路与想法04-16
语文讲座作文学案(高三)02-01
2020山西省太原市中考物理二模试卷08-26
常见型材规格及特性07-26
2016学生工作计划12-08
工业产品设计inventor国赛评分标准及大赛试题08-16
佛山党政机构改革(大部制)详解04-29
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 批量
- 打印
- CADVBA
- 中国陈列展示柜行业市场前景分析预测年度报告(目录) - 图文
- 道家秘传之《清微炁法》《调息法》
- 市农业和农村工作情况汇报
- 上海市2016奉贤区初三英语一模试卷(含答案) - 图文
- 标准时间管理程序
- 英语 词汇与结构100道题
- 2013-2014意外伤害急救常识试卷
- WORD试题1
- 会计基础第八套题及答案
- 《全国导游基础知识》教学大纲
- 会计继续教育--新企业内部控制规范及相关制度应用指南
- 计量经济学多元线性回归、多重共线性、异方差实验报告
- 2016年监狱警察个人工作总结
- 风险社会若干刑法理论问题反思
- 国际金融学分章习题作业(中文)
- 2014房屋登记官试题库
- 重庆市轨道交通控制保护区建设第三方监测管理暂行办法(定稿)
- 2019届广东省清远市高三上学期第九次周考语文试卷含答案及解析
- 景观建筑学 口袋公园 - 图文
- 成都市2017年高中阶段教育学校统一招生考试试卷