anthonydcobb Posted March 24, 2022 Share Posted March 24, 2022 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 Quote Link to comment
michaelk Posted March 24, 2022 Share Posted March 24, 2022 I would do something like this: foo = vs.FSActLayer(); txtSize = vs.GetTextSize(foo,0,); vs.SetTextSize(foo,0,100,txtSize +1); 3 Quote Link to comment
Pat Stanford Posted March 25, 2022 Share Posted March 25, 2022 Vectorscript (and Pythonscript) are procedural languages, not object oriented languages. You need to grab the data into a variable(s), calculate what you want to be different, and then store it back into the object. Very much like Michael has done above. 1 Quote Link to comment
MullinRJ Posted March 25, 2022 Share Posted March 25, 2022 (edited) 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 March 25, 2022 by MullinRJ Added SEL criterion to third example, to make functionality the same in all example scripts. 3 Quote Link to comment
anthonydcobb Posted March 25, 2022 Author Share Posted March 25, 2022 wow you all are awesome thank you so much! Quote Link to comment
MullinRJ Posted March 25, 2022 Share Posted March 25, 2022 I just modified the third script above so that it only acts on selected text blocks. I changed <T=Text> to <Sel & (T=Text)>. Now the three scripts should be functionally equivalent. A little sleep does wonders to clear the brain. Raymond Quote Link to comment
Recommended Posts
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.