BIM Coordinator Program (INT) April 22, 2024

Find the next step in your career as a Graphisoft Certified BIM Coordinator!

GDL
About building parametric objects with GDL.

[SOLVED] String length to pixel length? Like STW() in GDL

Erenford
Booster
Hello,
Is there a DG function that computes for the length of the string in pixels? Something equivalent of STW(string) in GDL.
I'm trying to make a button that have a width according to its text. I could base it on the widest char like 'W' but it would be too wide for something like char 'i'.

Thanks.
Archicad 25 5010 INT FULL
Archicad 26 5002 INT FULL
Visual Studio Professional 2019
Win 10 Pro 64-bit
2 REPLIES 2
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi Erenford,

You should use APIAny_GetTextLineLengthID goodie function for this.
Example code:
double	DetermineTextWidth (const char* str, short font, double size) 
{ 
	if (strlen (str) == 0) 
		return (0); 
 
	API_TextLinePars	tlp; 
	double				width = 0.0; 
 
	BNZeroMemory (&tlp, sizeof (API_TextLinePars)); 
	tlp.drvScaleCorr = true;	// Apply drawing scale... 
	tlp.index = 0;				// Get the length of the longest line (there may be only one line...) 
	tlp.lineStr = const_cast<char*> (str); 
	tlp.wFace = APIFace_Plain; 
	tlp.wFont = font; 
	tlp.wSize = size; 
	tlp.wSlant = PI / 2.0;		// Plain text 
	ACAPI_Goodies (APIAny_GetTextLineLengthID, &tlp, &width); 
	return (width); 
}


Regards,
Tibor
Erenford
Booster
oooh so there is one!

So for dialog box with default settings, I'm guessing no drawing style, with size 12. I'm not sure what the default font is so I just set 'wFont' to 1.

Seems it's working fine!
Thanks Tibor.
Archicad 25 5010 INT FULL
Archicad 26 5002 INT FULL
Visual Studio Professional 2019
Win 10 Pro 64-bit
Learn and get certified!