acedGetVar with CLAYER returns error: Value out of range

acedGetVar with CLAYER returns error: Value out of range

Anonymous
Not applicable
1,584 Views
3 Replies
Message 1 of 4

acedGetVar with CLAYER returns error: Value out of range

Anonymous
Not applicable

Hi, this is strange.

When I normally try to get this variable (CLAYER) using acedGetVar, everything works fine. But, when I open current user layer (for write) and then try to read this variable, acedGetVar returns error RTERROR.

Now, when I read variable ERRNO I get the result: "Value out of range"

 

This is part of my code for retrieving variables(it isn't really interesting):

 

 

template<typename T>
inline T GetVariable(const std::wstring & name)
{
	ResBufWrapperPtr pResBuf(new ResBufWrapper());		
	int res = acedGetVar(name.c_str(), pResBuf->GetFirstResBuf());
	if(res != RTNORM)
	{
		ResBufWrapperPtr pErrNo(new ResBufWrapper());
		acedGetVar(L"ERRNO", pErrNo->GetFirstResBuf());
		AcString msg;
		msg.format(L"Could not get system variable: %s. Error %d", name.c_str(), res);
		throw CLAAS_EXCEPTION(msg.constPtr());
	}
			
	return GetVariableData<T>(*pResBuf->GetFirstResBuf());
}

 

And this is my code that wants to know the value of CLAYER:

 

//first lock the document
AcAp::DocLockMode lm = m_pDoc->lockMode(true);

//next open layer for write
AcDbObjectPointer<AcDbObject> pObj(id, AcDb::kForWrite);

 

Now, when I call acedGetVar("CLAYER") before opening the object, everything works fine. But when I call it after opening the object, I get the error. But to receive this error, the object that you're opening must be really current user layer. So you can create a layer and set it as user layer (acedSetVar). And then open this object and call acedGetVar("CLAYER")

 

Is that an Autocad bug or do I do something wrong? I noticed this error on Autocad 2014, but it exists on other versions as well (2015, 2016)

0 Likes
Accepted solutions (1)
1,585 Views
3 Replies
Replies (3)
Message 2 of 4

Alexander.Rivilis
Mentor
Mentor
Accepted solution

I've not check your code but think that function acadGetVar(L"CLAYER",...) also trying то open AcDbLayerTableRecord of current layer in order to get it name, but if this AcDbLayerTableRecord was already opened ForWrite so acadGetVar can not open AcDbLayerTableRecord second time and so return error code.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 3 of 4

Anonymous
Not applicable

Not only this seems logical, but also it's true. I've checked it. Thanks for reply 🙂

0 Likes
Message 4 of 4

Anonymous
Not applicable

Can you please Help? I am trying to import GPS coordinates, gamma strengths, icon sizes, ect. from Script file and also command line paste. The script file is fine (I have a sample from a friend to compare), but I keep getting, "enter new value for clayer", "Cannot set value for clayer" or "specify point". I am pulling my hair out. Paul: 305-699-8071 , Key West

0 Likes