打印图纸,不折不扣的体力活。最多一次打了600多张图,打印机都因"体力不支"中途休息了几次,如果不是用程序批打,估计我也得累个半死。 下面贴出打印过程的代码,加个for循环就可以批打了。简单说明一下打印函数 PrinterName - 打印机名称 Styles - 样式表名称 MediaName - 纸张大小 Copies - 打印份数 AutoMedia - 自动纸张开关 AutoRotate - 自动旋转,纵向/横向 AutoClo - 打印完毕关闭文档 AutoFrame - 自动判断图框,主要针对图框为块的情形 打印过程并没有提供全部的AUTO CAD打印选项,因为我一般用不到,比如"打印偏移"、"打印到文件"我从来不用的,如果需要可以添加进去。 程序会根据指定块名查找图框,也可以根据块的纵横比例自动判断是否为图框,然后按块打印,一张图纸中允许有多个图框; 对于编组(Group)形式的图框,指定编组名即可 如果没有找到任何图框块或编组时,按图纸范围打印 另外,打印时会先预览,然后由用户选择是否打印,避免打错。 [代码如下] - By:忽又一天 /suddenday/ Sub QuickPlot() Call PlotFunction("SHARP AR-M256", "", "A3"conquest, 1, True, True, Fal, True) End Sub onpurpoSub Plot2PDF() Call PlotFunction("pdfFactory Pro", "b", "", 1, True, True, Fal, True) End Sub Sub PlotA4() Call PlotFunction("SHARP AR-M256", "b"汉堡包的英语怎么写, "A4", 1, Fal, True, Fal, True) End Sub '快速打印/批量打印 Public Sub PlotFunction(PrinterName As String, Styles As String, MediaName As String, Copies As extremepapersInteger, _ AutoMedia As Boolean, AutoRotate As Boolean, AutoClo As Boolean, AutoFrame As Boolean) On Error Resume Next unequivocal 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("Model") Set objPlot = objDoc.Plot ThisDrawing.Application.ZoomExtents ' 设置打印机 If Not Trim(PrinterName) = "" Then objLayout.ConfigName = PrinterName El Exit Sub End If ' 设置打印样式表 If Not Trim(Styles) = "" Then objLayout.StyleSheet = Styles El objLayout.StyleSheet = "b" End If ' 设置图纸尺寸 If AutoMedia Then objLayout.CanonicalMediaName = "A3" El If Not Trim(MediaName) = "" Then objLayout.CanonicalMediaName = MediaName El objLayout.CanonicalMediaName = "A3" End If End If ' 设置图纸单位 objLayout.PaperUnits = acMillimeters 'objLayout.PaperUnits = acInches ' 设置默认图纸打印方向 'objLayout.PlotRotation = ac0degrees '纵向 'objLayout.PlotRotation = ac180degrees objLayout.PlotRotation = ac90degrees '横向 'objLayout.PlotRotation = ac270degrees ' 设置图纸打印比例 objLayout.StandardScale = acScaleToFit objLayout.UStandardScale = True '使用标准打印比例 'objLayout.UStandardScale = Fal '使用自定义打印比例 ' 设置自定义打印比例 'objLayout.SetCustomScale txtNumerator.Value, txtDenominator.Value ' 设置图纸是否居中打印 objLayout.CenterPlot = True ' 打印时使用图形文件中的线宽 objLayout.PlotWithLineweights = True ' 设置是否应用打印样式 objLayout.PlotWithPlotStyles = True ' 打印时隐藏图纸空间对象 objLayout.PlotHidden = Fal ' 设置图纸打印份数 If Copies >= 1 Then objPlot.NumberOfCopies = CInt(Copies) El objPlot.NumberOfCopies = 1 End If ' 将打印错误报告切换为静默错误模式,以便不间断地执行打印任务 objPlot.QuietErrorMode = True ' 重新生成当前图形 objDoc.Regen acAllViewports ' 设置前台打印,使打印任务按打印顺序依次发送到打印机 objDoc.SetVariable "BACKGROUNDPLOT", 0 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 & "--" & objDoc.Blocks(Ent.Name).count ' 将三维点转化为二维点坐标 ReDim Prerve ptMin(0 To 1) ReDim Prerve 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 = "A4" If AutoRotate Then objLayout.PlotRotation = ac0degrees End If ' 完全预览并提示打印 objPlot.DisplayPlotPreview acFullPreview UrSel = MsgBox("是否打印预览? " & Chr(13) & Chr(13) & "打印到:" & objLayout.ConfigName & _ " 大小:" & objLayout.CanonicalMediaName & " 方式:acWindow(" & objLayout.PlotType & ") " & _ Chr(13) & Chr(13) & "选择[取消]退出程序!", vbYesNoCancel, "打印选项") If UrSel = vbYes Then objPlot.PlotToDevice objLayout.ConfigName PlotCount = PlotCount + 1 ElIf UrSel = 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, Fal) unt > 0 Then Debug.Print FrmGrp.Name & " [Items]:" & unt & "----group" ' 得到图框边界点坐标 FrmGrp.Item(0).GetBoundingBox ptMin, ptMax For i = 1 To unt - 1 FrmGrp.Item(i).GetBoundingBox TptMin, TptMax ReDim 学而思英语网Prerve TptMin(0 To 1) ReDim Prerve 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 Prerve ptMin(0 To 1) ReDim Prerve 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 = "A4" 川普女儿演讲 If AutoRotate Then objLayout.PlotRotation = ac0degrees End If ' 完全预览并提示打印 objPlot.DisplayPlotPreview acFullPreview UrSel = MsgBox("是否打印预览? " & Chr(13) & Chr(13) & "打印到:" & objLayout.ConfigName & _ " 大小:" & objLayout.CanonicalMediaName & " 方式:acWindow(" & objLayout.PlotType & ") " & _ Chr(13) & Chr(13) & "选择[取消]退出程序!", vbYesNoCancel, "打印选项") If UrSel = vbYes Then PlotCount = PlotCount + 1 objPlot.PlotToDevice objLayout.ConfigName ElIf UrSel = vbCancel Then Exit For End If End If Next FrmGrp ' 没有找到图框时按范围打印 If PlotCount = 0 And unt > 0 Then ptMax = ThisDrawing.GetVariable("EXTMAX") ptMin = ThisDrawing.GetVariable("EXTMIN") ' 图形范围内无实体则退出 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 = "A4" If AutoRotate Then objLayout.PlotRotation = ac0degrees End If ' 完全预览并提示打印 objPlot.DisplayPlotPreview acFullPreview UrSel = MsgBox("是否打印预览? " & Chr(13) & Chr(13) & "打印到:" & objLayout.ConfigName & _ " 大小:" & objLayout.CanonicalMediaName & " 方式:acExtents(" & objLayout.PlotType & ") " & _ Chr(13) & Chr(13) & "选择[取消]退出程序!", vbYesNoCancel, "打印选项") If UrSel = vbYes Then objPlot.PlotToDevice objLayout.ConfigName ElIf UrSel = vbCancel Then Exit Sub End If End If ' 关闭文档 Fal 为不保存修改 If AutoClo Then objDoc.Clo Fal, ThisDrawing.Name End Sub Public Function IsFrame(entobj As Object, AutoMode As Boolean) As Boolean '判断是否为图框 On Error Resume Next IsFrame = Fal Dim i As Integer Dim FrmNameList As Variant FrmNameList = "blkFrame,A1,A2,A3,A4,PC_PAPER_DIC" '图框块、编组名列表 FrmNameList = Split(FrmNameList, ",") For i = 0 To UBound(FrmNameList) If entobj.Name = FrmNameList(i) Then IsFrame = True Exit For End If Next '块名不符时由大小比例判断是否为图框(可能会误判,不过几率不高) If IsFrame = Fal And AutoMode And entobj.ObjectName = "AcDbBlockReference" Then entobj.GetBoundingBox ptMin, ptMax Debug.Print ptMin(0) & "--" & ptMax(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 = luckypatient2True End If End If End Function |
本文发布于:2023-05-25 15:04:03,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/fan/90/122246.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |