Jump to content
Developer Wiki and Function Reference Links ×

Splitting a single text object into multiple text objects


Recommended Posts

I normally write my labels as a single text file (each label as a single paragraph), drag it into VW and then copy and paste out of it into single labels [I have no need or use for the call out system as it's not fit for my purpose]. Then I just drag them into position and I'm done.

 

Is there a script (or Marionette) that will break a single text block into multiple text blocks based on eg carriage returns or space between paragraphs?

Link to comment

Hello @unearthed,

   I thought you would have had an answer by now. Since that didn't happen, I cobbled together a script that will split lines into text blocks. It could have more refinements, but I assume that is not necessary. Let me know if this works for you. And if you want the original text block to disappear after it is split, uncomment line 46 near the bottom. (See comments.) 

 

PROCEDURE SplitTextToLines;
{ Split selected text block into individual lines at each Carriage Return. Each line becomes its own text block. }
{ Original text block gets deleted if user uncomments the DelObject() line at the end of the script. }
{ 06 Mar 2023 - Raymond J Mullin }
{ NO WARRANTY EXPRESSED OR IMPLIED. }
{ USE AT YOUR OWN RISK. USE ON A COPY OF YOUR DATA FIRST. }
CONST
	CR = chr(13);
VAR
	H :Handle;
	Mirrored :Boolean;
	X, Y, Ang, LineSpc :Real;
	S, T :Dynarray of Char;
BEGIN
	PushAttrs;

	H := FSActLayer;

	{ create new text with these attributes. }
	TextVerticalAlign(2);			{ top baseline }
	TextJust(1);				{ left justified }
	TextSize(GetTextSize(H, 0));
	
	{ get the text, its insertion point, and the line spacing }
	S := GetText(H);
	GetTextOrientation(H, X, Y, Ang, Mirrored);
	LineSpc := GetTextSize(H, 0)/72;	{ approximate }
	
	{ make sure text ends with a carriage return. }
	if (S[len(S)] <> CR) then
		S := concat(S, CR);
		
	{ split lines here }
	while (len(S) > 0) do begin
		T := copy(S, 1, pos(CR, S)-1);
		delete(S, 1, pos(CR, S));

		if (len(T) > 0) then begin
			MoveTo(X, Y);
			CreateText(T);
		end;
		Y := Y - LineSpc;
	end;		{ while }
	
	{ **** Uncomment following line if you wish to delete the original text when done. **** }
	{DelObject(H); }
	
	PopAttrs;
	SysBeep;
END;
Run(SplitTextToLines);

 

Raymond

  • Like 2
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...