Example Scripts. How to observe source?

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
jooogger
Junior Member
Posts: 15
Joined: Sun Nov 22, 2020 4:34 am

Example Scripts. How to observe source?

Post by jooogger » Mon May 16, 2022 10:52 am

Example Script.png
Example Script.png (50.4 KiB) Viewed 1596 times
howto find and observe script's source?

User avatar
andrew
Site Admin
Posts: 9019
Joined: Fri Mar 30, 2007 6:07 am

Re: Example Scripts. How to observe source?

Post by andrew » Mon May 16, 2022 10:55 am

You can find them under scripts/Misc/Examples or online at:
https://github.com/qcad/qcad/tree/maste ... c/Examples

jooogger
Junior Member
Posts: 15
Joined: Sun Nov 22, 2020 4:34 am

Re: Example Scripts. How to observe source?

Post by jooogger » Tue May 17, 2022 8:24 am

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"]);
};

Post Reply

Return to “QCAD 'How Do I' Questions”