Copy link to clipboard
Copied
Hello
Is there any options to set snap to document grid off via javascript?
The code from manual doesn't work
with(myDocument.gridPreferences){
documentGridShown = false;
documentGridSnapTo = false;
baselineGridShown = false;
}
Thanks
Yeh ok - makes sense because it just toggles it
try this
var snapToGridAction = app.menuActions.itemByName("$ID/Snap to Document Grid");
// Check if Snap to Grid is currently ON before toggling
if (snapToGridAction.isValid && snapToGridAction.enabled && snapToGridAction.checked) {
snapToGridAction.invoke();
}
This one works:
app.documents[0].gridPreferences.documentGridSnapto = true;
Copy link to clipboard
Copied
It's possible other settings like 'Snap to Guides' or 'Smart Guides' are influencing object placement.
So something like this maybe work for you
var myDocument = app.activeDocument;
myDocument.guidePreferences.guidesLocked = false;
myDocument.guidePreferences.guidesShown = false;
app.activeWindow.transformReferencePoint = AnchorPoint.TOP_LEFT_ANCHOR;
You can invoke Document Grid Snap via the menus which turns it on
// Access the 'Snap to Document Grid' menu action
var snapToGridAction = app.menuActions.itemByName("$ID/Snap to Document Grid");
// Check if the action is valid and enabled
if (snapToGridAction.isValid && snapToGridAction.enabled) {
// Invoke the action to toggle the snapping
snapToGridAction.invoke();
} else {
alert("The 'Snap to Document Grid' action is not available.");
}
Copy link to clipboard
Copied
Thanks a lot. This option worked.
var snapToGridAction = app.menuActions.itemByName("$ID/Snap to Document Grid");
if (snapToGridAction.enabled) {
snapToGridAction.invoke(); }
Copy link to clipboard
Copied
There is just one problem, for some reason when the setting is turned off, the opposite happens - snap to grid turned on.
Copy link to clipboard
Copied
Yeh ok - makes sense because it just toggles it
try this
var snapToGridAction = app.menuActions.itemByName("$ID/Snap to Document Grid");
// Check if Snap to Grid is currently ON before toggling
if (snapToGridAction.isValid && snapToGridAction.enabled && snapToGridAction.checked) {
snapToGridAction.invoke();
}
Copy link to clipboard
Copied
Thank you very much, it works
Copy link to clipboard
Copied
This one works:
app.documents[0].gridPreferences.documentGridSnapto = true;
Copy link to clipboard
Copied
Thank you very much, it works too
Copy link to clipboard
Copied