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

Undo Entire JSFL Tool Action In One Step?

Participant ,
Oct 09, 2025 Oct 09, 2025

Is it possible to undo an entire JSFL tool's script with just one press of CTRL + Z?

 

For example, the following JSFL tool script allows a user to click on a shape and smooth it by running Animate's smoothSelection() method several times. 

 

Each time the smoothSelection() method runs, an extra undo step is added to the history panel. So is there any way to reduce it to one step while keeping the same logic? 

 

Thank you greatly for any assistance. 

var doc = fl.getDocumentDOM();

function configureTool(){
    var toolObj = fl.tools.activeTool;
    toolObj.setIcon("ExampleTool.png");  
    toolObj.setMenuString("Example Tool");
    toolObj.setToolName("Example Tool");
}

function mouseDown(){
	point = fl.tools.penDownLoc;
	doc.mouseClick({x: point.x, y: point.y}, false, false);
	smoothClickedShape();
}

function smoothClickedShape(){
	for (var i = 1; i <= 10; i++) {
		doc.smoothSelection();
	}
}

 

TOPICS
Code
92
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 ,
Oct 10, 2025 Oct 10, 2025

no, i don't think so.

 

 

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 Beginner ,
Oct 11, 2025 Oct 11, 2025

I've reverse-engineered Animate a bit, and here's what I can say from my experience.
Basically, JavaScript engine inside Animate works in such a way that you essentially directly call the program's internal functions, with some overhead for data converting from JS.
And usually, each edit call is accompanied by a boolean indicating whether to save your action to the undo buffer. For calls from JS, this is usually enabled. But the point is that the undo buffer doesn't know whether your JS script is being executed or not, so it can save your actions, for example, to a specific group to later undo your entire script.
So the short answer - no, it's impossible.

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
Participant ,
Oct 11, 2025 Oct 11, 2025

Thank you for looking into this @DaniilSV ! It looks like I might have to reduce the number of steps in my tool script instead. 

The only workaround I can think of, would be using fl.runScript()  with an extra script to possibly get a combined "Run Command" history step instead of having all my tool's actions being separate steps. 

HistoryPanelComparison.png

 

I'm just unsure whether that would work and if there's a way to send vairable values from the tool script to the separate script.
Such as a variable that would control the number of times smoothSelection() is run. 

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 ,
Oct 11, 2025 Oct 11, 2025
LATEST

it won't work, but it doesn't hurt to try.

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