michaelk Posted May 1, 2020 Share Posted May 1, 2020 Assume a world where there exists a Vectorworks file containing at least two Text Styles in it's resource manager. Run this script. Why aren't the text objects styled by the first and second text styles in the resource manager? Procedure Test; VAR h : HANDLE; s : STRING; BEGIN MoveTo(0",4"); BeginText; 'This should be Text Style 1' EndText; SetTextStyleRef(LNewObj,1); MoveTo(0",-4"); BeginText; 'It would be great if this was Text Style 2' EndText; SetTextStyleRef(LNewObj,2); END; RUN(Test); Quote Link to comment
JBenghiat Posted May 1, 2020 Share Posted May 1, 2020 I believe this is looking for the object index. Try using Name2Index Quote Link to comment
michaelk Posted May 1, 2020 Author Share Posted May 1, 2020 🙂. I tried that. It didn't work either. Then in desperation, I made a file with exactly two Text Styles and used 1 and 2 for the index values. Just now occurring to me: Are the first and only two Text Styles not guaranteed to be index 1 and 2? Quote Link to comment
Pat Stanford Posted May 1, 2020 Share Posted May 1, 2020 No, I don't think the indexes are ever guaranteed to be anything. There is only one Name2Index command which makes me think that the indexes for all the different object types are likely intermeshed. It did not work when you used SetTextStyleRef(LNewObj,Name2Index('This_Is_Name_Of_First_Text_Style'); ?? Quote Link to comment
michaelk Posted May 1, 2020 Author Share Posted May 1, 2020 Hmpf. Last night it didn't work. Today it does! TGIF Quote Link to comment
MullinRJ Posted May 1, 2020 Share Posted May 1, 2020 (edited) Michael, The names of the text styles are kept in the Name List, which is a list of all the unique names in the document, except the layer names. Like class names, object games, script names, their index number reflects their position in that list. Name2Index() returns the number associated with a name in that list, and can be expected to be different in every file. HTH, Raymond Edited May 1, 2020 by MullinRJ Quote Link to comment
Pat Stanford Posted May 1, 2020 Share Posted May 1, 2020 Just for ducks, what is the actual number Name2Index returns? My guess is it is probably something like a handle. Quote Link to comment
michaelk Posted May 1, 2020 Author Share Posted May 1, 2020 Hi Ray and Pat I was starting with a blank document so I hoped to have nothing in the name index. Didn't realize that classes counted. Just ran it, the second text style was index number 12. This is one of those tools I thought would be easy and I could knock out quickly. Ha!!!!! Quote Link to comment
JBenghiat Posted May 1, 2020 Share Posted May 1, 2020 1 minute ago, Pat Stanford said: Just for ducks, what is the actual number Name2Index returns? My guess is it is probably something like a handle. Picture an SQL-like table of all the unique names in the document that Raymond mentioned. The table has two fields, index and name. (I'm guessing at file-load, the handle gets added to the table as well.) Name2Index returns the numerical index assigned to each name. Looking up a value in the table by ID is much faster than by name. Quote Link to comment
michaelk Posted May 1, 2020 Author Share Posted May 1, 2020 Do the index values get added to as objects are created during the execution of a script? That would sure explain a lot of my evening last night. Quote Link to comment
JBenghiat Posted May 1, 2020 Share Posted May 1, 2020 16 minutes ago, michaelk said: Do the index values get added to as objects are created during the execution of a script? That would sure explain a lot of my evening last night. Yes — I'm not sure if the list includes every object or only named objects, but it is constantly getting updated. Like a handle, you should be able to rely on the index being consistent for the run of the script, assuming you don't delete or rename the item, but otherwise it's just an indexed list. Quote Link to comment
MullinRJ Posted May 1, 2020 Share Posted May 1, 2020 31 minutes ago, michaelk said: Do the index values get added to as objects are created during the execution of a script? The indices are assigned when new names are created, either manually, or when a script runs. When names are deleted they create a void in the list and the indices may be reassigned as new names are created. I would not try to predict the method. Just use Name2Index() to get the RefID of the TextStyle (or other named resource). It should be good until you delete that name or reopen the file. 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.