[solved] Paste script mouse click

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

[solved] Paste script mouse click

Post by sinase » Tue Mar 02, 2021 12:59 pm

Hello,

I will be very grateful if you can help me with this. I am working in a script (copyPaste.js) and i am blocked in one point. I need to simulate a mouse click on anyplace of my document, after copy and paste. It works correctly but i need to say where my object must been paste.

At the moment, my code is the follows:

//Begin.
var action = RGuiAction.getByScriptFile("scripts/Edit/Copy/Copy.js");
if (!isNull(action)) {
action.slotTrigger();
}

var action = RGuiAction.getByScriptFile("scripts/File/NewFile/NewFile.js");
if (!isNull(action)) {
action.slotTrigger();
}
var document = getDocument();


var action = RGuiAction.getByScriptFile("scripts/Edit/Paste/Paste.js");
if (!isNull(action)) {
action.slotTrigger();
}

//MOUSE_CLICK

this.autoZoom();
//End.


I need to put the code on //MOUSE_CLICK zone.

Many thanks!!
Kind regards.

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

Re: Paste script mouse click

Post by andrew » Tue Mar 02, 2021 1:09 pm

This won't work as Paste is an interactive tool requiring the target position as user input as well as other parameters.

FileNew and Copy are not interactive and immediately return control to your script.

To paste the clipboard, you can use a paste operation as follows (where x and y are your target coordinates):

Code: Select all

var op = new RPasteOperation(RDocument.getClipboard());
op.setOffset(new RVector(x,y));
op.setRotation(0.0);
op.setScale(1.0);
op.setFlipHorizontal(false);
op.setFlipVertical(false);
op.setToCurrentLayer(true);
op.setOverwriteBlocks(true);
op.setCopyEmptyBlocks(true);

var di = getDocumentInterface();
di.applyOperation(op);

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

Re: Paste script mouse click

Post by sinase » Tue Mar 02, 2021 3:23 pm

It works!!.

Many many thanks.
I'm really grateful

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”