Skip to main content
Braniac
June 23, 2025
Question

Issue with setting createPrimaryTextFrame in a documentpreset

  • June 23, 2025
  • 3 replies
  • 1014 views

Hi All,

I am not able to reliably set createPrimaryTextFrame in a document preset. I tried the following code to test and the results show it not being able to set the value more often than not. Is this a bug or am I doing something wrong

var p = false
for (var i = 0; i < 5; i++){
    var dp = app.documentPresets.itemByName("MJ")
    if (!dp.isValid)
        dp = app.documentPresets.add("MJ")

    dp.createPrimaryTextFrame = p
    $.writeln("Value to set " + p + " Value set " + dp.createPrimaryTextFrame)
    p = !p
}

-Manan

3 replies

Braniac
June 24, 2025

So do you mean to say that once the preset is created we can't change the createPrimaryTextFrame attribute value?

 

That's the thing with creation properties. You can't change them once they exist. There's a hack to change a primary frame to a non-primary one: type any character in it then remove that character. I'm not aware of a hack to change a frame to a primary one.

Braniac
June 24, 2025

Ok, that makes sense but I am still not able to explain why creation of presets fail to set the property correctly in the preset.

-Manan

Braniac
June 24, 2025

The problem seems to be that when you create a document preset by script, createPrimaryTextFrame is always set to true. Create a preset manually and apply it to a document when the document is created it works fine.

rob day
Braniac
June 23, 2025

Hi @Manan Joshi , Also, it isn’t throwing an error, but your add("MJ") needs to be add({name:"MJ") if you want the preset to be named MJ. Try this:

 
var p = false
for (var i = 0; i < 5; i++){
    var dp = app.documentPresets.itemByName("MJ")
    if (!dp.isValid)
        dp = app.documentPresets.add({name:"MJ"})

    dp.createPrimaryTextFrame = p
    $.writeln("Value to set " + p + " Value set " + dp.createPrimaryTextFrame + " Preset Name " + dp.name);

    /* returns: 
    Value to set false Value set false Preset Name MJ
    Value to set true Value set false Preset Name MJ
    Value to set false Value set false Preset Name MJ
    Value to set true Value set false Preset Name MJ
    Value to set false Value set false Preset Name MJ */

    p = !p
}
Braniac
June 23, 2025

Thanks for pointing that out @rob day that was a typo as I was checking the preset in the UI. With your code I get the following results

Value to set false Value set false Preset Name MJ
Value to set true Value set false Preset Name MJ
Value to set false Value set false Preset Name MJ
Value to set true Value set false Preset Name MJ
Value to set false Value set false Preset Name MJ
-Manan
rob day
Braniac
June 23, 2025

Yes that’s what I would expect. If you want 5 presets they would each have to have unique names

Braniac
June 23, 2025

primaryTextFrame is a creation property, you have to do it when you create the document. Something along these lines:

 

app.documents.add ({
  documentPreferences: {
    createPrimaryTextFrame: true,
    // Any other properties
  }
});
Braniac
June 23, 2025

Hi @Peter Kahrel,

Won't this argument need a document preset object. What I had done originally was create a new document preset and adding this property of primary frame into it. Then used the created document preset to create a new document. But the results this were not consistent.

-Manan