Jump to content
Developer Wiki and Function Reference Links ×

FSActlayer and a simple script


Recommended Posts

Hello all,

 

I am Trying to write a few basic scripts just to get a feel for the vectorscript language.

and the documentation has a list of all the functions but is not great at explaining how to use them.

 

I am trying to access information about a selected object.

which i believe is used with the 

vs.FSActlayer function.  I realize that returns a handle from a select item that I should store in a var or const

 

but I feel like i should be able to do something like FSActlayer.textsize or FSActlayer.position  it that makes sense.

 

basically I am just trying to write a script that increments text size up or down 1.

 

I can make a really short script to set the text size to a certain number

 

 

 

foo = vs.FSActLayer();

 

vs.SetTextSize(foo, 0, 100, 96)  

------------------------------------------------

but is there a way to do something like this

 

vs.SetTextSize(foo, 0, 100, foo + 1)

 

Anyway I appreciate any help at all!

 

Thanks,

Anthony

 

 

 

Link to comment

I believe @anthonydcobb is looking for a way to loop through a list of selected text objects to increase or decrease their sizes.

 

In Pascal you can use a for, while, or repeat/until loop, or you can use one of the built-in functions in the ForEachObject function family (there are 5). Here are three examples that essentially do the same thing:

 

This one uses a while loop.

PROCEDURE xxx;
{ Increase the text size of all selected text objects on the active layer by 1 point. }
{ Assumes all characters in a text block have uniform size. }
{ Uses a WHILE loop to examine the list of selected objects. }

CONST
	TextSzInc = 1;
VAR
	H :Handle;
BEGIN
	H := FSActLayer;
	while (H <> nil) do begin
		if (GetTypeN(H) = 10) then		{ 10 is object type for TEXT objects. }
			SetTextSize(H, 0, GetTextLength(H), GetTextSize(H, 0)+TextSzInc);
		H := NextSObj(H);
	end;
	SysBeep;
END;
Run(xxx);

 

This one uses ForEachObjectInList().

PROCEDURE yyy;
{ Decrement the text size of all selected text objects on the active layer by 1 point. }
{ Assumes all characters in a text block have uniform size. }
{ Uses ForEachObjectInList to control the loop. Only looks at Selected objects, and does not enter Groups. }

CONST
	TextSzInc = -1;
	
	function IncPtSz(H :Handle) :Boolean;
	Begin
		if (GetTypeN(H) = 10) then
			SetTextSize(H, 0, GetTextLength(H), GetTextSize(H, 0)+TextSzInc);
	End;	{ IncPtSz }
	
BEGIN
	ForEachObjectInList(IncPtSz, 2, 0, FSActLayer);		{ 2 = Selected objects, 0 = Shallow }
	SysBeep;
END;
Run(yyy);

 

 

And lastly, this one uses ForEachObject(), which is a CRITERIA based call.

PROCEDURE zzz;
{ Increment the text size of all selected text objects on the active layer by 2 points. }
{ Assumes all characters in a text block have uniform size. }
{ Uses ForEachObject() to control the loop, which filters objects by <criteria>. }
  
CONST
	TextSzInc = 2;
	
	procedure IncPtSz(H :Handle);
	Begin
		SetTextSize(H, 0, GetTextLength(H), GetTextSize(H, 0)+TextSzInc);
	End;	{ IncPtSz }
	
BEGIN
	ForEachObject(IncPtSz, Sel & (T=Text));		{ where "Text" = 10 }
	SysBeep;
END;
Run(zzz);

 

You can Pythonize these pascal scripts as is and they will work, or you can use more conventional ways of building a python list of selected text handles and iterate over that list. I will let you decide which way to go. Hopefully this will get you started.

 

Raymond

 

 

Edited by MullinRJ
Added SEL criterion to third example, to make functionality the same in all example scripts.
  • Like 3
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...