[Solved]Get entity based on ID

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]Get entity based on ID

Post by Ghost_of_Magellan » Thu Aug 04, 2016 3:42 pm

I will continue using transaction then. Thank you.
Regarding the second question.

Example:

Code: Select all

    entityIds = doc.queryAllVisibleEntities();
    for (i = 0; i < entityIds.length; i++) {
          entity = doc.queryEntity(entityIds[i]);
          Entity_ID = Entity_to_text(entity);
                if (Entity_ID == custom_ID){
                   //Does stuff
                   break;
                }
          }
    }
the custom_ID sometimes comes from the autorefresh fucntion and others comes from a tablewidget that holds the IDs of every entity on the document. Sometimes I need to cross reference the data between the table and the entitylist so Ibasically I need to do a for within a for to find the correct IDs. this means that in 100 entities I may end up making 10000 searches and the respective processes.
My question is: Is there a more effective way, in code size and processing speed, to find an entity in the entityIds pool that this one? Some way, perhaps that uses inbuilt Qcad instructions to find specific ?

Thank you very much for your response.
Last edited by Ghost_of_Magellan on Thu Aug 04, 2016 4:28 pm, edited 1 time in total.

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

Re: Get entity based on ID

Post by andrew » Thu Aug 04, 2016 3:49 pm

What does your Entity_to_text do?
Are you trying to look up an entity that matches a certain geometry (e.g. a line from 50,20 to 70,80) or an entity that matches a certain ID?

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

Re: Get entity based on ID

Post by Ghost_of_Magellan » Thu Aug 04, 2016 4:07 pm

Entity_to_text(entity); simply takes the Id of the entity and returns it as a string. Since I'll have to compare it with other sources that mostly work as strings.

Code: Select all

function Entity_to_text(entity){
	var Entity_ID;
	Entity_ID = entity.getId();
	Entity_ID = Entity_ID.toString();
	return Entity_ID;
}
vl_objIds = vl_changes.getAffectedObjects(); also returns as string, if i'm not mistaken, so It's all for the best, since I can't compare different types of variables.

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

Re: Get entity based on ID

Post by andrew » Thu Aug 04, 2016 4:20 pm

RTransaction::getAffectedObjects returns a list of object IDs as integers (RObject::Id) not strings.

If you have an entity ID, you can simply query the entity from the document using:

Code: Select all

entity = doc.queryEntity(entityId);

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

Re: Get entity based on ID

Post by Ghost_of_Magellan » Thu Aug 04, 2016 4:28 pm

andrew wrote:RTransaction::getAffectedObjects returns a list of object IDs as integers (RObject::Id) not strings.]
Correct once again, andrew. I failed to see the "vl_change_list= vl_objIds.toString();" on my own code.

Gonna do some testing, but I suppose this is all I'll need for now.

Thank you so very much, andrew,

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”