Copy link to clipboard
Copied
I think the below info is correct. Let's say my user variable is named "_DocType". I can read and write and check the existence of the variable like this:
var doc = app.ActiveDoc;
// Check Exists
var varFmt = doc.GetNamedObject (Constants.FO_VarFmt, "_DocType");
if(varFmt.ObjectValid()){
alert("Variable _DocType exists!")
}
// Write Variable - as "User Guide":
var varFmt = doc.GetNamedVarFmt ("_DocType");
varFmt.Fmt = "User Guide";
// Read Variable
var varFmt = doc.GetNamedObject (Constants.FO_VarFmt, "_DocType");
alert (varFmt.Fmt);
However, I'm not sure how to create the variable if it doesn't exist yet.
Thanks in advance!
I use something like this:
function getVarFmt (name, definition, doc) {
var varFmt;
varFmt = doc.GetNamedVarFmt (name);
if (varFmt.ObjectValid () === 0) {
varFmt = doc.NewNamedVarFmt (name);
varFmt.Fmt = definition;
}
return varFmt;
}
Note that if the variable format current exists, then the "definition" parameter isn't used.
Copy link to clipboard
Copied
I use something like this:
function getVarFmt (name, definition, doc) {
var varFmt;
varFmt = doc.GetNamedVarFmt (name);
if (varFmt.ObjectValid () === 0) {
varFmt = doc.NewNamedVarFmt (name);
varFmt.Fmt = definition;
}
return varFmt;
}
Note that if the variable format current exists, then the "definition" parameter isn't used.
Copy link to clipboard
Copied
Works perfectly (as expected) - Thanks again!