将 InDesign ScriptUI 选项保存在文件中并在下次运行时加载 [英] save InDesign ScriptUI options in file and load in the next run

查看:35
本文介绍了将 InDesign ScriptUI 选项保存在文件中并在下次运行时加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 InDesign 脚本中构建了一个具有任何选项的对话框.

我想将用户选择的设置保存在一个文件中(例如在名为 setting.ini 的文件中),以便在下次运行时不需要重新调整,并为对话框启用相同的设置.

有这种可能吗?

解决方案

是的,您可以使用标签功能将任何信息保存到任何 InDesign 对象.要保存您希望在下次运行脚本时访问的对话框中的内容,最有意义的是将信息直接保存到应用程序对象中,这样即使在关闭并重新启动 InDesign(如与将其保存到下次用户使用脚本时可能不会打开的文档中相反).

一般的工作流程是这样的:

//在用户关闭对话框后,将他们所做的设置保存到一个对象变量用户选择 = {//保存对话框中的任何信息,例如一些关于下划线的设置下划线:checkbox3.value,下划线重量:edittext6.text,下划线偏移量:edittext7.text,//等等. ...};//将给定的信息插入到脚本标签中,选择任意名称//过程中使用.toSource()对对象进行字符串化,labels只能保存字符串app.insertLabel(ha_a_usersettings", userChoice.toSource());

现在信息保存在应用程序本身中.下次运行脚本时,您可以像这样从标签中检索信息:

var savedSettings = eval(app.extractLabel("ha_a_usersettings"));

现在,您可以继续并使用 savedSettings 变量中的属性预填充对话框.

I built a Dialog in InDesign script that has any options.

I want to save the settings the user selects in a file (For example in a file named setting.ini) to do not require a re-adjustment in the next run and the same settings are enabled for the Dialog.

Is there such a possibility?

解决方案

Yes, you can use the label functionality to save any information to any InDesign objects. To save things from dialogs that you want to access the next time that a script is run, it would make most sense to save the info into the app object directly, that way it will be available even after closing and re-starting InDesign (as opposed to saving it into a Document which might not be open the next time the users uses the script).

The general workflow would be something like this:

// after the user closes the dialog, save the settings they made to an object
var userChoice = {
  // save any info from the dialog, for example some settings about underlines
  underline: checkbox3.value,
  underlineWeight: edittext6.text,
  underlineOffset: edittext7.text,

  // etc. ...
};

// insert the given information into a script label, pick any arbitrary name
// use .toSource() to stringify the object in the process, labels can only save strings

app.insertLabel("ha_a_usersettings", userChoice.toSource());

Now the info is saved in the app itself. Next time you run the script, you can retrieve the information from the label like this:

var savedSettings = eval(app.extractLabel("ha_a_usersettings"));

Now you can proceed and pre-populate the dialog with the properties you have in the savedSettings variable.

这篇关于将 InDesign ScriptUI 选项保存在文件中并在下次运行时加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆