TheSwamp

Code Red => VB(A) => Topic started by: JayRem on December 16, 2004, 05:16:27 PM

Title: Modify Text
Post by: JayRem on December 16, 2004, 05:16:27 PM
I have text that outputs as a number say 96 for example which represents inches.  That's fine and dandy but what I am looking to do is change that from "96" to 8' - 0".   Hopefully that makes sense.  The program that I have puts the dimensions of a rectangle in the center by using the bounding box.  If anyone has an idea please shoot it past me.  Thanks in advance again!
Title: Modify Text
Post by: Keith™ on December 16, 2004, 05:25:19 PM
What is the program written in VBA I presume ... if tht is the case ... then

Code: [Select]

Var = ThisDrawing.Utility.RealToString(Var, acArchitectural, Precision)


Var is your variable variant 96
Precision is an integer 0-14

Return value is the string value representing your Var
Title: Modify Text
Post by: JayRem on December 16, 2004, 05:29:43 PM
I'll give it a try thanks man
Title: Modify Text
Post by: JayRem on December 16, 2004, 05:40:55 PM
Keith,

I'm still havin' trouble If I post my code could ya give it a tweek??  I'm not sure as to where to put your last statement you posted...

Code: [Select]
Sub TextDemo()
    Dim objsset As AcadSelectionSet
   Dim ObjEnt As AcadEntity
    Dim minExt As Variant
    Dim maxExt As Variant
    Dim text1 As Double
Dim text2 As AcadText
Dim text3 As Double
Dim text As String
Dim text4 As AcadText
Dim height As Double
height = 4
Dim inst(0 To 2) As Double
Dim var As Variant
inst(2) = 0
Set objsset = ThisDrawing.PickfirstSelectionSet
objsset.Select acSelectionSetAll
For Each ObjEnt In objsset
If ObjEnt.Layer = "0" Then
    ObjEnt.GetBoundingBox minExt, maxExt
    text1 = maxExt(1) - minExt(1)
    text3 = maxExt(0) - minExt(0)
    inst(0) = (maxExt(0) - (text3 / 2)) - 6
    inst(1) = maxExt(1) - (text1 / 2)
    text = "x"
    Set text4 = ThisDrawing.ModelSpace.AddText(text, inst, height)
    inst(1) = inst(1) + 5
    text = text1
    Set text4 = ThisDrawing.ModelSpace.AddText(text, inst, height)
    inst(1) = inst(1) - 10
    text = text3
    Set text4 = ThisDrawing.ModelSpace.AddText(text, inst, height)
    End If
Next
objsset.Delete
End Sub
Title: Modify Text
Post by: Keith™ on December 16, 2004, 09:00:20 PM
Try this

Code: [Select]

Sub TextDemo()
    Dim objsset As AcadSelectionSet
    Dim ObjEnt As AcadEntity
    Dim minExt As Variant
    Dim maxExt As Variant
    Dim BoxWidth As Variant
    Dim BoxHeight As Variant
    Dim Text As AcadText
    Dim Height As Double
    Dim inst(0 To 2) As Double
    Dim PrecVal As Integer
   
    Height = 4
    inst(2) = 0
    PrecVal = ThisDrawing.GetVariable("LUPREC")
   
    Set objsset = ThisDrawing.PickfirstSelectionSet
    objsset.Select acSelectionSetAll
       
    'On Error Resume Next
    For Each ObjEnt In objsset
      If ObjEnt.Layer = "0" Then
        ObjEnt.GetBoundingBox minExt, maxExt
        BoxHeight = maxExt(1) - minExt(1)
        BoxWidth = maxExt(0) - minExt(0)
        inst(0) = (maxExt(0) - (BoxWidth / 2)) - 6
        inst(1) = maxExt(1) - (BoxHeight / 2)
        Set Text = ThisDrawing.ModelSpace.AddText("x", inst, Height)
        Text.Alignment = acAlignmentMiddleCenter
        Text.TextAlignmentPoint = inst
        inst(1) = inst(1) + 5
        Set Text = ThisDrawing.ModelSpace.AddText(ThisDrawing.Utility.RealToString(BoxHeight, acArchitectural, PrecVal), inst, Height)
        Text.Alignment = acAlignmentMiddleCenter
        Text.TextAlignmentPoint = inst
        inst(1) = inst(1) - 10
        Set Text = ThisDrawing.ModelSpace.AddText(ThisDrawing.Utility.RealToString(BoxWidth, acArchitectural, PrecVal), inst, Height)
        Text.Alignment = acAlignmentMiddleCenter
        Text.TextAlignmentPoint = inst
      End If
    Next
objsset.Delete
End Sub
Title: Modify Text
Post by: JayRem on December 17, 2004, 09:21:50 AM
Thanks a lot man!!  And here's the best part, I understand it!!

Thanks a billion
Title: Modify Text
Post by: Keith™ on December 17, 2004, 09:27:59 AM
No problem .. glad it works for you...