Open and close database

Open and close database

nggarnaud
Advocate Advocate
838 Views
3 Replies
Message 1 of 4

Open and close database

nggarnaud
Advocate
Advocate

Dear all,

I have a problem with opening and closing the database in order to create my custom object to it. The .arx loads successfully,  but when i invoke my command i am invite to debug or close the program. AuToCAD 2017 update 1.2 was installed with administrator right.

ARXDbg build fine in VS 2015 community with update 1. No problem at loading in AutoCAD 2017

Can anyone help me with these line of codes?

should i use a void function instead of a AcDbObject createGenerativeLinePrototype function?

What am i missing?

 

Thank you!!!

 

 cDbDatabase * pGenerativeDb;
AcGePoint3d GenerativeStartPoint(5.0, 5.0, 5.0);
AcGePoint3d GenerativeEndPoint(36.0, 36, 36.0);

//GenerativeLinePrototype4 * pGLine04 = new GenerativeLinePrototype4(GenerativeStartPoint, GenerativeEndPoint);

AcDbEntity* pGLine04 = new GenerativeLinePrototype4(GenerativeStartPoint, GenerativeEndPoint);


AcDbBlockTable* pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable, AcDb::kForRead);

AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);


AcDbObjectId GenerativeLinePrototype4Id;
pBlockTable->add(GenerativeLinePrototype4Id, pBlockTableRecord);
pBlockTableRecord->appendAcDbEntity(GenerativeLinePrototype4Id, pGLine04);
pBlockTable->close();
pBlockTableRecord->close();
pGLine04->close();

//pGLine04->objectClosed(GenerativeLinePrototype4Id);
0 Likes
839 Views
3 Replies
Replies (3)
Message 2 of 4

zrobert
Advocate
Advocate

Hi;

 

Try to Open block table for write, not for read.

 

Because you do not use pBlockTable only to access the model space, but later you add GenerativeLinePrototype4Id to pBlockTable .

Message 3 of 4

tbrammer
Advisor
Advisor

Basically your code contains exactly one disastrous wrong line

pBlockTable->add(GenerativeLinePrototype4Id, pBlockTableRecord); 

I think your code should look like this:

 

AcDbDatabase * pGenerativeDb; // <-- What are you doing with this?
AcGePoint3d GenerativeStartPoint(5.0, 5.0, 5.0);
AcGePoint3d GenerativeEndPoint(36.0, 36, 36.0);

AcDbEntity* pGLine04 = new GenerativeLinePrototype4(GenerativeStartPoint, GenerativeEndPoint);

AcDbBlockTable* pBlockTable;
Acad::ErrorStatus es;
es = acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable, AcDb::kForRead);
if (es==Acad::eOk)
{ 
	AcDbBlockTableRecord *pBlockTableRecord;
	es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
	if (es==Acad::eOk)
	{
		 AcDbObjectId GenerativeLinePrototype4Id;
		 //NO!!! You don't want to add to the block table!
		 //pBlockTable->add(GenerativeLinePrototype4Id, pBlockTableRecord); 
		 pBlockTableRecord->appendAcDbEntity(GenerativeLinePrototype4Id, pGLine04);
		 pBlockTableRecord->close();
		 pGLine04->close();
	}
	pBlockTable->close();
}

It is perfectly right to open the block table for read only, because you only use it to open the model space blocktable record.  I only added some error checking.


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Message 4 of 4

nggarnaud
Advocate
Advocate

Thank you all, i will give it a try and come back at you pretty soon.

0 Likes