cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Developer forum
GDL coding questions, Python and add-on development using the API Dev Kit.

Efficient way to crop text by length in cm

Anonymous
Not applicable
Hi,

i hope I haven’t missed a function, but I’m looking for a efficient way to crop text by a given length and not by the number of characters, like “strsub”.

Maybe somebody have a better solution.
My actual solution is:

while stw(txt1) >100 do !** 100 is the max lenght of the text
txt1=strsub(txt1,0,_loop)
_loop=_loop-1
endwhile
10 REPLIES 10

Joachim Suehlo
Advisor
With Richtext2 this should work.
Drag and drop a multine 2D Text into a 2D Script window
and define Parameters for Text content and text length and replace the
hard coded values by the parameters in the script.
Joachim Suehlo . AC12-26 . MAC OSX 10.15 . WIN10

Anonymous
Not applicable
Hi Joachim,

i think with Richtext2 i only have the option to get a linebreak after the given lenght, so that i get a new line when the text didn't fit, what i want to avoid.

Barry Kelly
Moderator
So just to be clear.
You don't want the text to wrap to a new line.
You just want to cut the text off at a certain width and not after a certain number of characters?

Barry.

One of the forum moderators.
Versions 6.5 to 25
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Dell Precision 3510 - i7 6820HQ @ 2.70GHz, 16GB RAM, AMD FirePro W5130M, Windows 10

Anonymous
Not applicable
Yes exactly

runxel
Virtuoso
Not really sure why that would be useful, but it's certainly an edge case. There is no built-in function for that.

What you've done there is already quite good.
The only way there might be to improve the execution time, would be some kind of "divide & conquer" algorithm.
Mostly AC 26 on Mac | Author of SelfGDL | Developer of the GDL plugin for Sublime Text |
«Furthermore, I consider that Carth... yearly releases must be destroyed»

Anonymous
Not applicable
You're right, an edge case, that's why i haven't asked some years ago.

F.E. when you have an object, which shows the change history of an layout, like the Graphisoft Object already does. The content of the name is limited to 255 char., when you want to limit the column width you have to use linebreaks, which may cause to many lines.

runxel
Virtuoso
Okay, this might be an legitimate example, which I can totally understand.
Still an edge case, tho.

Also: Would you really want to split a word at an arbitrary position?
This will look weird to anybody who reads it, for sure.
I guess you're the BIM manager of your office (or a similar position). Maybe you can introduce a special char as a delimiter (like ";") in your office. And everything after that char gets cut off.
Or you just split by space (" "). This might be the easiest and best looking solution. It will also perform slightly faster than looping through every character, I assume.
Maybe even leave enough room for an ellipsis ("…") to append to the string, so it doesn't look as bad.
Mostly AC 26 on Mac | Author of SelfGDL | Developer of the GDL plugin for Sublime Text |
«Furthermore, I consider that Carth... yearly releases must be destroyed»

Anonymous
Not applicable
The idea was, to have it as option. Maybe sometimes it's better to crop one name of a change, than to push others out of the table. You're idea with the ellipsis is nice.

I've started in investigate, if a simplified object for the change management makes sense.

I'm no a BIM Manager, i'm ArchiCAD Trainer, Consultat, Instructor at Graphisoft Berlin.
Maybe i should revise my signature

runxel
Virtuoso
Hello there fellow Berliner!
FST_Berlin wrote:
I've started in investigate, if a simplified object for the change management makes sense.
Ah, like... for distribution in the D(ACH) space with the next release?

Offtopic:
Archicad 4-40
Well I certainly got the joke
Mostly AC 26 on Mac | Author of SelfGDL | Developer of the GDL plugin for Sublime Text |
«Furthermore, I consider that Carth... yearly releases must be destroyed»

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!