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.
Add new button with my script
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Re: Add new button with my script
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
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
Re: Add new button with my script
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!
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!