明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1466|回复: 0

vba 打印机问题

[复制链接]
发表于 2009-12-9 11:48:00 | 显示全部楼层 |阅读模式

偶用vba编了个识别图框块批量打图的程序,遇到两个问题,1,能预览图,但打印不出来;2,预览出来的是空白;请论坛里的各位高手指点指点,不胜感激,源码如下

用户窗体主要有两个combobox,两个optionbuttun,两个commandbuttun

Private Sub Command1_Click()
 On Error Resume Next
Dim plotname As Variant
Dim plotstyle As Variant
Dim point1 As Variant, point2 As Variant
Dim ent As AcadEntity
Dim i As Integer
Dim j  As Integer
Dim scs As String
j = 0
If Com1.ListIndex < 0 Or Com2.ListIndex < 0 Then
    MsgBox "请选择打印机和样式", vbOKOnly, "注意!"
Else
    Me.Hide
    plotname = Com1.Text
    plotstyle = Com2.Text
   
 
   
   
    For Each ent In ThisDrawing.Application.ActiveDocument.ModelSpace
        If TypeOf ent Is AcadBlockReference Then
            ent.GetBoundingBox point1, point2
            ReDim Preserve point1(0 To 1)
            ReDim Preserve point2(0 To 1)
            Dim a As Double, b As Double
            a = Abs(Abs(point1(0)) - Abs(point2(0)))
            b = Abs(Abs(point1(1)) - Abs(point2(1)))
            If a > 0 Then
             scs = tk(a, b)
             If scs <> "0" Then
                 If scs <> "A4" Then
                
                    If Opt1.Value = True Then
                    scs = "A3"
                    End If
                 End If
                
                 With ThisDrawing.ActiveLayout
                
                 .SetWindowToPlot point1, point2
                
                 .ConfigName = plotname
                 .StyleSheet = plotstyle
                 .StandardScale = acScaleToFit
                 .PaperUnits = acMillimeters
                 .CanonicalMediaName = scs
                
                 .GetWindowToPlot point1, point2
                
                 If scs = "A4" Then
                 .PlotRotation = ac0degrees
                 Else
                 .PlotRotation = ac90degrees
                 End If
                 End With
                
                 If i <> 6 Then
                     ThisDrawing.Plot.DisplayPlotPreview acFullPreview
                     i = MsgBox("是否取消预览?" & "“是”取消预览全部打印,“否”继续预览,“取消”退出程序", vbYesNoCancel, "注意")
                     If i = 2 Then
                     j = j + 1
                     Exit For
                     End If
                 End If
                 j = j + 1
                  ThisDrawing.ActiveLayout.PlotType = acWindow
                  ThisDrawing.Application.ActiveDocument.SetVariable "BACKGROUNDPLOT", 0
                  Debug.Print scs & ":" & a & "X" & b
             End If
            End If
        End If
    Next ent
    MsgBox "本次打印" & j & " 张图纸 ", vbOKOnly, "恭喜"
    Me.Show
  
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim plotDevices As Variant
Dim plotsheets As Variant
    plotDevices = ThisDrawing.ActiveLayout.GetPlotDeviceNames()
    plotsheets = ThisDrawing.ActiveLayout.GetPlotStyleTableNames()
    Dim x As Integer
    Com1.Clear
    Com2.Clear
    For x = LBound(plotDevices) To UBound(plotDevices)
        Com1.AddItem plotDevices(x)
    Next
    For x = LBound(plotsheets) To UBound(plotsheets)
        Com2.AddItem plotsheets(x)
    Next
    Opt1.Value = True
End Sub
Function tk(xa As Double, ya As Double)
On Error Resume Next
tk = "0"
If xa < ya Then
    If xa Mod 210 = 0 And ya Mod 297 = 0 Then
    tk = "A4"
    End If
Else
    If xa Mod 1189 = 0 And ya Mod 841 = 0 Or xa * 2 Mod 1189 = 0 And ya * 2 Mod 841 = 0 Then
        tk = "A0"
    ElseIf xa Mod 841 = 0 And ya Mod 594 = 0 Or xa * 2 Mod 841 = 0 And ya * 2 Mod 594 = 0 Then
            tk = "A1"
        ElseIf xa Mod 594 = 0 And ya Mod 420 = 0 Or xa * 2 Mod 594 = 0 And ya * 2 Mod 420 = 0 Then
                tk = "A2"
            ElseIf xa Mod 420 = 0 And ya Mod 297 = 0 Or xa * 2 Mod 420 = 0 And ya * 2 Mod 297 = 0 Then
                    tk = "A3"
    End If
End If
End Function

补充 原程序如下

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 00:29 , Processed in 0.174589 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表