Checking if entity is selected

Checking if entity is selected

Kyudos
Advisor Advisor
812 Views
4 Replies
Message 1 of 5

Checking if entity is selected

Kyudos
Advisor
Advisor

Before I embark on developing an alternative can I just double check...

 

The only way to check if an AcDbObject / AcDbEntity is selected is to iterate through a selection set (or equivalent array) - correct?

 

There is no "selected" property of the object (e.g., isSelected) that AutoCAD maintains?

 

Meaning the time taken to check if something is selected varies with the size of the selection?

0 Likes
813 Views
4 Replies
Replies (4)
Message 2 of 5

nick83
Advocate
Advocate

The only way to check if an AcDbObject / AcDbEntity is selected is to iterate through a selection set (or equivalent array) - correct?


as far as i know, thats the only way we have.


Meaning the time taken to check if something is selected varies with the size of the selection?


yeah, but we are talking about milliseconds 🙂

 

well, for example, try this code, to check was the entity selected before command starts or not.

//dont forget to add ACRX_CMD_USEPICKSET | ACRX_CMD_REDRAW to the command, that will use this function
bool isEntitySelected(AcDbObjectId eId2Check)
{
	bool isSelected = false;
	AcDbObjectId eId;
	ads_name one_ent;
	long len = 0L;
	struct resbuf *grip_set = NULL, *ents = NULL;
	int res = acedSSGetFirst(&grip_set, &ents);
	if (res == RTNORM)
	{
		if (ents) 
		{
			if (ents ->restype == RTPICKS) 
			{		
				acedSSLength(ents->resval.rlname, &len);

				for (long a = 0; a < len; a++)
				{
					if (ads_ssname(ents->resval.rlname,a,one_ent)!=RTNORM)continue;
					if(acdbGetObjectId(eId, one_ent)!= Acad::eOk)continue;
					if (eId == eId2Check)
					{
						isSelected = true;
						break;
					}
				}
				acedSSFree(ents->resval.rlname);
			}
			acutRelRb(ents);
		}

		if (grip_set) 
		{
			if (grip_set->restype == RTPICKS) acedSSFree(grip_set->resval.rlname);
			acutRelRb(grip_set);
		}
	}
	return isSelected;
}

 

0 Likes
Message 3 of 5

Alexander.Rivilis
Mentor
Mentor

@Kyudos wrote:

... There is no "selected" property of the object (e.g., isSelected) that AutoCAD maintains?...


It seems that you do not understand the basic principles of ObjectARX. For example, about that AcDbXXXX classes are related only to the database and have no knowledge about the AutoCAD UI (selection is a UI unit).

 

If you has a selection as AcDbObjectIdArray - its find() method is fast enough.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 4 of 5

Kyudos
Advisor
Advisor

@Alexander.Rivilis wrote:

If you has a selection as AcDbObjectIdArray - its find() method is fast enough.


Yeah it's fast enough for one-offs, but I have connected objects that cannot easily be grouped, since they potentially belong to more than one group and need to be able to move independently. In order for me to move them correctly I need to know whether they themselves are selected, and whether the things they are connected to are selected. This potentially involves searching the "selected" array many hundreds or thousands of times for my most complex moves. I was considering maintaining my own 'selected' property to speed this up.

0 Likes
Message 5 of 5

Alexander.Rivilis
Mentor
Mentor

You can use AcEdSSGetFilter class in order to check adding/removing object to selection set.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes