home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "modExtrudeText"
- '******************************************************************'
- '* *'
- '* TurboCAD for Windows *'
- '* Copyright (c) 1993 - 2001 *'
- '* International Microcomputer Software, Inc. *'
- '* (IMSI) *'
- '* All rights reserved. *'
- '* *'
- '******************************************************************'
-
- 'All variables must be declared
- Option Explicit
-
- 'Useful constant for rotations that need to be specified in radians
- Const Pi# = 3.14159
-
- 'Text string to create
- Const Text As String = "Hello, 3D World!"
-
- 'Height of text in world units
- Const TextHeight# = 0.8
-
- 'Angle to draw text at (45 degrees)
- Const TextAngle# = 45 * (Pi / 180)
-
- 'CountCosmetics
- 'Report how many child graphics are cosmetic
- Private Function CountCosmetics(ByVal gr As Graphic)
- Dim cCosmetic As Long
- cCosmetic = 0
- With gr.Graphics
- Dim count As Long
- count = .count
- Dim i As Long
- For i = 0 To count - 1
- If .Item(i).Cosmetic Then cCosmetic = cCosmetic + 1
- Next
- End With
- CountCosmetics = cCosmetic
- End Function
-
- 'DebugGraphicInfo
- 'Just dump some information into the Visual Basic Immediate Window
- Private Sub DebugGraphicInfo(ByVal Name As String, ByVal gr As Graphic)
- Debug.Print Name & ": type = "; gr.Type
- Debug.Print " with " & gr.Vertices.count & " vertices"
- Debug.Print " and " & gr.Graphics.count & " child graphics (" & _
- CountCosmetics(gr) & " cosmetic)"
- End Sub
-
- 'CreateExtrudedText
- 'Example to demonstrate the use of TEXT and TCW40EXTRUDE graphic subtypes
- 'Steps in the macro:
- 'Step 1. Create and position a flexible text TEXT graphic
- 'Step 2. Explode the TEXT graphic into individual letters
- 'Step 3. Create an extrusion of each letter, varying the extrusion height and color
- 'Make it Public, in case you want to re-use this
- Public Sub CreateExtrudedText()
-
- 'Graphics collection that we create text and extrusions with
- Dim Grs As Graphics
- Set Grs = ActiveDrawing.Graphics
-
- 'Step 1. Create and position a flexible TEXT graphic
- 'AddText method takes string, starting point X, Y, Z, and height
- Dim GrText As Graphic
- Set GrText = Grs.AddText(Text, 0, 0, 0, TextHeight)
- DebugGraphicInfo "GrText created", GrText
-
- 'Set the newly created TEXT graphic to "Flexible" type
- 'Flexible text is described by polygons
- GrText.Properties("TextMode") = 3 'TextMode 3 = Flexible
-
- 'Get TEXT graphic's center from it's bounding box
- Dim xc#, yc#, zc#
- With GrText.CalcBoundingBox
- xc = (.Max.X + .Min.X) / 2
- yc = (.Max.Y + .Min.Y) / 2
- zc = (.Max.Z + .Min.Z) / 2
- End With
-
- 'Rotate the TEXT graphic 45 degrees about the Z axis
- 'RotateAxis method takes angle, axis, and center of rotation
- GrText.RotateAxis TextAngle, 0, 0, 1, xc, yc, zc
-
- 'Translate the TEXT graphic so that the center of the graphic is at 5, 5, 0
- Dim x0#, y0#, z0#
- x0 = 5: y0 = 5: z0 = 0
- GrText.MoveRelative x0 - xc, y0 - yc, z0 - zc
-
- 'Step 2. Explode the TEXT graphic into individual letters
- 'Exploding a flexible TEXT graphic returns a GraphicSet containing
- 'only one graphic: a Group of graphics.
-
- 'Explode method returns a GraphicSet; we take the first and only one (index 0).
- 'GrExplode is a group object
- Dim GrExplode As Graphic
- Set GrExplode = GrText.Explode(0)
- DebugGraphicInfo "GrExplode created", GrExplode
-
- 'Explode the group and get a GraphicSet, in which each graphic
- 'is a polyline (with possible pen up segments) representing an individual letter.
- Dim GrSet As GraphicSet
- Set GrSet = GrExplode.Explode
-
- 'Step 3. Create an extrusion of each letter, varying the extrusion height and color
- With GrSet
-
- 'Get the size of the GraphicSet
- Dim GrSetCount As Long
- GrSetCount = .count
-
- 'Go through each letter in the GraphicSet
- Dim i As Long
- For i = 0 To GrSetCount - 1
-
- 'GrSect is a letter graphic left from the explosion
- Dim GrSect As Graphic
- Set GrSect = .Item(i)
- DebugGraphicInfo "GrSect(" & i & ") from set", GrSect
-
- 'Deselect it; Explode always selects the result of the explosion
- GrSect.Properties("Selected") = 0
-
- 'Create an extrusion
- 'Add method takes RegenMethod optional parameter to create a Regen graphic
- Dim GrExtrude As Graphic
- Set GrExtrude = Grs.Add(RegenMethod:="TCW40EXTRUDE")
- DebugGraphicInfo "GrExtrude(" & i & ") created", GrExtrude
-
- 'Make the extrusion graphic transparent
- GrExtrude.Properties("Solid") = 0
-
- 'Give it one of the 16 "basic" colors
- 'See the VBA documentation for QBColor...
- GrExtrude.Properties("PenColor") = QBColor(i + 1)
-
- 'Take the letter graphic out of the drawing...
- Grs.Remove GrSect.Index
-
- '...and make it the child of the extrusion
- GrExtrude.Graphics.AddGraphic GrSect
- DebugGraphicInfo "GrExtrude(" & i & ") with base graphic", GrExtrude
-
- 'Now add the extrusion vector origin (first vertex)
- GrExtrude.Vertices.Add 0, 0, 0
-
- 'And extrusion vector end point (second vertex)
- Dim ExtrusionZ#
- ExtrusionZ = (i + 1) * TextHeight / 4
- GrExtrude.Vertices.Add 0, 0, ExtrusionZ
- DebugGraphicInfo "GrExtrude(" & i & ") before Update", GrExtrude
-
- 'Force the Regen to generate the 3D polygons correctly
- 'The Update command will also add a third vertex and the cosmetic graphics
- GrExtrude.Update
- DebugGraphicInfo "GrExtrude(" & i & ") after Update", GrExtrude
-
- 'And draw the 3D letter on the view now
- GrExtrude.Draw
- Next
- End With
- End Sub
-