Jump to content
Developer Wiki and Function Reference Links ×

SetTextStyleRef


Recommended Posts

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);

 

Link to comment

🙂.  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?

Link to comment

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');

 

??

Link to comment

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 by MullinRJ
Link to comment

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!!!!!

Link to comment
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.

Link to comment
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.

Link to comment
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

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...