TheSwamp
Code Red => VB(A) => Topic started by: Matersammichman on August 04, 2006, 01:21:21 PM
-
How can you use vba to make underlined text?
-
Like so:
Dim InsPt(2) As Double
Dim strTxt As String
strTxt = "How about %%uunderline%%u?"
ThisDrawing.ModelSpace.AddText strTxt, InsPt, 0.2
-
Hmmm...
I'm with ya, but I'd like to be able to put in the text from a text box input , and not have to put in "%%U" every time...
more ideas?
-
Huh? You mean like this?
Dim InsPt(2) As Double
Dim strTxt As String
strTxt = "%%u" & TextBox1.Value & "%%u"
ThisDrawing.ModelSpace.AddText strTxt, InsPt, 0.2
-
Yes, thank you.
-
Okay, let's carry it a step further-
How would you create DOUBLE underlined text?
-
Okay, let's carry it a step further-
How would you create DOUBLE underlined text?
how would you do it in regular acad?
-
unfortunately...draw another line under the text manually.
-
I thought there was a font properties that allowed you to have double underline.
-
I thought there was a font properties that allowed you to have double underline.
not in AutoCAD
-
unfortunately...draw another line under the text manually.
given that, you could use the text ins pt, and calc the text length, then offset (or draw) a second line below the first.
-
I actually have this done in VBA as our titles at work are text with double underlines drawn in.
I will post the code once I get to work.
-
Obviously you can go and customize to your hearts content.
They are plines so that the width can be made to what you need.
Public Sub TitleLine()
Dim objPick As AcadEntity
Dim varPnt As Variant
Dim strPrmt As String
Dim objUtil As AcadUtility
Dim fPt As Variant
Dim rpt As Variant
Dim txtIns As Variant
Dim lin As AcadLine
Dim plin As AcadPolyline
Dim plinpts(0 To 5) As Double
Dim linst(0 To 2) As Double
Dim linend(0 To 2) As Double
Dim fx As Variant
Dim rx As Variant
Dim midx As Variant
Dim modscl As Integer
On Error GoTo ErrHandler
strPrmt = vbCr & "Pick Title: "
Set objUtil = ThisDrawing.Utility
DoOver:
objUtil.GetEntity objPick, varPnt, strPrmt
If TypeOf objPick Is AcadText Then
objPick.GetBoundingBox fPt, rpt
txtIns = objPick.InsertionPoint
If rpt(0) - fPt(0) < 1.75 Then
midx = fPt(0) + (0.5 * (rpt(0) - fPt(0)))
fx = midx - 0.875
rx = midx + 0.875
Else
fx = fPt(0)
rx = rpt(0)
End If
If ThisDrawing.ActiveSpace = acPaperSpace Then
plinpts(0) = fx
plinpts(1) = txtIns(1) - 0.0625
plinpts(2) = 0
plinpts(3) = rx
plinpts(4) = txtIns(1) - 0.0625
plinpts(5) = 0
Set plin = ThisDrawing.PaperSpace.AddPolyline(plinpts)
plin.ConstantWidth = 0.03125
plin.layer = "0"
plin.color = acGreen
linst(0) = fx
linst(1) = plinpts(1) - 0.0625
linst(2) = 0
linend(0) = rx
linend(1) = linst(1)
linend(2) = 0
Set lin = ThisDrawing.PaperSpace.AddLine(linst, linend)
lin.layer = "0"
lin.color = acGreen
Else
modscl = objPick.height / 0.175
plinpts(0) = fx
plinpts(1) = txtIns(1) - (0.0625 * modscl)
plinpts(2) = 0
plinpts(3) = rx
plinpts(4) = txtIns(1) - (0.0625 * modscl)
plinpts(5) = 0
Set plin = ThisDrawing.ModelSpace.AddPolyline(plinpts)
plin.ConstantWidth = (0.03125 * modscl)
plin.layer = "0"
plin.color = acGreen
linst(0) = fx
linst(1) = plinpts(1) - (0.0625 * modscl)
linst(2) = 0
linend(0) = rx
linend(1) = linst(1)
linend(2) = 0
Set lin = ThisDrawing.ModelSpace.AddLine(linst, linend)
lin.layer = "0"
lin.color = acGreen
End If
End If
'GoTo DoOver
ExitNow:
Exit Sub
ErrHandler:
Select Case Err.Number
Case -2147352567
Err.Clear
GoTo ExitNow
Case Else
Err.Clear
GoTo ExitNow
End Select
End Sub
-
Great code Murphy!
Thanks!
-
Not a problem. That's what makes this place so great.
Why redo what someone has already done?