I’m trying to assign the Asc.scope.eq variable to the text in the math equation field the cursor is currently in.
I want the variable assigned before the evaluatex() function is called.
(function (window, undefined) {
window.Asc.plugin.init = function () {
Asc.scope.eq = "2+2"
// Somehow assign Asc.scope.eq to the text in the math equation text field the cursor is in
var fn = evaluatex(Asc.scope.eq);
var res = fn().toString();
var sScript = "var oDocument = Api.GetDocument();";
sScript += "oDocument.AddMathEquation('" + res + "');";
this.info.recalculate = true;
this.executeCommand("close", sScript);
};
})(window, undefined);
I’ve been trying to find a solution for a few hours now, but I’m really struggling.
Any help is appreciated
Thanks in advance! 
Hello @Pineapple0000
Somehow assign Asc.scope.eq to the text in the math equation text field the cursor is in
I’m not sure that this approach is possible. It seems that you can use GetSelectedContent method (GetSelectedContent | ONLYOFFICE) to achieve the same scenario.
Please clarify if I misunderstood the request.
Hi @Alexandre
I have attempted to do that, but I can’t find an implementation that successfully assigns the selected text to the variable
Do you think you could write an example?
Thank you
Hello,
we’re looking into it. I will contact you as soon as possible.
1 Like
It seems that this method works this way:
window.Asc.plugin.init = function () {
window.Asc.plugin.executeMethod("GetSelectedContent", [{type:"text"}], (text) => {
console.log(text);
window.Asc.scope.eq = text;
});
};
However, you need to select the formula in the field first. I’m not sure how to achieve this at the moment. I’ve found my old plugin sample and a video test, which might be useful for your research (it selects all data in the file; I’m not sure if it still works, but it could still be helpful). I’ll send it to you via PM.
1 Like