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

Issue with setting createPrimaryTextFrame in a documentpreset

Community Expert ,
Jun 23, 2025 Jun 23, 2025

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

TOPICS
Scripting
879
Translate
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 ,
Jun 23, 2025 Jun 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
  }
});
Translate
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 ,
Jun 23, 2025 Jun 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

Translate
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 ,
Jun 23, 2025 Jun 23, 2025

Your code seems to be working fine for creating the document. I will have to test it more. However, for creation of document preset the following does not work either

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

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

So do we conclude that createPrimaryTextFrame can't be set into the documentPreset and has to be sent into the document add method as you mentioned? This is not right in my opinion because if this holds then I can never use a named document preset for document creation that need to have primary frame in addition to other properties. 

-Manan

Translate
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 ,
Jun 23, 2025 Jun 23, 2025

Hi @Peter Kahrel,

For creating the document with primary frame on/off only your code snippet works well. However, I am not sure how this code works. The add method definition is 

Document add ([showingWindow:Boolean=Boolean], documentPreset:DocumentPreset, withProperties:Object)

How is your code working when the 1st argument is to be a boolean? 

Secondly did you check my code snippet at https://community.adobe.com/t5/indesign-discussions/issue-with-setting-createprimarytextframe-in-a-d.... If the problem statement is to create multiple document preset it does not work reliably.

-Manan

Translate
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 ,
Jun 24, 2025 Jun 24, 2025

How is your code working when the 1st argument is to be a boolean? 

 

showingWindow and documentPreset are optional parameters. In my code there's just one parameter, withProperties:Object

Translate
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 ,
Jun 24, 2025 Jun 24, 2025

This is interesting because I always thought that in order to send an argument beyond the optional ones you were required to send the arguments preceding it. I may have to revisit my understanding on this one

-Manan

Translate
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 ,
Jun 24, 2025 Jun 24, 2025

> I always thought that in order to send an argument beyond the optional ones you were required to send the arguments preceding it.

 

That is correct. But apparently that doesn't go for {with properties}. So if you want to use a preset, you have to set showWindow. But {with properties}} can be used without showingWindow and documentPreset.

Translate
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 ,
Jun 26, 2025 Jun 26, 2025

This is a new learning for me @Peter Kahrel thanks for the tip

-Manan

Translate
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 ,
Jun 23, 2025 Jun 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
}
Translate
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 ,
Jun 23, 2025 Jun 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
Translate
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 ,
Jun 23, 2025 Jun 23, 2025

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

Translate
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 ,
Jun 23, 2025 Jun 23, 2025

So do you mean to say that once the preset is created we can't change the createPrimaryTextFrame attribute value? The original code that was troubling me was indeed failing where I was creating a new preset with a time stamp as the name. I will post that piece as well tomorrow.

-Manan

Translate
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 ,
Jun 23, 2025 Jun 23, 2025

Does this work for you?

 

var dp = makeDocPreset("MJ");
dp.properties = {columnCount:1, createPrimaryTextFrame:true}


/**
* Makes a new document preset 
* @ param preset name name 
* @ return the new preset 
*/

function makeDocPreset(n){
    if (app.documentPresets.itemByName(n).isValid) {
        return app.documentPresets.itemByName(n);
    } else {
        return app.documentPresets.add({name:n});
    }
}
Translate
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 ,
Jun 23, 2025 Jun 23, 2025

It did not work the first time I ran it and then it worked for other iterations. Also check out the code at https://community.adobe.com/t5/indesign-discussions/issue-with-setting-createprimarytextframe-in-a-d...

This piece never works for me. I get the following results

Value to set false Value set true
Value to set true Value set false
Value to set false Value set true
Value to set true Value set false
Value to set false Value set true
-Manan
Translate
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 ,
Jun 24, 2025 Jun 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.

Translate
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 ,
Jun 24, 2025 Jun 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

Translate
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 ,
Jun 24, 2025 Jun 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.

Translate
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 ,
Jun 26, 2025 Jun 26, 2025

Ok, thanks for the insight. But this is oddly designed. It seems as if this is some sort of half baked API implementation because from a scripters view point there seems no reason to have this implemented the way it is done currently

-Manan

Translate
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 ,
Jun 26, 2025 Jun 26, 2025
LATEST

True. Unfortunately that goes for quite a few APIs.

Translate
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