Skip to main content
Participant
November 16, 2017
Answered

Changing gridlines with extendscript

  • November 16, 2017
  • 1 reply
  • 735 views

I'd like to build a script that automatically adjusts the "Gridline every: ### pixels" preference based on the active comp's resolution. Yes I know about the proportional grid, but I like that the non-proportional grid has subdivisions so I prefer to use that. The issue I'm running into is that if I change the preference's value through extend script, it doesn't update in the comp viewer until I've opened and closed the preferences window. However, if I try to change the proportional grid's division, it updates in the comp viewer instantly. For whatever reason the preferences for the normal grid are in Adobe After Effects 14.0 Prefs-indep-general.txt, while the the preferences for the proportional grid are in Adobe After Effects 14.0 Prefs.txt, so I'm thinking that's probably the root of the problem. Anyone have any thoughts on what's causing this obstacle, and maybe a solution to fix it? Here's the code to change the preferences:

// Changes grid to every 64 pixels

app.preferences.savePrefAsString("Main Pref Section v2", "Pref_GRID_PIX_PER_DIV", "64.000000", PREFType.PREF_Type_MACHINE_INDEPENDENT);

// Changes proportional grid to 8 increments horizontally

app.preferences.savePrefAsString("Main Pref Section v2", "Pref_ANIMGRID_CELS_HORIZ", "8.000000");

This topic has been closed for replies.
Correct answer Tomas Sinkunas

You were right on your track, except one line of code is missing - you need to force to reload preferences:

app.preferences.reload();

So this should do the trick

var sectionName = "Main Pref Section v2";

var keyName = "Pref_GRID_PIX_PER_DIV";

var keyValue = "100.000000";

var prefsLocation = PREFType.PREF_Type_MACHINE_INDEPENDENT;

app.preferences.savePrefAsString(sectionName, keyName, keyValue, prefsLocation);

app.preferences.reload();

1 reply

Tomas Sinkunas
Tomas SinkunasCorrect answer
Legend
November 17, 2017

You were right on your track, except one line of code is missing - you need to force to reload preferences:

app.preferences.reload();

So this should do the trick

var sectionName = "Main Pref Section v2";

var keyName = "Pref_GRID_PIX_PER_DIV";

var keyValue = "100.000000";

var prefsLocation = PREFType.PREF_Type_MACHINE_INDEPENDENT;

app.preferences.savePrefAsString(sectionName, keyName, keyValue, prefsLocation);

app.preferences.reload();

Participant
November 17, 2017

Thanks Tomas, that's exactly what I was looking for!

How did you know about the reload() method? I can't find it in any of the ExtendScript documentation. Is it just a common method for JS-based languages?