[Solved]Selecting entities and direction

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
Ghost_of_Magellan
Full Member
Posts: 58
Joined: Wed Mar 16, 2016 5:10 pm

[Solved]Selecting entities and direction

Post by Ghost_of_Magellan » Mon May 02, 2016 9:49 am

Greetings once again!

A few questions:

1 - I want to build a code function that allows me to select an entity on the drawing board, the same way as if I had clicked on the entity itself. I assume there is a library function for this, using, perhaps, the ID of the entity. could an example be provided?

2 - I want to make a function that allows me to change the direction of an entity. For example: Line starts in [0;0] and ends in [10;10]. I want to be able to change it from [10;10] to [0;0] with a click. I don't think that merely changing the coordinates is the best way to achieve this. I have noticed that there are two functions in QCad library "direction1()" and "direction2()" that may have something to do with this, but I fail to understand how they work and if they are what I am looking for.

3 - I note that when I create entities in QCad, there is a small red dot that appears on points of interest as I work. I would like to know how to make this dot appear in points of my choosing, through code.

As usual, I use javascript.

Thank you very much.
Last edited by Ghost_of_Magellan on Thu May 05, 2016 10:12 am, edited 1 time in total.

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

Re: Selecting entities and direction

Post by andrew » Mon May 02, 2016 10:12 am

Ghost_of_Magellan wrote:1 - I want to build a code function that allows me to select an entity on the drawing board, the same way as if I had clicked on the entity itself. I assume there is a library function for this, using, perhaps, the ID of the entity. could an example be provided?
RDocumentInterface::selectEntity
Ghost_of_Magellan wrote:2 - I want to make a function that allows me to change the direction of an entity. For example: Line starts in [0;0] and ends in [10;10]. I want to be able to change it from [10;10] to [0;0] with a click. I don't think that merely changing the coordinates is the best way to achieve this. I have noticed that there are two functions in QCad library "direction1()" and "direction2()" that may have something to do with this, but I fail to understand how they work and if they are what I am looking for.
Reversible entities have a function reverse: RLineEntity::reverse(), e.g. myLine.reverse();
As usual, such a change would have to be applied using an operation.
Ghost_of_Magellan wrote:3 - I note that when I create entities in QCad, there is a small red dot that appears on points of interest as I work. I would like to know how to make this dot appear in points of my choosing, through code.
RDocumentInterface::setRelativeZero

Ghost_of_Magellan
Full Member
Posts: 58
Joined: Wed Mar 16, 2016 5:10 pm

Re: Selecting entities and direction

Post by Ghost_of_Magellan » Mon May 02, 2016 12:05 pm

Hmm. So it seems I can't just do

Code: Select all

		doc = EAction.getDocument();
		entityIds = doc.queryAllVisibleEntities();
		//Cycle
		entity = doc.queryEntity(entityIds[i]);
		// End Cycle
		doc.selectEntity(55, true);
The functions won't understand the int value, it seems. That, or I'm trying to put the values into the wrong object, though i have attempted to put it into entityIds and entity and the debuger returned the error: "Result of expression 'entity.selectEntity' [undefined] is not a function."

I believe it is safe to say that I have not yet grasped the class and object variables as I should.

I have also tried:

Code: Select all

doc.selectEntity(entity.getId(), true);
within the cycle to no avail.

May I have a code example?
I apologize for wasting your time.

Thank you, andrew.

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

Re: Selecting entities and direction

Post by andrew » Mon May 02, 2016 1:38 pm

It could be that you are selecting entities but the selection is not reflected on the display. Try using the document interface instead (EAction.getDocumentInterface()). A document knows nothing about the views that are attached to it and cannot update them.

See also:
http://www.qcad.org/doc/qcad/latest/dev ... asses.html

Ghost_of_Magellan
Full Member
Posts: 58
Joined: Wed Mar 16, 2016 5:10 pm

Re: Selecting entities and direction

Post by Ghost_of_Magellan » Mon May 02, 2016 5:51 pm

Thank you andrew, the RDocumentInterface worked nicely. And the documentation you provided, though too complicated for me, helped me get a sense of how the doc-interface-graphical connections in QCad work.
docInterface = EAction.getDocumentInterface();
docInterface.selectEntity(55, true);
The 55 here, being just an example. Now I can select any entity in order of its ID.

I tried to use the same logic with the setRelativeZero but ended up short. I made some attempts
var tst = tst.RVector(10,10,0,true);
docInterface.setRelativeZero(tst);
/* Result of expression 'tst' [undefined] is not an object.*/
docInterface.setRelativeZero(10,10,0);
/* <global>() at -1 */
docInterface.setRelativeZero(10,10,0,true);
/* <global>() at -1 */
Among many other examples, some so ridiculous that I'm simply too embarassed to post here =\

I suppose the proper way to do it would initiate a RVector variable with the contents of the point in either int or string?

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

Re: Selecting entities and direction

Post by andrew » Mon May 02, 2016 7:12 pm

var v = new RVector(10,10);
docInterface.setRelativeZero(v);
or short:
docInterface.setRelativeZero(new RVector(10,10));

Ghost_of_Magellan
Full Member
Posts: 58
Joined: Wed Mar 16, 2016 5:10 pm

Re: Selecting entities and direction

Post by Ghost_of_Magellan » Wed May 04, 2016 9:22 am

This is exactly it!

Thank you very much, andrew.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”