Jump to content

"Text Style" Object Type integer


Recommended Posts

Ok, Follow up question.  Does anyone know how to set the Document Text Style preference for future text objects to be a particular text style via script?

and 

How to move text styles into a Text Style folder via script?

Edited by The Hamma
Link to comment
20 hours ago, Peter Vandewalle said:

Move a resource to a folder: I think SetParent()…

Perfect, Thanks.  

 

Here is a script to import two Text Styles into the current drawing that are stored in: 

     {Workgroup folder or user folder}\Libraries\Defaults\Text Styles\Text Styles.vwx'

 

 

"""
Script to import two text styles into current drawing.  Custom scripts can be added to:
{Workgroup folder or user folder}\Libraries\Defaults\Text Styles\Text Styles.vwx

Modify Style1 or Style2 to import your custom style

This Python Script may be freely distributed. No warranty provided.
Use at your own risk.

David Hamer, 2021 revision 10/21/2021
"""


Style1 = 'Callouts 10 pt' #change this to import different text style
Style2 = 'Dimensions 10 pt' #change this to import different text style
StyleFolder = 'Text Styles' #Name of resource folder to create in current drawing
SourceSub = 'Defaults:Text Styles' #Sub path
ResType =109 #Text Style type
folderIndex =13 #Libraries 

if vs.GetName(Style1) != []:
	ResourceList, NumItems = vs.BuildResourceList(ResType, folderIndex, SourceSub) 
	while NumItems != 0:
		ResourceName = vs.GetNameFromResourceList(ResourceList, NumItems)
		if ResourceName == Style1:
			vs.ImportResourceToCurrentFile(ResourceList,NumItems)
			if vs.GetObject(StyleFolder) == []:
				vs.NameObject(StyleFolder)
				vs.BeginFolderN(ResType)
				vs.EndFolder()
			vs.SetParent(vs.GetObject(Style1),vs.GetObject(StyleFolder))
		NumItems -= 1

if vs.GetName(Style2) != []:
	ResourceList, NumItems = vs.BuildResourceList(ResType, folderIndex, SourceSub) 
	while NumItems != 0:
		ResourceName = vs.GetNameFromResourceList(ResourceList, NumItems) 
		if ResourceName == Style2:
			vs.ImportResourceToCurrentFile(ResourceList,NumItems)
			if vs.GetObject(StyleFolder) == []:
				vs.NameObject(StyleFolder)
				vs.BeginFolderN(ResType)
				vs.EndFolder()
			vs.SetParent(vs.GetObject(Style2),vs.GetObject(StyleFolder))
		NumItems -= 1

 

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