- Example Script.png (50.4 KiB) Viewed 1685 times
Example Scripts. How to observe source?
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Example Scripts. How to observe source?
howto find and observe script's source?
Re: Example Scripts. How to observe source?
You can find them under scripts/Misc/Examples or online at:
https://github.com/qcad/qcad/tree/maste ... c/Examples
https://github.com/qcad/qcad/tree/maste ... c/Examples
Re: Example Scripts. How to observe source?
Got this!
*/
function ExDeleteObject(guiAction) {
ModifyExamples.call(this, guiAction);
}
ExDeleteObject.prototype = new ModifyExamples();
ExDeleteObject.prototype.beginEvent = function() {
ModifyExamples.prototype.beginEvent.call(this);
var di = this.getDocumentInterface();
var document = this.getDocument();
var op, entity, id;
// add line entity,
// document takes ownership of entity:
op = new RAddObjectsOperation();
entity = new RLineEntity(document, new RLineData(new RVector(0,0), new RVector(100,100)));
op.addObject(entity);
di.applyOperation(op);
// after applying the operation, the ID of the newly added entity is known
// and can be stored as reference for the added entity:
id = entity.getId();
EAction.handleUserMessage(qsTr("Added line with ID %1".arg(id)));
// query a copy of the stored entity from the document
// and use it to delete the entity:
entity = document.queryEntity(id);
op = new RDeleteObjectsOperation();
op.deleteObject(entity);
di.applyOperation(op);
EAction.handleUserMessage(qsTr("Deleted line with ID %1").arg(id));
EAction.handleUserMessage(qsTr("You can use <i>Edit > Undo</i> to restore the line entity."), false);
this.terminate();
};
/**
* Adds a menu for this action.
*/
ExDeleteObject.init = function(basePath) {
var action = new RGuiAction(qsTr("Add and Delete Line"), RMainWindowQt.getMainWindow());
action.setRequiresDocument(true);
action.setScriptFile(basePath + "/ExDeleteObject.js");
action.setGroupSortOrder(78200);
action.setSortOrder(100);
action.setWidgetNames(["ModifyExamplesMenu"]);
};