Add new button with my script

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
sinase
Active Member
Posts: 47
Joined: Sat Jan 30, 2021 11:12 pm

Add new button with my script

Post by sinase » Thu Mar 04, 2021 11:31 am

Hi,

It is possible to add a new button at the principal page with my script action associed?. I have saw this method:

https://www.qcad.org/doc/qcad/latest/de ... _bars.html

But i would like a more quick access button. There is an example?

Thank you very much.

CVH
Premier Member
Posts: 3467
Joined: Wed Sep 27, 2017 4:17 pm

Re: Add new button with my script

Post by CVH » Thu Mar 04, 2021 12:23 pm

Hi, the link is the correct way.
You need to alter your script to a QCAD GUI addon.
There is a certain File/Folder/Class structure/script name convention.
https://qcad.org/rsforum/viewtopic.php?p=32190#p32190

One can define where your action button will appear under the init section.
In action.setWidgetNames([ , , , ])

About every QCAD GUI script is an example:
https://github.com/qcad/qcad/tree/master/scripts

Regards,
CVH

sinase
Active Member
Posts: 47
Joined: Sat Jan 30, 2021 11:12 pm

Re: Add new button with my script

Post by sinase » Mon Mar 15, 2021 4:47 pm

Hello,

I have my script avaiable on my new top menu with an icon image asociated. I am trying to show that icon on a toolbar, but this new toolbar is empty. It is possible to show that icon quick access? I dont know what is failing in my code:

// MyScripts.js
include("scripts/EAction.js");

function MyScripts(guiAction) {
EAction.call(this, guiAction);
}
MyScripts.prototype = new EAction();

MyScripts.getMenu = function() {
// EAction.getMenu is a helper function that returns an existing
// or new QMenu object with the given title and object name.
// The object name (here "MyScriptMenu") must be unique.
return EAction.getMenu(MyScripts.getTitle(), "MyScriptsMenu");
};

MyScripts.getToolBar = function() {
return EAction.getToolBar(MyScripts.getTitle(), "MyScriptsToolBar");
};

MyScripts.getTitle = function() {
return qsTr("My Scripts");
};

MyScripts.init = function() {
MyScripts.getMenu();
MyScripts.getToolBar();
};



// CutPaste.js
include("../MyScripts.js");

function CutPaste(guiAction) {
MyScripts.call(this, guiAction);
}

CutPaste.prototype = new MyScripts();

CutPaste.prototype.beginEvent = function() {

MyScripts.prototype.beginEvent.call(this);

var action = RGuiAction.getByScriptFile("scripts/Edit/Cut/Cut.js");
if (!isNull(action)) {
action.slotTrigger();
}
var action2 = RGuiAction.getByScriptFile("scripts/File/NewFile/NewFile.js");
if (!isNull(action2)) {
action2.slotTrigger();
}
var di = EAction.getDocumentInterface();
var document = di.getDocument();
var op = new RPasteOperation(RDocument.getClipboard());
op.setOffset(new RVector(0,0));
op.setRotation(0.0);
op.setScale(1.0);
op.setFlipHorizontal(false);
op.setFlipVertical(false);
op.setToCurrentLayer(true);
op.setOverwriteBlocks(true);
//op.setCopyEmptyBlocks(true);

di.applyOperation(op);
di.autoZoom();

var data = readTextFile("/Planning/Oferta.txt");
var d = new Date();
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
di.exportFile("O:/" + data + "/Procesado/" + data + "_" + h + m + s + ".dxf", "DXF 2000");

this.terminate();
};

CutPaste.init = function(basePath) {
var action = new RGuiAction("&CutPaste", RMainWindowQt.getMainWindow());
action.setRequiresDocument(true);
action.setScriptFile(basePath + "/CutPaste.js");
action.setIcon(basePath + "/CutPaste.svg");
action.setDefaultCommands(["cutpaste"]);
action.setGroupSortOrder(100);
action.setSortOrder(100);
action.setWidgetNames(["MyScriptsMenu"]);
};


Thank you!

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”