Page 1 of 1

Script Shell. How to repeat last command? Variable scope

Posted: Sat Feb 17, 2018 9:11 am
by dfriasb
Script Shell seems to be a very powerful tool. But I have some doubts about it:
  • 1.- Is there some way to get last line entered? It usually happens to me that I want to rewrite last command with some little change, but then I have to rewrite the whole line again. In some terminals you can do that with up arrow; I saw in QCAD Script Shell this works in a different way.

    2.- I'm trying to use Script Shell to define or modify variables directly in QCAD interface. I use that variables in scripts located in /scripts/ Misc/Examples/LayerExamples. I cannot see any effect on that variables and their scripts. For example, I have a script that defines Wall variable as "Abc"; if I change the value of variable Wall in QCAD Script Shell (Wall="Bcd"; for example), and then I Run Script that contains variable Wall inside, I cannot see any change on the result; Wall is still "Abc" for this script effects.
Has last point something to do with variable scope?

Thank you. Best regards!

David

Re: Script Shell. How to repeat last command? Variable scope

Posted: Mon Feb 19, 2018 11:38 am
by andrew
dfriasb wrote:
  • 1.- Is there some way to get last line entered?
Yes, arrow up should do this but is currently broken due to implementation of arrow up shortcuts to pan zoom.
dfriasb wrote:2.- I'm trying to use Script Shell to define or modify variables directly in QCAD interface. I use that variables in scripts located in /scripts/ Misc/Examples/LayerExamples. I cannot see any effect on that variables and their scripts.
QCAD uses different script scopes to prevent that one tool could influence or damage another tool in any way by changing its variables, etc. You can generally not access other script actions that were not instantiated in the script shell self.

Re: Script Shell. How to repeat last command? Variable scope

Posted: Fri Mar 02, 2018 10:04 am
by dfriasb
andrew wrote:
dfriasb wrote:
  • 1.- Is there some way to get last line entered?
Yes, arrow up should do this but is currently broken due to implementation of arrow up shortcuts to pan zoom.
Arrow up is working perfectly in Command Line but not in Script Shell. This text is coming in my case when I press arrow up, which is and old script pasted some days ago:

include("../LayerExamples.js");

// define array for character #1 in layer name:
var layerCharPos1 = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];

// define array for character #2 in layer name. These are the layyers to be frozen :::::
var layPos2 = ["a","c","k","u","v"];

/**
* \ingroup ecma_misc_examples_layerexamples
* \class lay1
* This action changes the color of all white layers to black.
*/
function lay1(guiAction) {
LayerExamples.call(this, guiAction);
}

lay1.prototype = new LayerExamples();

lay1.prototype.beginEvent = function() {
LayerExamples.prototype.beginEvent.call(this);

var di = this.getDocumentInterface();
var document = this.getDocument();

var op = new RModifyObjectsOperation();

var layerIds = document.queryAllLayers();
for (var i=0; i<layerIds.length; i++) {
for (j=0;j<layPos2.length;j++) {
var layerId = layerIds;
var layer = document.queryLayer(layerId);

if (layer.getName()== layPos2 + layPos2[j]) {
layer.setFrozen(true);
op.addObject(layer);
}
}
}
di.applyOperation(op);
this.terminate();
};

/**
* Adds a menu for this action.
*/
lay1.init = function(basePath) {
var action = new RGuiAction(qsTr("lay1"), RMainWindowQt.getMainWindow());
action.setRequiresDocument(true);
action.setScriptFile(basePath + "/lay1.js");
action.setDefaultCommands(["lay1"]);
action.setGroupSortOrder(78100);
action.setSortOrder(200);
action.setWidgetNames(["LayerExamplesMenu"]);
};


That seems to be really weird... :-( Any idea of what can be happening?