[solved] Select entity
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.
-
thielaco
- Active Member
- Posts: 25
- Joined: Wed Sep 06, 2023 11:22 am
- Location: Tours, France
[solved] Select entity
hi,
how is the way to select an entity (make it effective, not on the fly) before picking position?
Regards
Thierry
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
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
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.
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
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.
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
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.
Regards,
CVH
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.
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
ExMyMinimal.prototype = new EAction();
I don't find this code line into script like TG... is it necessary to insert it ?
Regards
Thierry
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
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.
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.
-
CVH
- Premier Member
- Posts: 4959
- Joined: Wed Sep 27, 2017 4:17 pm
Re: Select entity
You need to dig deeper ....
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
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
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 ....
Regards,
CVH
-
thielaco
- Active Member
- Posts: 25
- Joined: Wed Sep 06, 2023 11:22 am
- Location: Tours, France
Re: Select entity
I am ashamed... Thanks you very much
Regards,
Thierry
Regards,
Thierry