+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Forum Newbie
    Using
    AutoCAD 2006
    Join Date
    Dec 2010
    Posts
    3

    Default Feet Inches to metric

    Registered forum members do not see this ad.

    Hi,
    Does anyone have a VBA function that will convert drawing text that's in feet, inches and fractions of an inch (5'-11 -1/2") into metric equivelent? I can't seem to find one. This would be for text only, not a dimension.

    Thanks.

  2. #2
    Forum Deity SEANT's Avatar
    Using
    AutoCAD 2014
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    2,453

    Default

    This would work, but the text would have to be in a very specific format i.e.:

    5'-11 1/2"

    Code:
     
    Sub ToMetric()
    Dim entTxt As AcadText
    Dim dblmeasure As Double
    Dim varpkpt As Variant
    Dim ent As AcadEntity
       With ThisDrawing
       
          .Utility.GetEntity ent, varpkpt, "Select measure as text."
          If TypeOf ent Is AcadText Then
             Set entTxt = ent
             dblmeasure = .Utility.DistanceToReal(entTxt.TextString, acArchitectural) * 0.0254
             Set entTxt = ThisDrawing.ModelSpace.AddText(CStr(dblmeasure) & " Meters", entTxt.InsertionPoint, entTxt.Height)
             ent.Delete
          End If
       End With
    End Sub

  3. #3
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Code:
    Option Explicit
     
    ' --> request reference to Microsoft VBScript Regular Expression 5.5
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    Sub MerryXmass()              'from fixo'
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    Dim s As String
    Dim i As Long
    Dim cnt As Integer
    Dim quotes As Integer
    Dim num As Double
    Dim regex As regexp
    Set regex = New regexp
    regex.IgnoreCase = True
    regex.Global = False
    cnt = 0
    ''Tested:
    's = "5 \ ' - 11 - 1/2\ """ 'ok
    ''s = "10 - 1/2\ """ 'ok
    s = "18/32\ """ 'ok
    Dim ar() As String
    Dim decs() As String
    If quotes = 1 And cnt = 2 Then
    regex.Pattern = "(\d+)(.*)(\d{1,2})(.*)(\d+)(/)(\d{1,2})(.*)$"
    s = regex.Replace(s, "$1;$3;$5;$7")
    MsgBox s
    ar = Split(s, ";", -1, 1)
    num = (CDbl(ar(0)) * 12 + (CDbl(ar(1)) + CDbl(ar(2)) / CDbl(ar(3)))) * 0.0254
    ''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''
    ElseIf quotes = 0 And cnt = 1 Then
    s = Replace(s, "-", ";", 1, -1, 1)
    s = Replace(s, Chr(34), "", 1, -1, 0)
    s = Replace(s, Chr(92), "", 1, -1, 0)
    ar = Split(s, ";", -1, 0)
    decs = Split(ar(1), "/", -1, 0)
    num = (CDbl(ar(0) + CDbl(decs(0)) / CDbl(decs(1)))) * 0.0254
    ''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''
    ElseIf quotes = 0 And cnt = 0 Then
    s = Replace(s, "/", ";", 1, -1, 1)
    s = Replace(s, Chr(34), "", 1, -1, 0)
    s = Replace(s, Chr(92), "", 1, -1, 0)
    decs = Split(s, ";", -1, 0)
    num = (CDbl(decs(0)) / CDbl(decs(1))) * 0.0254
    ''~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''
    Else
    MsgBox "Unknown format"
    End If ''
    Set regex = Nothing
    Debug.Print num
    End Sub
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    Private Function CountChars(source As String, find As String) As Integer
    Dim i As Long
    Dim c As Long
    Dim ch As Integer
    ch = Asc(find)
    Dim x() As Byte
    x = StrConv(source, vbFromUnicode)
    For i = 0 To UBound(x)
    If x(i) = CByte(ch) Then
    c = c + 1
    End If
    Next
    CountChars = c
    End Function
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    Merry Xmass *Seant* and all of the friends of mine from here

    Oleg
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  4. #4
    Forum Newbie
    Using
    AutoCAD 2006
    Join Date
    Dec 2010
    Posts
    3

    Default

    MerryXmas Fixo but I'm stuck on how to use MerryXmass. I'm almost certain it's what I'm looking for. What would you recommend I try to see how this will work with some AutoCAD text?

  5. #5
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    I didn't check the project carefully, you make it
    Attached Files
    Last edited by fixo; 22nd Dec 2010 at 10:19 am. Reason: added project
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  6. #6
    Forum Deity SEANT's Avatar
    Using
    AutoCAD 2014
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    2,453

    Default

    Merry Christmas, Fixo, my friend. I’ll have to study this use of Regular Expression; a nice gift for anyone, not just the original poster.

  7. #7
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Thanks so much , Sean, my friend
    Unfortunatelly, I have not enough time to write all condition using regular expression
    just the first one from them
    I'd like to wish you all of the best in new year
    Regards,

    Oleg
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  8. #8
    Forum Newbie
    Using
    AutoCAD 2006
    Join Date
    Dec 2010
    Posts
    3

    Default

    Registered forum members do not see this ad.

    FaLaLaLaLa...LaLaLaLa.

    Thank you Fixo! Having much fun with your gift. Still tweeking it but had to let you know I'm thrilled so far.

Similar Threads

  1. change ordi.lsp to feet and inches from decimal inches?
    By losquest in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 18th Sep 2010, 11:43 pm
  2. feet inches to metric
    By Nathandi in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 22nd Dec 2009, 12:32 pm
  3. how to set feet & inches
    By gracehazelby in forum AutoCAD General
    Replies: 13
    Last Post: 23rd Oct 2008, 05:06 pm
  4. Convert Feet & Inches Drawing into Metric??
    By Unick in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 1st Aug 2007, 03:39 pm
  5. inches to feet
    By giloosh in forum AutoCAD Beginners' Area
    Replies: 5
    Last Post: 13th Sep 2005, 10:49 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts