CAD VBA 实现图纸的快速打印
'快速打印
Function KSDY(E As AcadEntity)
Dim ptMax
Dim ptMin
E.GetBoundingBox ptMin, ptMax '返回的是世界坐标
ReDim Preserve ptMin(0 To 1)
ReDim Preserve ptMax(0 To 1)
' 设置打印比例为“布满图纸”
ThisDrawing.ActiveLayout.StandardScale = acScaleToFit
ThisDrawing.ActiveLayout.SetWindowToPlot ptMin, ptMax
' 设置打印类型
ThisDrawing.ActiveLayout.PlotType = acWindow
If Me.OptionButton4.Value = True Then
'启用打印预览
ThisDrawing.ActiveLayout.GetWindowToPlot ptMin, ptMax
ThisDrawing.Plot.DisplayPlotPreview acFullPreview
Else
'打印当前的区域
'若选中“打印到文件”
If PlotTofile_CheckBox.Value Then
MsgBox "1"
MsgBox PlotFilesPath_ComboBox.Text & ThisDrawing.Name & "-" & n & ".plt"
If PlotFilesPath_ComboBox.Text = "" Then PlotFilesPath_ComboBox.Text = GetPath
ThisDrawing.Plot.PlotToFile PlotFilesPath_ComboBox.Text & ThisDrawing.Name & "-" & n & ".plt"
n = n + 1
Else
ThisDrawing.Plot.PlotToDevice ThisDrawing.ModelSpace.Layout.ConfigName
End If
End If
End Function
Function KSDY(E As AcadEntity)
Dim ptMax
Dim ptMin
E.GetBoundingBox ptMin, ptMax '返回的是世界坐标
ReDim Preserve ptMin(0 To 1)
ReDim Preserve ptMax(0 To 1)
' 设置打印比例为“布满图纸”
ThisDrawing.ActiveLayout.StandardScale = acScaleToFit
ThisDrawing.ActiveLayout.SetWindowToPlot ptMin, ptMax
' 设置打印类型
ThisDrawing.ActiveLayout.PlotType = acWindow
If Me.OptionButton4.Value = True Then
'启用打印预览
ThisDrawing.ActiveLayout.GetWindowToPlot ptMin, ptMax
ThisDrawing.Plot.DisplayPlotPreview acFullPreview
Else
'打印当前的区域
'若选中“打印到文件”
If PlotTofile_CheckBox.Value Then
MsgBox "1"
MsgBox PlotFilesPath_ComboBox.Text & ThisDrawing.Name & "-" & n & ".plt"
If PlotFilesPath_ComboBox.Text = "" Then PlotFilesPath_ComboBox.Text = GetPath
ThisDrawing.Plot.PlotToFile PlotFilesPath_ComboBox.Text & ThisDrawing.Name & "-" & n & ".plt"
n = n + 1
Else
ThisDrawing.Plot.PlotToDevice ThisDrawing.ModelSpace.Layout.ConfigName
End If
End If
End Function
[本日志由 田草 于 2008-08-03 12:19 AM 编辑]
|
157787698 于 2009-11-09 04:18 PM 发表评论:
上述打印区域片的问题有没有解决?
目前我也遇到这个问题,想尽了各种办法绝无法解决
如果有解决办法,请指点一下,谢谢
tiancao1001 于 2009-10-30 09:01 AM 发表评论:
没有这么智能,
xiaoshi112 于 2009-10-29 10:50 PM 发表评论:
可不可以让打印的时候把图纸自动的拼在一起打印,这样更加节省图纸?
xiaoshi112 于 2009-10-29 10:49 PM 发表评论:
可不可以让打印的时候把图纸自动的拼在一起打印,这样更加节省图纸?
tiancao1001 于 2008-12-02 01:39 PM 发表评论:
'快速打印
Function KSDY2(P1 As Variant, P2 As Variant)
Dim PtMin As Variant
Dim PtMax As Variant
PtMin = P1
PtMax = P2
ReDim Preserve PtMin(0 To 1)
ReDim Preserve PtMax(0 To 1)
' 设置打印比例为“布满图纸”
ThisDrawing.ActiveLayout.StandardScale = acScaleToFit
ThisDrawing.ActiveLayout.SetWindowToPlot PtMin, PtMax
' 设置打印类型为窗口
ThisDrawing.ActiveLayout.PlotType = acWindow
'设置为居中打印
ThisDrawing.ActiveLayout.CenterPlot = True
If Me.OptionButton4.Value = True Then
'启用打印预览
ThisDrawing.ActiveLayout.GetWindowToPlot PtMin, PtMax
ThisDrawing.Plot.DisplayPlotPreview acFullPreview
Else
'打印当前的区域
'若选中“打印到文件”
If PlotTofile_CheckBox.Value Then
If PlotFilesPath_ComboBox.text = "" Then PlotFilesPath_ComboBox.text = GetPath
ThisDrawing.Plot.PlotToFile PlotFilesPath_ComboBox.text & ThisDrawing.Name & "-" & N & ".plt"
N = N + 1
Else
ThisDrawing.Plot.PlotToDevice ThisDrawing.ModelSpace.Layout.ConfigName
End If
End If
End Function
Function KSDY2(P1 As Variant, P2 As Variant)
Dim PtMin As Variant
Dim PtMax As Variant
PtMin = P1
PtMax = P2
ReDim Preserve PtMin(0 To 1)
ReDim Preserve PtMax(0 To 1)
' 设置打印比例为“布满图纸”
ThisDrawing.ActiveLayout.StandardScale = acScaleToFit
ThisDrawing.ActiveLayout.SetWindowToPlot PtMin, PtMax
' 设置打印类型为窗口
ThisDrawing.ActiveLayout.PlotType = acWindow
'设置为居中打印
ThisDrawing.ActiveLayout.CenterPlot = True
If Me.OptionButton4.Value = True Then
'启用打印预览
ThisDrawing.ActiveLayout.GetWindowToPlot PtMin, PtMax
ThisDrawing.Plot.DisplayPlotPreview acFullPreview
Else
'打印当前的区域
'若选中“打印到文件”
If PlotTofile_CheckBox.Value Then
If PlotFilesPath_ComboBox.text = "" Then PlotFilesPath_ComboBox.text = GetPath
ThisDrawing.Plot.PlotToFile PlotFilesPath_ComboBox.text & ThisDrawing.Name & "-" & N & ".plt"
N = N + 1
Else
ThisDrawing.Plot.PlotToDevice ThisDrawing.ModelSpace.Layout.ConfigName
End If
End If
End Function
田草 于 2008-03-08 09:42 AM 发表评论:
我发现打印偏移和图纸的可打印区域有关系,但是我不知道怎么用vba获得图纸的可打印区域,
田草 于 2008-03-07 05:54 PM 发表评论:
'不知道为什么, 'ThisDrawing.ActiveLayout.CenterPlot = True 这句有的时候,出现PlotOrigin 不定,
'而且使用GetBoundingBox获取对象的角点有的时候也不太好用。还是使用getPoint比较实在。
Sub xPrint2()
Dim P1 As Variant
Dim P2 As Variant
Dim W As Double
Dim H As Double
Dim W1 As Double
Dim H1 As Double
Dim xOrigin(1) As Double
Dim xScale(1) As Double
Dim S As Double
Dim R
On Error Resume Next
P1 = ThisDrawing.Utility.GetPoint(, "打印窗口的角点:")
P2 = ThisDrawing.Utility.GetPoint(P1, "打印窗口的另一个角点:")
E:
On Error GoTo F:
ReDim Preserve P1(0 To 1)
ReDim Preserve P2(0 To 1)
ThisDrawing.ActiveLayout.GetPaperSize W, H
Prompt str(W) & " / " & str(H) & vbCrLf
W1 = Abs(P1(0) - P2(0)): H1 = Abs(P1(1) - P2(1))
Prompt str(W1) & " / " & str(H1) & vbCrLf
R = ThisDrawing.ActiveLayout.PlotRotation
If R = ac0degrees Or R = ac180degrees Then
xScale(0) = W1 / W
xScale(1) = H1 / H
If xScale(0) >= xScale(1) Then
S = xScale(0)
Else
S = xScale(1)
End If
Prompt str(S) & vbCrLf
ThisDrawing.ActiveLayout.SetCustomScale 1, S
xOrigin(0) = Abs(W1 / S - W) / 2
Prompt str(xOrigin(0)) & vbCrLf
xOrigin(1) = Abs(H1 / S - H) / 2
Prompt str(xOrigin(1)) & vbCrLf
ElseIf R = ac90degrees Or R = ac270degrees Then
xScale(0) = H1 / W
xScale(1) = W1 / H
If xScale(0) >= xScale(1) Then
S = xScale(0)
Else
S = xScale(1)
End If
Prompt str(S) & vbCrLf
ThisDrawing.ActiveLayout.SetCustomScale 1, S
xOrigin(0) = Abs(H1 / S - W) / 2
Prompt str(xOrigin(0)) & vbCrLf
xOrigin(1) = Abs(W1 / S - H) / 2
Prompt str(xOrigin(1)) & vbCrLf
End If
ThisDrawing.ActiveLayout.PlotOrigin = xOrigin
ThisDrawing.ActiveLayout.SetWindowToPlot P1, P2
ThisDrawing.ActiveLayout.GetWindowToPlot P1, P2
ThisDrawing.ActiveLayout.PlotType = acWindow
ThisDrawing.Plot.DisplayPlotPreview acFullPreview
'ThisDrawing.Plot.PlotToDevice ThisDrawing.ModelSpace.Layout.ConfigName
P1 = ThisDrawing.Utility.GetPoint(, "打印窗口的角点:")
P2 = ThisDrawing.Utility.GetPoint(P1, "打印窗口的另一个角点:")
GoTo E:
F:
End Sub
'而且使用GetBoundingBox获取对象的角点有的时候也不太好用。还是使用getPoint比较实在。
Sub xPrint2()
Dim P1 As Variant
Dim P2 As Variant
Dim W As Double
Dim H As Double
Dim W1 As Double
Dim H1 As Double
Dim xOrigin(1) As Double
Dim xScale(1) As Double
Dim S As Double
Dim R
On Error Resume Next
P1 = ThisDrawing.Utility.GetPoint(, "打印窗口的角点:")
P2 = ThisDrawing.Utility.GetPoint(P1, "打印窗口的另一个角点:")
E:
On Error GoTo F:
ReDim Preserve P1(0 To 1)
ReDim Preserve P2(0 To 1)
ThisDrawing.ActiveLayout.GetPaperSize W, H
Prompt str(W) & " / " & str(H) & vbCrLf
W1 = Abs(P1(0) - P2(0)): H1 = Abs(P1(1) - P2(1))
Prompt str(W1) & " / " & str(H1) & vbCrLf
R = ThisDrawing.ActiveLayout.PlotRotation
If R = ac0degrees Or R = ac180degrees Then
xScale(0) = W1 / W
xScale(1) = H1 / H
If xScale(0) >= xScale(1) Then
S = xScale(0)
Else
S = xScale(1)
End If
Prompt str(S) & vbCrLf
ThisDrawing.ActiveLayout.SetCustomScale 1, S
xOrigin(0) = Abs(W1 / S - W) / 2
Prompt str(xOrigin(0)) & vbCrLf
xOrigin(1) = Abs(H1 / S - H) / 2
Prompt str(xOrigin(1)) & vbCrLf
ElseIf R = ac90degrees Or R = ac270degrees Then
xScale(0) = H1 / W
xScale(1) = W1 / H
If xScale(0) >= xScale(1) Then
S = xScale(0)
Else
S = xScale(1)
End If
Prompt str(S) & vbCrLf
ThisDrawing.ActiveLayout.SetCustomScale 1, S
xOrigin(0) = Abs(H1 / S - W) / 2
Prompt str(xOrigin(0)) & vbCrLf
xOrigin(1) = Abs(W1 / S - H) / 2
Prompt str(xOrigin(1)) & vbCrLf
End If
ThisDrawing.ActiveLayout.PlotOrigin = xOrigin
ThisDrawing.ActiveLayout.SetWindowToPlot P1, P2
ThisDrawing.ActiveLayout.GetWindowToPlot P1, P2
ThisDrawing.ActiveLayout.PlotType = acWindow
ThisDrawing.Plot.DisplayPlotPreview acFullPreview
'ThisDrawing.Plot.PlotToDevice ThisDrawing.ModelSpace.Layout.ConfigName
P1 = ThisDrawing.Utility.GetPoint(, "打印窗口的角点:")
P2 = ThisDrawing.Utility.GetPoint(P1, "打印窗口的另一个角点:")
GoTo E:
F:
End Sub
田草 于 2008-02-21 02:59 PM 发表评论:
你自己用vba记录下来,再用vba导入啊。
liuningbo00 于 2008-02-21 02:47 PM 发表评论:
请问VBA 应用上一次打印设置 代码如何写?麻烦指教,多谢。。。
田草 于 2007-10-29 01:52 PM 发表评论:
打印原点和 打印区域窗口坐标 到底是个什么关系呢?
regen也没有用,
居中打印,vba的命令好像有的时候不执行。
田草 于 2007-10-27 11:18 PM 发表评论:
田草 于 2007-08-26 03:47 PM 发表评论:
设置ThisDrawing.ModelSpace.Layout.PlotOrigin 这个是不行的。
0527 于 2007-08-26 03:46 PM 发表评论:
田草 于 2007-08-25 09:10 PM 发表评论:
'重新指定原点,防止漂移
ThisDrawing.ModelSpace.Layout.PlotOrigin = originalValue
…………
'必须保存原始原点,否则打印会随机飘动?
Dim originalValue As Variant
originalValue = ThisDrawing.ModelSpace.Layout.PlotOrigin
ThisDrawing.ModelSpace.Layout.PlotOrigin = originalValue
…………
'必须保存原始原点,否则打印会随机飘动?
Dim originalValue As Variant
originalValue = ThisDrawing.ModelSpace.Layout.PlotOrigin
他所说的随机漂移肯定是错的,但是他的方法不知道可行否,回去验证一下,再告诉大家。
田草 于 2007-08-25 08:43 PM 发表评论:
我们可以使用ThisDrawing.Utility.TranslateCoordinates(PtMax, acWorld, acDisplayDCS, False)将世界坐标转换成显示坐标,这样就不会出现打印的时候图像出现偏移。
发表评论 - 不要忘了输入验证码哦! |