I'm experimenting with a script that can add guides, and then separately, remove one of them. The upper half of the script is just a dialog with some variable names, particularly an editable text field.
Then there's a for-loop drawing several guides, followed by an event handler function and then the event handler itself.
I get an alert when I change the text field so this assures me the event handler function is successfully called, but for some reason, I have no idea why, the guide doesn't get removed. Can anyone fix this?
Hi @dane13860245, you cannot make changes to the DOM while a modal dialog is active. The error is:
Here is one approach to get you moving forward. I'm pretty sure it isn't the best way, because it re-creates the dialog each time, rather than re-using the existing dialog. I would like to see a neater way, if you come up with it. The crux is that everytime you click the Apply button it closes, then *does stuff*, then re-creates the dialog with the new values (you must keep the settings object up-to-date).
Anyway, here it is:
See what you think.
Thank you mb, I will give this a try and see what I can do.
So okay, you can't "delete" guides in a dialog, for whatever reason. But, can you HIDE guides instead? If so, then I might render all possible guides, and then reveal them gradually as desired in an event listener, if that's possible.
Also, what is "DOM"?
You can easily find definition in Google - Document Object Model.
Here is one for InDesign:
Here's code very similar to yours except at the bottom, I've reinstated the event handler function to do something. What I intend it to do is to "hide" a guide that has already been made earlier on, though it doesn't work.
Shouldn't "Blah3" here:
be in ""?
Hi @dane13860245, the DOM in this case is the Indesign Document Object Model, meaning any objects belonging to the Indesign app, as opposed to ExtendScript itself. You can do whatever you want in ExtendScript when a scriptUI dialog is open, but you can't do anything that changes the document. So you cannot change the visibility of a guide while the dialog is open. Also, more importantly, there doesn't seem to be any way to hide a single guide. There's nothing I could see in the api for Guide except maybe a workaround: guideColor. You could "hide" a guide by coloring it the same color as the paper:
// just an example guide var guide = app.activeDocument.guides; // this stops the guide being visible into the pasteboard guide.fitToPage = true; // make this match your paper guide.guideColor = [255, 255, 255];
However you must do it in part of the code *after* the dialog is closed. See my while loop for example. It cannot be done in the eventListener as you wrote.
If you really need the document to update while the user is editing the dialog values, you might need to use a "palette" instead of a "dialog". I'm not very familiar with those, and they are more tricky to set up, but I'm pretty sure they can be made to do what you want.
P.S. You can post code with the </> button in the forum editor.