script not working
Posted: Sat May 02, 2020 3:51 pm
Dear all,
I have reviewed this code many times but I can't find what is not working. When I paste the central part in QCAD script console it works great, but not when try it as a command. I guess it is something related with guiAction; looks like action is not completed...
Any help will be very welcomed.
Best regards,
David
This is the code that works correctly on console:
And this is the complete file:
I have reviewed this code many times but I can't find what is not working. When I paste the central part in QCAD script console it works great, but not when try it as a command. I guess it is something related with guiAction; looks like action is not completed...
Any help will be very welcomed.
Best regards,
David
This is the code that works correctly on console:
Code: Select all
var di = this.getDocumentInterface();
var doc = this.getDocument();
var selectedEntities = doc.querySelectedEntities();
var op = new RAddObjectsOperation();
for (i=0; i<selectedEntities.length; i++) {
entity = doc.queryEntity(selectedEntities[i]);
if (!isBlockReferenceEntity(entity)) {continue;}
blockName = entity.getReferencedBlockName();
blockRefPosition = entity.getPosition();
blockRefAngle = entity.getRotation()*360/(2*Math.PI);
// impressió ::
printText = addSimpleText(blockName, blockRefPosition, 0.003, blockRefAngle, "Cotes", RS.VAlignMiddle, RS.HAlignCenter, false, false);
op.addObject(printText);}
Code: Select all
// prints all selected block references block names. Text angle displayed is block reference rotation angle ::
// !!! something is not working when starting the command on QCAD.
include("../DFa.js");
include("simple.js");
function printblocknameselected(guiAction) {
DFa.call(this, guiAction);}
printblocknameselected.prototype = new DFa();
printblocknameselected.prototype.beginEvent = function() {
DFa.prototype.beginEvent.call(this);
// THIS PART IS WORKING IN QCAD SCRIPT CONSOLE :
var di = this.getDocumentInterface();
var doc = this.getDocument();
var selectedEntities = doc.querySelectedEntities();
var op = new RAddObjectsOperation();
for (i=0; i<selectedEntities.length; i++) {
entity = doc.queryEntity(selectedEntities[i]);
if (!isBlockReferenceEntity(entity)) {continue;}
blockName = entity.getReferencedBlockName();
blockRefPosition = entity.getPosition();
blockRefAngle = entity.getRotation()*360/(2*Math.PI);
// impressió ::
printText = addSimpleText(blockName, blockRefPosition, 0.003, blockRefAngle, "Cotes", RS.VAlignMiddle, RS.HAlignCenter, false, false);
op.addObject(printText);}
// TIL HERE.
di.applyOperation(op);
this.terminate();
};
// Adds menu&command for this action::
printblocknameselected.init = function(basePath) {
var action = new RGuiAction(qsTr("&printblocknameselected"), RMainWindowQt.getMainWindow());
action.setRequiresDocument(true);
action.setScriptFile(basePath + "/printblocknameselected.js");
action.setDefaultCommands(["bnames"]);
action.setDefaultShortcut(new QKeySequence("b,n"));
action.setGroupSortOrder(78100);
action.setSortOrder(200);
action.setWidgetNames(["DFaMenu"]);
};