AutoCAD VBA: selected TextString contains misrecognized characters

74 views Asked by At

I want to develop a program for converting selected Text objects containing Arabic/Persian SHX shapes into Arabic/Persian regular texts.

Similar to the screenshot below, as a text is selected, all the characters (contents) are shown in a pop-up window. In this picture, فرعی چهارم (4) is created using tءuŒ }ڑ—v¥ )4( characters. Therefore, everything should get translated fine by remapping the characters into their equivalent on an Arabic keyboard.

enter image description here

However, when the same text is retrieved inside the VBA editor, text contents are incorrectly shown (for example, tءuŒ }ڑ—v¥ )4( is shown as t?uŒ }?—v¥ )4(, please be advised that some characters are not recognized and replaced with ?)

enter image description here

Therefore, as the procedures continue, we end up in a wrong translation, because of those initial ? characters.

enter image description here

The part of the code that seeks to retrieve the selected texts is as follows:

Private Sub convertBtn_Click() 'When the user clicks on the translator icon/button, this code starts running
    Dim txt As String
    Dim textObject As AcadText
    Dim actSelSet As AcadSelectionSet
    
    ThisDrawing.Activate 'activate the drawing in which the user has hit the translate button
    Set actSelSet = ThisDrawing.PickfirstSelectionSet    'This is the current selection on the model screen
    For Each i In actSelSet              'iterates all the selected objects
        If TypeOf i Is AcadText Then     'check whether the selection is a textObject or not
            txt = i.TextString           'The text property of the selected text object
            Debug.Print CStr(txt)
            textStringConversion.strToAsc (txt)
        End If
    Next i
End Sub

How to retrieve the text contents correctly, just as they are shown in the AutoCAD properties tab?

0

There are 0 answers