Creating a Label Text with AC Globals

Example object for this post can be downloaded here.

When creating labels, the most convenient way is to follow and use the built-in parametrisation of ARCHICAD labels – to have the same kind of settings for pointer and text, and to set your custom parameters on the graphical UI.

On the “Settings dialog” of a label, there are 4 different panels for the parameter settings: 2 for the common settings and 2 others for the libpart specific settings. In the following example only the parameters on the Text Style Panel are used. For the available Global variables for the Labels see the GDL Reference Guide.

Parameters on Text Style Panel

An overview of this panel, with the connecting global variable names:

Parameters for defining style

LABEL_FONT_NAME: Contains the selected font type and the font script on windows.
LABEL_TEXT_SIZE: always stores the font size in “mm”, even if the infield set to points. This calculation is done by ARCHICAD in the background. 72 points = 25.4 mm
LABEL_FONT_STYLE2: this variable is an integer, holding information of the bold/italic/underline/strikethrough checkboxes, and can be simply used in DEFINE STYLE{2} commands. There is an old variable, called LABEL_FONT_STYLE: it contains informations from the first 3 checkboxes, and can be used in DEFINE STYLE commands.

Parameters for paragraphs and textblocks

LABEL_TEXT_PEN: Label’s text pen.
LABEL_TEXT_ALIGN: Integer parameter for storing the text alignment information. Can be used as a parameter of PARAGRAPH command.
LABEL_TEXT_LEADING: The leading or line spacing value is a multiplier for the vertical space between lines, measured from the baseline of one text line to the baseline of the previous line. The percent value is converted to a real number (100% equals 1). Can be used as a parameter of TEXTBLOCK command.
LABEL_TEXT_WRAP: The Wrap Text checkbox “locks” the width of a placed text block (including those placed as non‐breaking text blocks), so when you add text which would extend beyond the text block margin, it will be wrapped to the next line. If this box is unchecked, the text block size is determined by the length of the text it contains.
LABEL_TEXT_WIDTH_FACT, LABEL_TEXT_CHARSPACE_FACT: The text width factor and charspace factor percentage values are converted to a real number where 100% equals 1. Can be used as a parameter of TEXTBLOCK command.

Example for text formatting in labels

With the variables above, you can easily define and use it as your own style:

! ------------------------------------------------------------------------------
! Input parameters controlled by the user:
! ------------------------------------------------------------------------------
! labelWidth 		- (RealNum) The Width of the Label Text in Paper size - mm
!			  in case the Wrap Text is ON

mySampleString = "Simple label sample\nSecond line"

define style{2} "mySampleStyle" LABEL_FONT_NAME,	! name font_family
				LABEL_TEXT_SIZE,	! size
				LABEL_FONT_STYLE2	! face_code

paragraph "mySamplePar"	LABEL_TEXT_ALIGN,	! name alignment
			0,			! firstline_indent
			0,			! left_indent
			0,			! right_indent
			LABEL_TEXT_LEADING	! line_spacing
	style "mySampleStyle"

	_textBlockWidth = labelWidth		! fixed with in Paper Size - mm
	_textBlockWidth = 0			! calculated width

textblock "mySampleBlock"	_textBlockWidth,		! name width 
				4,				! anchor
				0,				! angle
				LABEL_TEXT_WIDTH_FACT,		! width_factor
				LABEL_TEXT_CHARSPACE_FACT,	! charspace_factor
				1,				! fixed_height
				"mySamplePar"			! paragraph's name

richtext2 0, 0, "mySampleBlock"

Parameters for Label text box fill

In addition to control the text style, further style settings can be set with the ARCHICAD Global Variables. With the Frame, Frame Offset and Opaque globals a fill can be created for the Label text box.

LABEL_FRAME_ON: New global from AC19. Checking the Frame checkbox creates an automatic solid line frame for the Label text box, if the Pointer is checked in (LABEL_CUSTOM_ARROW = 0). If you want to create a frame in case of the Pointer is unchecked, this global is recommended.
LABEL_CUSTOM_ARROW: Checking the Pointer button creates an automatic pointer line for the Label text box. This button also controls the automatic frame.
LABEL_FRAME_OFFSET: New global from AC19. If desired, offset the Frame from the text by entering an offset value in the field at right.
LABEL_TEXT_BG_PEN: Checking the Opaque checkbox allows you to set a background color for your label that differs from the screen’s background color. Checking the box activates the pencolor selection settings at right: open the pop‐up palette to choose a color. If the opaque is OFF then LABEL_TEXT_BG_PEN global gives back zero which is the transparent pen number.

Example for text box fill formatting in labels

In the following example it is supposed that the Pointer checkbox is unchecked (LABEL_CUSTOM_ARROW = ON), otherwise an automatic Frame is created for the label text box.

For creating a fill the sizes of the textblock and the frame offset have to be known. The “TEXTBLOCK_INFO”request and the LABEL_FRAME_OFFSET global returns the sizes in Paper Size – mm, so it should be converted into model size by using the GLOB_SCALE global variable. If the textblock width is controlled by the user (LABEL_TEXT_WRAP = ON) then the fill polygon’s width should be calculated from that parameter (labelWidth).

! Get the sizes of the textblock in Paper Size - mm
r = REQUEST ("TEXTBLOCK_INFO", "mySampleBlock", _blockWidth_mm, _blockHeight_mm)
! Frame offset from AC Global
_frameOffset 	= LABEL_FRAME_OFFSET * GLOB_SCALE / 1000
	! Textblock width given by the user
	_blockWidth	= labelWidth * GLOB_SCALE / 1000
	! Textblock width from "TEXTBLOCK_INFO" request
	_blockWidth	= _blockWidth_mm * GLOB_SCALE / 1000	
! Textblock height from "TEXTBLOCK_INFO" request
_blockHeight	= _blockHeight_mm * GLOB_SCALE / 1000

! Set fill depending on the value of the Opaque Pen
define solid_fill "labelSolidFill"	! Solid Fill for the Background
define empty_fill "labelEmptyFill"	! Empty Fill for transparent Background

EPS = 0.0001
	fill "labelSolidFill"
	fill "labelEmptyFill"		! if the pen value is 0 (Transparent) or 
					! -1 (Window Background)

! Draw fill using the Frame, Frame Offset and the Opaque Pen
! Draw contour if Arrow checkbox unchecked, Frame checked
poly2_b 5, 2 + 4 + (LABEL_FRAME_ON & LABEL_CUSTOM_ARROW),
    -_frameOffset, 		    _blockHeight / 2 + _frameOffset,   1,
    _blockWidth + _frameOffset,     _blockHeight / 2 + _frameOffset,   1,
    _blockWidth + _frameOffset,     - _blockHeight / 2 - _frameOffset, 1,
    -_frameOffset,		    - _blockHeight / 2 - _frameOffset, 1,
    -_frameOffset, 		    _blockHeight / 2 + _frameOffset,   -1