Make a sample for read dictionary error

Make a sample for read dictionary error

Anonymous
Not applicable
891 Views
5 Replies
Message 1 of 6

Make a sample for read dictionary error

Anonymous
Not applicable

Hi,

i have make a sample for add xrecord to entity, but while i make the sample for read the xrecod, the problem stop at acutprintf, anyone can tell me where i made the mistake?

 

For add xrecord:

add xrecord.jpg

 

For read the xrecord, but programe stop at acutprintf:

 

READ.jpg

 

Error information:

error.jpg

0 Likes
Accepted solutions (2)
892 Views
5 Replies
Replies (5)
Message 2 of 6

BerndCuder8196
Advocate
Advocate
Accepted solution

First of all, please post the code as text, not as picture. In the browser you can add code with forum button: </>

With the code i can reproduce the problem.

 

Next is, i think AcDb::kDxfInt32 will be sb->resval.rlong

 

Here an example that will work, notice, BeCAD_ItextData is an custom class from my application. It also checks if there is

always an Xrecord on the entity

 

Sets the Xrecord:

 

void setItextXrecordData(AcDbText *pText, BeCAD_ItextData *pItextData)
{
	AcDbObjectId extDictId = pText->extensionDictionary();

	if (extDictId == NULL)
	{
		pText->createExtensionDictionary();

		extDictId = pText->extensionDictionary();
	}

	AcDbDictionary *pDictionary;

	if (acdbOpenObject(pDictionary, extDictId, AcDb::kForWrite) != Acad::eOk)
	{
		return;
	}

	AcDbXrecord *pXrecord = NULL;

	if (!pDictionary->has(_T("CCNC_Data")))
	{
		pXrecord = new AcDbXrecord();

		AcDbObjectId xRecordId;

		pDictionary->setAt(_T("CCNC_Data"), pXrecord, xRecordId);

		pDictionary->close();
	}
	else
	{
		AcDbObjectId xRecordId;

		pDictionary->getAt(_T("CCNC_Data"), xRecordId);

		pDictionary->close();

		if (acdbOpenObject(pXrecord, xRecordId, AcDb::kForWrite) != Acad::eOk)
		{
			return;
		}
	}

	if (pXrecord == NULL)
	{
		return;
	}

	struct resbuf *prbXtn;

	if (pItextData->m_drawSpaceId == AcDbObjectId::kNull)
	{
		prbXtn = acutBuildList(
			AcDb::kDxfInt16, pItextData->m_scale,
			AcDb::kDxfInt16, pItextData->m_unit,
			AcDb::kDxfReal, pItextData->m_height,
			RTNONE);
	}
	else
	{
		ads_name ename;

		acdbGetAdsName(ename, pItextData->m_drawSpaceId);

		prbXtn = acutBuildList(
			AcDb::kDxfInt16, pItextData->m_scale,
			AcDb::kDxfInt16, pItextData->m_unit,
			AcDb::kDxfReal, pItextData->m_height,
			AcDb::kDxfSoftPointerId, ename,
			RTNONE);
	}

	pXrecord->setFromRbChain(*prbXtn);

	pXrecord->close();

	ads_relrb(prbXtn);
}

Reads the Xrecord:

 

bool getItextXrecordData(AcDbText *pText, BeCAD_ItextData *pItextData)
{
	AcDbObjectId extDictId = pText->extensionDictionary();

	AcDbDictionary *pDictionary;

	if (acdbOpenObject(pDictionary, extDictId, AcDb::kForRead) != Acad::eOk)
	{
		return false;
	}

	AcDbObjectId xRecordId;

	pDictionary->getAt(_T("CCNC_Data"), xRecordId);

	pDictionary->close();

	AcDbXrecord *pXrecord;

	if (acdbOpenObject(pXrecord, xRecordId, AcDb::kForRead) != Acad::eOk)
	{
		return false;
	}

	struct resbuf *prbXtn;

	pXrecord->rbChain(&prbXtn);

	pXrecord->close();

	struct resbuf *pTemp;

	pTemp = prbXtn;

	pItextData->m_scale = pTemp->resval.rint;

	pTemp = pTemp->rbnext;

	pItextData->m_unit = pTemp->resval.rint;

	pTemp = pTemp->rbnext;

	pItextData->m_height = pTemp->resval.rreal;

	pTemp = pTemp->rbnext;

	if (pTemp != NULL)
	{
		ads_name ename;

		memcpy(ename, pTemp->resval.rlname, sizeof(ads_name));

		acdbGetObjectId(pItextData->m_drawSpaceId, ename);
	}
	else
	{
		pItextData->m_drawSpaceId = AcDbObjectId::kNull;
	}

	ads_relrb(prbXtn);

	return true;
}

 

 

 

 

0 Likes
Message 3 of 6

Anonymous
Not applicable

thank you! very appriciate, now i found a very strange things. if i not use "sb=rb", and just "acutPrintf(_T("\n对象的属性为:%s"),rb->resval.rstring)", the program is successful, if i used the temporary resbuf "sb", the program error and stop.

0 Likes
Message 4 of 6

Alexander.Rivilis
Mentor
Mentor
Accepted solution

Delete line acutRelRb(sb) because you twice free the same memory.

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

Anonymous
Not applicable
Perfect! it was done like you said, thank you!
0 Likes
Message 6 of 6

Alexander.Rivilis
Mentor
Mentor

@Anonymous wrote:
Perfect! it was done like you said, thank you!

I've reassign Solution as far as you mark your post, which does not contain Solution, instead of my or @BerndCuder8196 post.

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