News:

Be sure your post is relevant to the current discussion.  Create a new topic within the appropriate board if you are unsure.

Main Menu
TurboCAD 2026 Platinum box
Now available

TurboCAD 2026.2

The latest update for TurboCAD 2026. It installs over any 2026 build and keeps your activation, drawings and settings. Get it from the Start Page or Help > Check for Update.

VBA (VB Scripts) Text Justification

Started by JMWolzSr, May 10, 2016, 01:48:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JMWolzSr

I am using VBA running in Excel to collect surveying coordinates from a TC Drawing.  Once I add the coordinates to the spread sheet, I add the point number to the drawing (and other info, as desired).  However, I am confused about what some of the optional parameters are and specifically what the Justification equivalents are.  The VBA format is:

Function AddText(Text As String, X0 As Double, Y0 As Double, Z0 As Double, Height As Double, [Angle], [Width], [Offset], [Justification]) As Graphic
    Member of IMSIGX.Graphics
    Creates and adds a text Graphic object to the collection.

Required parameters, no problem.

Optional parameters beginning with: Angle, no problem; Width, I assume this allows you to stretch or squeeze the text horizontally, but not important; Offset, don't know what this does, tried several numbers that did not appear to have an impact; Justification, originally assumed it was looking for "Top Left" or similar, however, it needs to be numeric, "1" equals top left justification, tried 1 through 11 that produced eight unique combinations of reference points and horizontal justification, always had "Top", tried some random numbers - 20 30 - with unpredictable results, found that Drawing_Defaults.ini has Justification set at 256 in an older version.

So, does anyone know what the proper numbers are for the sixteen different horizontal and vertical Justification combinations?

If you could verify my guess about Width and know what Offset is and the details that would be a plus.

Finally, how do you format the font of the AddText?  I've tried presetting the font, changing the standard text style, and other things, but it always is Times New Roman.
"Nothing ever comes to one, that is worth having, except as a result of hard work."

--Booker T. Washington,
American educator and political leader

Andy H

#1
Had a look round and found this in the sdk help file,

TextMode Enum:      1 = Standard Text, 2 = Scalable Text, 3 = Flexible Text

TextFormat         257 = Top Left; 258 = Top Center; 260 = Top Right; 513 = Middle Left; 514 = Middle Center; 516 = Middle Right; 1025 = Baseline Left; 1026 = Baseline Center; 1028 = Baseline Right; 2049 = Bottom Left; 2050 = Bottom Center; 2052 = Bottom Right

TextSize The size of the text

Obliquity Slant angle in degrees for Flexible Text

and a test script which I tried out as a script (not exactly as shown in the example) and it worked but not exactly how I thought it would.
'Draw one sample of each text justification format
Dim app As IMSIGX.Application
Dim drw As IMSIGX.Drawing
Dim grf As IMSIGX.Graphic
Dim base As Integer
Dim fmt As Integer
Set app = GetObject("", "TurboCAD.Application")
Set drw = app.Drawings.Add
For i = 0 to 3
  base = 256
  if i = 1 Then base = 512
  if i = 2 Then base = 1024
  if i = 3 Then base = 2048
  For j = 0 to 2
    fmt = base + 1
    if j = 1 Then fmt = base + 2
    if j = 2 Then fmt = base + 4
    Set grf = drw.Graphics.AddText("Format_" & fmt, 0, 3*i+j, 0, 0.25, 0, , , fmt)
  Next
Next

Width - no idea,  if it is for text width then the text would need to be in scalable or possible flexible mode, and although one can change drawing default to scalable, I can't find a way to change system defaults that way.

Font - its probably using drawing defaults for the text, Someone will need to correct me here if I'm wrong, but I think the text styles are drawing / template specific, so you could change the style in the style manages, click the button 'apply changes', close the style manager then save as a template for future use.

Just had another play and its using system defaults on my computer, to get it to work with the font Arial I had to use TC explorer palette to change the program default to Arial.

JMWolzSr

Thanks!

TextFormat         257 = Top Left; 258 = Top Center; 260 = Top Right; 513 = Middle Left; 514 = Middle Center; 516 = Middle Right; 1025 = Baseline Left; 1026 = Baseline Center; 1028 = Baseline Right; 2049 = Bottom Left; 2050 = Bottom Center; 2052 = Bottom Right

This is exactly what I needed.  When I saw that the default was 256, I figured it would be related to progressive squares of 2.  However, it would have taken some trial and error to come up with the plus 1(left), 2(center), 4(right), 8(fit) to complete the puzzle.  Therefore, bits 1-4 and 9-12 of a two byte number are horizontal justification - left, center, right, fit - and vertical justification - top, middle, baseline, bottom - respectively.

I haven't tested out your ideas on the font.
"Nothing ever comes to one, that is worth having, except as a result of hard work."

--Booker T. Washington,
American educator and political leader