home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / v8trial / TurboCADv8ProfessionalNoReg.exe / Data.Cab / F42055_modTitleBlock.bas < prev    next >
Encoding:
BASIC Source File  |  2001-10-16  |  5.1 KB  |  166 lines

  1. Attribute VB_Name = "modTitleBlock"
  2. '******************************************************************'
  3. '*                                                                *'
  4. '*                      TurboCAD for Windows                      *'
  5. '*                   Copyright (c) 1993 - 2001                    *'
  6. '*             International Microcomputer Software, Inc.         *'
  7. '*                            (IMSI)                              *'
  8. '*                      All rights reserved.                      *'
  9. '*                                                                *'
  10. '******************************************************************'
  11.  
  12. Option Explicit
  13.  
  14. Sub SetTitleBlock()
  15.  
  16. 'Code in this listing does several things:
  17. 'First, we get a reference to the active drawing object, then we set its
  18. 'drawing mode to Paper Space (Paper Space and Model Space will be discussed
  19. 'in Chapter 5), then we define paper size, calculate and draw border
  20. 'rectangle within defined paper space and margins, then draw the title box
  21. 'within the border rectangle (as a table), and then fill two cells of the
  22. 'title box table with simple text: "Design By" and "Project".
  23.  
  24. 'Set up error handler
  25.   On Error GoTo SetTitleBlock_Err
  26.  
  27. 'Declare and set major TurboCAD objects
  28.   Dim ActDr As Drawing
  29.   Dim Grs As Graphics
  30.   Dim Gr As Graphic
  31.   Dim Vi As View
  32.     
  33. 'Get active drawing object
  34.   Set ActDr = ActiveDrawing
  35.     
  36. 'Set active drawing space: Paper Space = 0, Model Space = 1
  37.   ActDr.Properties("TileMode") = 0
  38.         
  39. 'Get graphics collection of the active drawing
  40.   Set Grs = ActDr.Graphics
  41.  
  42. 'Set measurement units for the current drawing space to inches
  43.   ActDr.Properties("PaperLinearUnitName") = "in"
  44.  
  45. 'Declare variables to hold paper size data
  46.   Dim PSetUp As PageSetup
  47.   Dim SpaceUnits$, UnitScale#
  48.   Dim PaperWidth#, PaperHeight#
  49.  
  50. 'Read property (we set it to inches ealier in the code)
  51.     SpaceUnits = ActDr.Properties("PaperLinearUnitName")
  52.  
  53. 'Read paper size properties (we don't need to do that, it's just an illustration)
  54.     Set PSetUp = ActDr.PageSetup
  55.     PaperWidth = PSetUp.SheetWidth
  56.     PaperHeight = PSetUp.SheetHeight
  57.     
  58. 'Set paper size
  59.     PaperWidth = 12#
  60.     PaperHeight = 10#
  61.  
  62. 'Define scaling rate depending on measurement units specified by user
  63. '(in our case we programmtically set 'PaperLinearUnitName' to inches û
  64. 'see code above).We need to convert user measurement units to millimiters
  65. '(TurboCAD's internal measurement units)
  66.     If SpaceUnits = "mm" Then UnitScale = 1
  67.     If SpaceUnits = "cm" Then UnitScale = 10
  68.     If SpaceUnits = "m" Then UnitScale = 100
  69.     If SpaceUnits = "in" Or SpaceUnits = """" Then UnitScale = 25.4
  70.     If SpaceUnits = "ft" Or SpaceUnits = "'" Then UnitScale = 25.4 * 12
  71.     
  72.     PSetUp.SheetWidth = PaperWidth * UnitScale
  73.     PSetUp.SheetHeight = PaperHeight * UnitScale
  74.  
  75. 'Calculate rectangle for the frame based on defined paper size including margins
  76.   Dim LeftMargin#, RightMargin#, TopMargin#, BottomMargin#
  77.   Dim xLeft#, xRight#, yBottom#, yTop#
  78.     LeftMargin = 1
  79.     RightMargin = 0.5
  80.     TopMargin = 0.5
  81.     BottomMargin = 0.5
  82.     
  83.     xLeft = LeftMargin
  84.     xRight = PaperWidth - RightMargin
  85.     yBottom = BottomMargin
  86.     yTop = PaperHeight - TopMargin
  87.     
  88. 'Draw frame
  89.     Set Gr = Grs.Add(imsiPolyline)
  90.     With Gr.Vertices
  91.         .Add xLeft, yBottom, 0
  92.         .Add xRight, yBottom, 0
  93.         .Add xRight, yTop, 0
  94.         .Add xLeft, yTop, 0
  95.         .AddClose
  96.     End With
  97.     Gr.Properties("PenWidth") = 0.01
  98.     Gr.Draw
  99.     
  100. 'Draw Title Box (as a table)
  101.   Dim GrTable As Graphic
  102.   Dim hTable#, wTable#
  103.   Dim xL#, xR#, yB#, yT#, xMid#, yMid#
  104.  
  105.     hTable = 1
  106.     wTable = 6
  107.     
  108.     xL = xRight - wTable
  109.     xR = xL + wTable
  110.     yB = yBottom
  111.     yT = yB + hTable
  112.     xMid = (xL + xR) / 2
  113.     yMid = (yB + yT) / 2
  114.     
  115.     Set GrTable = Grs.Add(imsiPolyline)
  116.     With GrTable.Vertices
  117.         .Add xL, yB, 0
  118.         .Add xR, yB, 0
  119.         .Add xR, yT, 0
  120.         .Add xL, yT, 0
  121.         .Add xL, yB, 0
  122.         .Add xL, yMid, 0, False
  123.         .Add xR, yMid, 0
  124.         .Add xMid, yB, 0, False
  125.         .Add xMid, yT, 0
  126.     End With
  127.     GrTable.Properties("PenWidth") = 0.01
  128.     GrTable.Draw
  129.  
  130. 'Add text to table
  131.   Dim GrText As Graphic
  132.   Dim InputString$
  133.     
  134.     InputString = "Design By"
  135.     Set GrText = Grs.AddText(InputString, (xL + xMid) / 2, yT, 0, hTable / 2, , , , 2)
  136.     InputString = "Project"
  137.     Set GrText = Grs.AddText(InputString, (xMid + xR) / 2, yT, 0, hTable / 2, , , , 2)
  138.  
  139. 'Get actiev view of the active drawingà
  140.   Set Vi = ActDr.Views(0)
  141. 'à and fit drawing to screen
  142.   Vi.ZoomToExtents
  143.  
  144. SetTitleBlock_Exit:
  145.  
  146. 'Destroy TurboCAD objects
  147.     Set ActDr = Nothing
  148.     Set Grs = Nothing
  149.     Set PSetUp = Nothing
  150.     Set Gr = Nothing
  151.     Set GrTable = Nothing
  152.     Set GrText = Nothing
  153.     Set Vi = Nothing
  154.     
  155.     Exit Sub
  156.  
  157. SetTitleBlock_Err:
  158.     If Err.Number <> 0 Then
  159.        MsgBox "Error " & Err.Number & " in Sub 'SetTitleBlock'" & _
  160.        vbLf & vbLf & Err.Description
  161.        Resume SetTitleBlock_Exit
  162.     End If
  163. End Sub
  164.  
  165.  
  166.