Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
}
});
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
> 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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
> 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.
Copy link to clipboard
Copied
This is a new learning for me @Peter Kahrel thanks for the tip
-Manan
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Yes that’s what I would expect. If you want 5 presets they would each have to have unique names
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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});
}
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
> 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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
True. Unfortunately that goes for quite a few APIs.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now