This really belongs in the scripting section.
Anyway, the reason that using item['Path'] doesn't work is because 'TextTarget' is a relative path. So it's a list of how to get to the text from your current location. I realize that's stupid and makes absolutely no sense. But it is what it is.
So, what you have to do is first, select the bottom layer since all layer and object paths are relative to the bottom layer. Then you have to select the layer where your text object is a child. Finally you set the path 'TextTarget" path to the child that represents the text.
This seemed to work well for me. I even used Layer Groups and vector groups and it seemed to function just fine.
So the first change I made is at the start of each new item in the loop I select the bottom most layer using the path (9999, -9999, [], False). After we prove that the object is a text object I use the first two path parameters to select the layer where the text object exists. Path = (item['Path'][0], item['Path'][1], [], False)
Then I set the item['TextTarget'] = (0,0, item['Path'][2], True)
This will traverse only the children of the currently selected layer. This includes entering layer groups, and vector groups.
These three changes are all you need to get this script to work as you like. This script could also make a neat "CopyFormatting" option. Where the first object in the selection is the template and all other text objects selected get changed to match its parameters. Excellent script idea.
Code: Select all
def Do(Environment):
# EnableOptimizedScriptUndo
App.Do( Environment, 'EnableOptimizedScriptUndo', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((16,0,0),1)
}
})
# Clear script output window
App.Do( Environment, 'ScriptWndClear')
# Get list of selected vector objects
SelectedText = App.Do( Environment, 'ReturnVectorObjectProperties' )
if SelectedText['ListOfObjects'] == None:
print 'No text is selected...'
return
# Ask user for font size
UserSize = App.Do( Environment, 'GetNumber', {
'DefaultValue': 12,
'MinValue': 6,
'MaxValue': 90,
'DialogTitle': 'Font Size',
'GetInteger': App.Constants.Boolean.true,
'LogarithmicSlider': App.Constants.Boolean.false,
'Prompt': 'Enter font point size (6 to 90)',
'GeneralSettings': {'ExecutionMode': App.Constants.ExecutionMode.Interactive}})
if UserSize['OKButton']:
# loop through selected text list
for item in SelectedText['ListOfObjects']:
App.Do( Environment, 'SelectLayer', {'Path': (9999, -9999, [], False)})
# read the text data
txt = item['TextExData']
# only text data allowed
if txt == None:
continue
App.Do( Environment, 'SelectLayer', {'Path': (item['Path'][0],item['Path'][1], [], False)})
# change the font point size
txt['PointSize'] = UserSize['EnteredNumber']
txt['Font'] = 'Lato Medium'
txt['AntialiasStyle'] = App.Constants.AntialiasEx.Smooth
#Set text path to object we're changing
txt['TextTarget'] = (0, 0, item['Path'][2], True)
txt['PathTarget'] = None
# update the text
App.Do( Environment, 'TextEx', txt )
print 'Done...'