• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Import some variables

New Here ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

Hi All,

I like to import only some variables from an old FM template file to a new one.
The SimpleImport function is not accurate as all variables of the source old FM template file will be imported.

With this function, no filters may be set to define which variables must be imported or not.

I am able to get TextRange string of a source variable but do not find any solution to copy it as TextRange value of the same variable (var.VarFmt.Name) in the new FM template file.

Is it possible to copy an applicable variable definition between two files with FM scripting?
What is(are) the function(s) to use?

JM

TOPICS
Scripting

Views

744

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Oct 16, 2018 Oct 16, 2018

Hi JM,

It's probably more simple than you might have guessed. Here is a function that transfers the properties of a single variable format to another document. Hope this helps.

Russ

function transferVarDef(fromDoc, toDoc, varName)

{

    //Get the source variable format, abort if it does not exist.

    var varFmt1 = fromDoc.GetNamedVarFmt(varName);

    if(!varFmt1.ObjectValid())

    {

        alert("Variable format \"" + varName + "\" does not exist in " +

            "the file " + fromDoc.Name);

        re

...

Votes

Translate

Translate
Mentor ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

Hi JM,

It's probably more simple than you might have guessed. Here is a function that transfers the properties of a single variable format to another document. Hope this helps.

Russ

function transferVarDef(fromDoc, toDoc, varName)

{

    //Get the source variable format, abort if it does not exist.

    var varFmt1 = fromDoc.GetNamedVarFmt(varName);

    if(!varFmt1.ObjectValid())

    {

        alert("Variable format \"" + varName + "\" does not exist in " +

            "the file " + fromDoc.Name);

        return;

    }

   

    //Get the corresponding format in the destination doc, creating it if it

    //does not exist.

    var varFmt2 = toDoc.GetNamedVarFmt(varName);

    if(!varFmt2.ObjectValid())

    {

        varFmt2 = toDoc.NewNamedObject(Constants.FO_VarFmt, varName);

    }

    //Set the destination format with the properties of the source format.

    varFmt2.SetProps(varFmt1.GetProps());

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

Thanks Russ,

I will try your solution and let you know if it works for both User and System variables.

JM

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

Klaus makes a good point about character formats. If a variable definition references a character format that does not exist in the target document, obviously that format would not be applied. It would be some work to add that check, then transfer the desired formats along with the variable definition. Likely, though, your templates are the same and this should not be an issue. If it is, you can transfer a character format by a very similar process.

Russ

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

But ChrFmts are not the end. What about e.g. colors nested to the ChrFmts.?

Do they exist?

If they exist: is their definition is identical or do they differ?

So I hope, your templates are the same........

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

If a character format doesn't exist in the target document, you won't actually "lose" it when you run Russ's code; it will still appear in the variable definition and you will see the reference to it when you insert the variable. Once you import Character formats from your template, the variables will be "fixed".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

Are you just concerned with User Variables or System Variables or both?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

But you have to take care about charfmts that might be found in some variables.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 22, 2018 Oct 22, 2018

Copy link to clipboard

Copied

LATEST

Thanks Russ,

I have tested your solution that works fine for User and System variables.

Those variable definitions have no CharFmt nor color differences between old and new FM template files.
I will take other suggestions about these parameters if such differences will be included in new versions of FM templates.

JM

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines