[solved] Select entity

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
thielaco
Active Member
Posts: 25
Joined: Wed Sep 06, 2023 11:22 am
Location: Tours, France

[solved] Select entity

Post by thielaco » Wed May 22, 2024 6:35 pm

hi,
how is the way to select an entity (make it effective, not on the fly) before picking position?
Regards
Thierry

thielaco
Active Member
Posts: 25
Joined: Wed Sep 06, 2023 11:22 am
Location: Tours, France

Re: Select entity

Post by thielaco » Wed May 22, 2024 7:35 pm

This code doesn't work, when I click on the entity, nothing happens...

Code: Select all

InsertBlockR.prototype.pickEntity = function(event, preview) {
	var di = this.getDocumentInterface();
    var doc = this.getDocument();
    var entityId = event.getEntityId();
    var entity = doc.queryEntity(entityId);
    var pos = event.getModelPosition();

   if (isNull(entity)) {
        this.entity = undefined;
        this.shape = undefined;
        return;
    } else {		
		var op = this.getOperation(preview);
		if (isLineBasedEntity(entity) ||
			isArcEntity(entity) ||
			(RPolyline.hasProxy() && isPolylineEntity(entity))) {		
			if (preview) {	
				di.previewOperation(op);
			} else {
				if (!isNull(op)) {	
					this.entity = entity;
					this.setState(InsertBlockR.State.SettingPosition);			
					//debugger;
					di.applyOperation(op);
				}
			}
		}
		else {
			if (!preview) {
				if (RSpline.hasProxy() && RPolyline.hasProxy()) {
					EAction.warnNotLineArcPolyline();
				}
				else {
					EAction.warnNotLineArc();
				}
			}
		}
	}
};

333onlyhalfevil
Full Member
Posts: 92
Joined: Fri Apr 28, 2023 12:39 pm

Re: Select entity

Post by 333onlyhalfevil » Thu May 23, 2024 5:50 am

After the part where you query the entity, try using the selectEntity function to select it: di.selectEntity(entityId);.

Also, at the end of your script, you need to clear the previews and repaint the views so your selection will be displayed to the GUI with: di.clearPreview() and di.repaintViews().

Check out the select script on github for additional info on how to select things: https://github.com/qcad/qcad/blob/maste ... /Select.js

Hope that helps.

thielaco
Active Member
Posts: 25
Joined: Wed Sep 06, 2023 11:22 am
Location: Tours, France

Re: Select entity

Post by thielaco » Thu May 23, 2024 8:08 am

in the script,there are two entities to select... the bloc I want to insert and the polyline... and also the insert position.
Is there another function that requires similar sequence? Perhaps it is the cause to a conflict.

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

Re: Select entity

Post by CVH » Thu May 23, 2024 8:54 am

Hi,
InsertBlockR.prototype.pickEntity(event, preview)
Is not stand alone code.

It is part of an interactive script where EAction will handle the sequence of things.
Remark that any interactive script can be suspended for doing something else meanwhile.
A basic tutorial (Only in English): https://www.ribbonsoft.com/en/tutorial- ... pt-actions

this.getOperation(preview) is the part that will return the operation.
- In preview mode it will probably only do part of the action to show a preview of the outcome ... So far.
- In final mode (preview = false) it will handle the required action.

pickEntity() then shows this preview (di.previewOperation(op)) or applies the operation in full.

It must be clear that picking an entity is the final step in this interactive script.
From your newer post I understand that you first want to indicate an entity and then a point on/near that entity.
Then pickEntity() is not your final interaction.

And another remark is that you can't select a Block in Model_Space, you can select entities, a Block-Reference for example.
One can select a Block in the Block List, the tool would then insert a copy of the current Block as Block-Reference near an entity at a position.
Selecting the Block itself is not part of the interaction.

One can of course filter on RBlockReferenceEntity for a selected entity and collect the referenced Block Id or name.
thielaco wrote:
Thu May 23, 2024 8:08 am
Is there another function that requires similar sequence? Perhaps it is the cause to a conflict.
Yes, pick any (Open Source) Addon script that has fairly the same sequence as yours and look it up on GitHub.

Regards,
CVH

thielaco
Active Member
Posts: 25
Joined: Wed Sep 06, 2023 11:22 am
Location: Tours, France

Re: Select entity

Post by thielaco » Thu May 23, 2024 9:18 am

ExMyMinimal.prototype = new EAction();
I don't find this code line into script like TG... is it necessary to insert it ?
Regards
Thierry

thielaco
Active Member
Posts: 25
Joined: Wed Sep 06, 2023 11:22 am
Location: Tours, France

Re: Select entity

Post by thielaco » Thu May 23, 2024 10:29 am

I join the code...
debugger on line 152 give this.entity correct but just after... nothing and if I debug just after this.setState(...)SettingPosition, this.entity is undefined.
on qcad command line, the ask stay on select line, arc or polyline. but no error is visible.
InsertBlockRInit.js
(604 Bytes) Downloaded 894 times
InsertBlockR.ui
(15.81 KiB) Downloaded 858 times
InsertBlockR.js
(14.39 KiB) Downloaded 871 times

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

Re: Select entity

Post by CVH » Thu May 23, 2024 10:31 am

thielaco wrote:
Thu May 23, 2024 9:18 am
I don't find this code line into script like TG
You need to dig deeper .... :wink:

TG line 58: TextAlong.prototype = new Draw();
Draw is included as: include("scripts/Draw/Draw.js");

Draw.js line 37: Draw.prototype = new EAction();
There EAction is included as: include("scripts/EAction.js");

In one way or another all tools are based on EAction.

Regards,
CVH

thielaco
Active Member
Posts: 25
Joined: Wed Sep 06, 2023 11:22 am
Location: Tours, France

Re: Select entity

Post by thielaco » Thu May 23, 2024 10:43 am

i don't see the skyscraper behind my little finger... sometimes

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

Re: Select entity

Post by CVH » Thu May 23, 2024 11:20 am

thielaco wrote:
Thu May 23, 2024 10:43 am
i don't see the skyscraper behind my little finger... sometimes
Well, sometimes it is searching for a needle in a haystack.

Look at the declarations of your states:
ChoosingEntity : 0
SettingPosition : 0


Setting position is thus also state 0 and that clears this.entity
Your code never reached the setting position state .... :wink:

Regards,
CVH

thielaco
Active Member
Posts: 25
Joined: Wed Sep 06, 2023 11:22 am
Location: Tours, France

Re: Select entity

Post by thielaco » Thu May 23, 2024 11:37 am

I am ashamed... Thanks you very much
Regards,
Thierry

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”