- UID
- 2299
- 积分
- 465
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-31
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
AutoCAD2000中引入的Layout是一个非常好用的报表工具
请参照下面的例程
- '纯文本报表(生成一个无PViewport的Layout)
- Private Sub NewTextLayout(LayoutName, PaperSize As String, Rotate As Boolean)
- Dim TempLayout As AcadLayout
-
- Set TempLayout = ThisDrawing.Layouts.Add(LayoutName)
- TempLayout.CanonicalMediaName = PaperSize
- If Rotate Then
- TempLayout.PlotRotation = ac90degrees
- Else
- TempLayout.PlotRotation = ac0degrees
- End If
- ThisDrawing.ActiveLayout = TempLayout
- ThisDrawing.ActiveSpace = acPaperSpace
- ThisDrawing.MSpace = False
- '删除系统缺省添加的PViewPort
- ThisDrawing.PaperSpace.Item(1).Delete
- End Sub
- '写文字
- Private Sub DrawText(textString, strFont As String, X, Y, height As Double)
- Dim textObj As AcadText
- Dim pt(0 To 2) As Double
-
- pt(0) = X
- pt(1) = Y
- pt(2) = 0
- ThisDrawing.ActiveTextStyle = ThisDrawing.TextStyles.Item(strFont)
- Set textObj = ThisDrawing.PaperSpace.AddText(textString, pt, height)
- End Sub
- '写Align文字
- Private Sub DrawAlignText(textString, strFont As String, insX, insY, alnX, alnY, height As
- Double, strAln As String)
- Dim textObj As AcadText
- Dim insPt(0 To 2) As Double
- Dim alnPt(0 To 2) As Double
- Dim Align As AcAlignment
- Select Case strAln
- Case "A"
- Align = acAlignmentAligned
- Case "F"
- Align = acAlignmentFit
- Case "M"
- Align = acAlignmentMiddle
- Case "C"
- Align = acAlignmentCenter
- Case "R"
- Align = acAlignmentRight
- Case "TL"
- Align = acAlignmentTopLeft
- Case "TC"
- Align = acAlignmentTopCenter
- Case "TR"
- Align = acAlignmentTopRight
- Case "ML"
- Align = acAlignmentMiddleLeft
- Case "MC"
- Align = acAlignmentMiddleCenter
- Case "MR"
- Align = acAlignmentMiddleRight
- Case "BL"
- Align = acAlignmentBottomLeft
- Case "BC"
- Align = acAlignmentBottomCenter
- Case "BR"
- Align = acAlignmentBottomRight
- Case Else
- Align = acAlignmentLeft
- End Select
- insPt(0) = insX
- insPtpt(1) = insY
- insPtpt(2) = 0
- alnPt(0) = alnX
- alnPt(1) = alnY
- alnPt(2) = 0
- ThisDrawing.ActiveTextStyle = ThisDrawing.TextStyles.Item(strFont)
- Set textObj = ThisDrawing.PaperSpace.AddText(textString, insPt, height)
- textObj.Alignment = Align
- textObj.TextAlignmentPoint = alnPt
- End Sub
- '划线
- Private Sub DrawLine(xFrom, yFrom, xTo, yTo As Double)
- Dim lineObj As AcadLine
- Dim ptFrom(0 To 2) As Double
- Dim ptTo(0 To 2) As Double
-
- ptFrom(0) = xFrom
- ptFrom(1) = yFrom
- ptFrom(2) = 0
-
- ptTo(0) = xTo
- ptTo(1) = yTo
- ptTo(2) = 0
-
- Set lineObj = ThisDrawing.PaperSpace.AddLine(ptFrom, ptTo)
- End Sub
- '打印Layout
- Private Sub PlotLayout(LayoutName As String, bPlotToFile As Boolean)
- Dim strLayouts(1) As String
- Dim varLayouts As Variant
- Dim bSuccess As Boolean
-
- strLayouts(1) = LayoutName
- varLayouts = strLayouts
-
- ThisDrawing.Plot.SetLayoutsToPlot varLayouts
- If bPlotToFile Then
- MsgBox LayoutName + "打印到文件", vbExclamation, "打印提示"
- Else
- ThisDrawing.Plot.NumberOfCopies = 1
- bSuccess =
- ThisDrawing.Plot.PlotToDevice(ThisDrawing.Application.Preferences.Output.DefaultOutputDevic
- e)
- End If
- End Sub
- '删除布局
- Private Sub DeleteLayout(LayoutName As String)
- ThisDrawing.Layouts.Item(LayoutName).Delete
- End Sub
- '图&文Layout
- Private Sub NewGraphLayout(LayoutName As String)
- Dim TempLayout As AcadLayout
- Dim PVPort As AcadPViewport
- Dim pt(0 To 2) As Double
-
- Set TempLayout = ThisDrawing.Layouts.Add(LayoutName)
- TempLayout.CanonicalMediaName = "A4"
- TempLayout.PlotRotation = ac90degrees
-
- ThisDrawing.ActiveLayout = TempLayout
- ThisDrawing.ActiveSpace = acPaperSpace
- ThisDrawing.MSpace = False
- Set PVPort = ThisDrawing.PaperSpace.Item(1)
- pt(0) = 112
- pt(1) = 95
- pt(2) = 0
- PVPort.Center = pt
- PVPort.Width = 196
- PVPort.height = 160
- PVPort.Update
- End sub
- '画吧,写吧,打印它吧
- Private Sub PrintFWFCHZB()
- Dim i As Integer
-
- Dim titleFont As String
- Dim textFont As String
- Dim dataFont As String
- dim strFWJZMJFCHZB as string
-
- strFWJZMJFCHZB = 'My Report'
-
- NewTextLayout strFWJZMJFCHZB, "A4", False
-
- titleFont = "黑体"
- textFont = "宋体"
- dataFont = "仿宋"
-
- For i = 0 To 25
- DrawLine 16, 50 + i * 8, 180, 50 + i * 8
- Next i
- DrawLine 16, 50, 16, 250
- DrawLine 40, 50, 40, 250
- DrawLine 80, 50, 80, 250
- DrawLine 180, 50, 180, 250
- DrawText "X X X X X X X X 汇 总 表", titleFont, 50, 260, 4
- DrawText "建筑物名称:", textFont, 18, 252, 3
- If strLMC <> "" Then
- DrawText strLMC, dataFont, 44, 252, 3
- End If
- DrawText "层 次", textFont, 22, 244.7, 2.6
- DrawText "建筑面积", textFont, 52, 244.7, 2.6
- DrawText "备 注", textFont, 124, 244.7, 2.6
- '....
- ThisDrawing.Regen acActiveViewport
- PlotLayout strFWJZMJFCHZB, False
- DeleteLayout strFWJZMJFCHZB
- End Sub
方便吧,一切尽在掌握中。
去实现你自己图文并茂的报表生成器吧! |
|