Author Topic: Inserts Table Generation ?  (Read 12611 times)

0 Members and 1 Guest are viewing this topic.

LE

  • Guest
Inserts Table Generation ?
« on: April 20, 2006, 10:03:08 PM »
All right;

I want, to generate a quantity inserts table [from the current db] and as much I am trying to find why is closing autocad, I just can't... anyway please have a look at the following code, hope other eyes are better than mines....  and let me know where the code is failling...

Thank you in advance!

I am using the AcDbTable Class.

Code: [Select]
static int TableQuantity() {

AcDbTable *pTable = NULL;
pTable = new AcDbTable();

if (pTable->isWriteEnabled()) {

pTable->insertColumns(0,10.0);
pTable->insertColumns(1,10.0);
pTable->insertColumns(2,10.0);
pTable->generateLayout();

//pTable->insertRows(1,10.0);

////pTable->setNumColumns(3);
////pTable->setNumRows(1);
////pTable->generateLayout();

// title
pTable->setTextString(0,0,"Block Quantity");
pTable->setAlignment(0,0,AcDb::kMiddleCenter);
pTable->setTextHeight(0,0,1.65);

// headers
pTable->insertRows(1,10.0);
pTable->generateLayout();

pTable->setTextString(1,0,"Preview");
pTable->setAlignment(1,0,AcDb::kMiddleCenter);
pTable->setTextHeight(1,0,1.65);

pTable->setTextString(1,1,"Name");
pTable->setAlignment(1,1,AcDb::kMiddleCenter);
pTable->setTextHeight(1,1,1.65);

pTable->setTextString(1,2,"Number");
pTable->setAlignment(1,2,AcDb::kMiddleCenter);
pTable->setTextHeight(1,2,1.65);

//pTable->generateLayout();

AcDbBlockTablePointer pBlockTable(CURDB(), AcDb::kForRead);
EOK(pBlockTable.openStatus());
AcDbBlockTableIterator *pBTIterator;
Acad::ErrorStatus es = pBlockTable->newIterator(pBTIterator, true, true);
if (!EOKM(es))
return false;
for (; !pBTIterator->done(); pBTIterator->step()) {
AcDbObjectId BTRId;

es = pBTIterator->getRecordId(BTRId);
if (!EOKM(es)) {
delete pBTIterator;
return false;
}
AcDbBlockTableRecordPointer pBlockTableRecord(BTRId, AcDb::kForRead);
EOK(pBlockTableRecord.openStatus());

// falta filtro para estos bloques "A$C#???????"
// los bloques anidados llevan "|"
if (// no anonymous blocks
pBlockTableRecord->isAnonymous() ||
// no xref's
pBlockTableRecord->isFromExternalReference() ||
// no overlaid xref's
pBlockTableRecord->isFromOverlayReference() ||
// no block layouts *MODEL_SPACE, *PAPER_SPACE...
pBlockTableRecord->isLayout()) {
continue;
}
AcDbBlockTableRecordIterator *pBTRIterator = NULL;
es = pBlockTableRecord->newIterator(pBTRIterator);
if (!EOKM(es))
continue;
const TCHAR *bName;
es = pBlockTableRecord->getName(bName);
if (!EOKM(es)) {
delete pBTIterator;
return false;
}

char text [33];
AcDbObjectIdArray ids;
if (pBlockTableRecord->getBlockReferenceIds(ids) == Acad::eOk) {
//acutPrintf("\nBlock name %s", bName);
//acutPrintf("\nCount %d", ids.length());
int cnt;
cnt = ids.length();
itoa(cnt,text,10);
}

pTable->insertRows(1,10.0);
pTable->generateLayout();

pTable->setBlockTableRecordId(pTable->numRows(),0,BTRId,true);
pTable->setAlignment(pTable->numRows(),0,AcDb::kMiddleCenter);

pTable->setTextString(pTable->numRows(),1,bName);
pTable->setAlignment(pTable->numRows(),1,AcDb::kMiddleCenter);
pTable->setTextHeight(pTable->numRows(),1,1.65);

pTable->setTextString(pTable->numRows(),2,text);
pTable->setAlignment(pTable->numRows(),2,AcDb::kMiddleCenter);
pTable->setTextHeight(pTable->numRows(),2,1.65);

//pTable->generateLayout();
}
delete pBTIterator;

AcDbObjectId curSpaceId=CURDB()->currentSpaceId();
AcDbBlockTableRecord *pBlkRec = NULL;
if (acdbOpenObject(pBlkRec, curSpaceId, AcDb::kForWrite)==Acad::eOk) {
pBlkRec->appendAcDbEntity(pTable);
pBlkRec->close();
pTable->close();
}
}
}

MickD

  • Gator
  • Posts: 3312
  • (x-in)->[process]->(y-out)
Re: Inserts Table Generation ?
« Reply #1 on: April 20, 2006, 10:28:04 PM »
Just a quick guess hile I'm at lunch, try adding the table to the db 'before' adding things and especially before adding things from the database.
Like when extruding a 3d solid, you must add the polyline to the db 'before' you can use it to create the region which must also be added before extruding into a solid.

hth.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #2 on: April 21, 2006, 11:21:09 AM »
Just a quick guess hile I'm at lunch, try adding the table to the db 'before' adding things and especially before adding things from the database.
Like when extruding a 3d solid, you must add the polyline to the db 'before' you can use it to create the region which must also be added before extruding into a solid.

hth.

Thank you Mick,

I am looking right now into the only sample available [the one that comes with the SDK]... it is strange that there is no other one on the net... at least on my search with google and on the adesk forums....

I'll be back....

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #3 on: April 21, 2006, 02:32:50 PM »
As far this is going, what happens is the sequence I had on my original code posted, with the latest tests it is not closing autocad.

In code words, it has to follow something like the following:

Code: [Select]
AcDbTable *pTable = NULL;
pTable = new AcDbTable();

// 2 rows - title and headers
pTable->insertRows(0,10.0);
// 3 columns
pTable->insertColumns(0,10.0,2);

pTable->setTextString(0,0,"TITLE");

// merge the first row for the title
pTable->mergeCells(0,0,0,pTable->numColumns() - 1);

Then, from here we can scan the blocks and add them to the table one row at the time [well, sounds easy, I need to keep doing the testing and find out by myself...]

Have fun,
Luis.

Chuck Gabriel

  • Guest
Re: Inserts Table Generation ?
« Reply #4 on: April 21, 2006, 04:00:31 PM »
...
Like when extruding a 3d solid, you must add the polyline to the db 'before' you can use it to create the region which must also be added before extruding into a solid.

Actually, you CAN create a region from a polyline without adding the polyline to the database first.  Likewise, you can also extrude the region to form a solid without first appending the region to the database.

You need, at some point, to either append the objects to the database or delete them, but you aren't strictly required to append them.

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #5 on: April 21, 2006, 05:10:07 PM »
Update...

I have the function running..... pretty good!!!

It works if first we create the basic table and after re-opening the object and populate the data into the table.

And now, I am going back to try to populate the table before appending it to the DB...


 :-)

MickD

  • Gator
  • Posts: 3312
  • (x-in)->[process]->(y-out)
Re: Inserts Table Generation ?
« Reply #6 on: April 21, 2006, 08:06:53 PM »
You need, at some point, to either append the objects to the database or delete them, but you aren't strictly required to append them.

Yes Chuck, you are correct (as allways :) ). I just remember reading somewhere that they had to be appended otherwise it would fail. Ever since I have created them and erased them. The reason it probably failed was from failing to delete the in memory regions/poly's (?). I'll have to dig that up and have another look.

The point I was trying to get across though was that sometimes things in memory and things not in the db may not play well together(?).
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #7 on: April 21, 2006, 08:10:51 PM »
I tried to do everything before [populate the table]..... and does not work at all, so I end up doing first the table skeleton and after that read all the inserts and pass them into the table, without any problem now, and the user does not have a clue, because it is doing these in a blink of the eye.... [all the table stuff is done in the memory as per the help docs btw]

 :-)

MickD

  • Gator
  • Posts: 3312
  • (x-in)->[process]->(y-out)
Re: Inserts Table Generation ?
« Reply #8 on: April 21, 2006, 08:18:07 PM »
I'm glad you got it working Luis, I may need your advice in these matters very soon :)
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

Chuck Gabriel

  • Guest
Re: Inserts Table Generation ?
« Reply #9 on: April 21, 2006, 08:24:44 PM »
Sorry Mick.  I didn't mean to distract from the point you were making.  It's just that the particular example you gave happened to be something I had actually done recently, so it was fresh in my mind (and you know I can't resist an opportunity to shoot off my mouth).

As for tables, I'm afraid I wouldn't have a clue.  2000i doesn't have them.  Sometimes I worry about my skills becoming outdated due to the fact we'll probably never upgrade.  I'm screwed.

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #10 on: April 21, 2006, 08:33:24 PM »
I'm glad you got it working Luis, I may need your advice in these matters very soon :)

No problem my friend.

 :-)

MickD

  • Gator
  • Posts: 3312
  • (x-in)->[process]->(y-out)
Re: Inserts Table Generation ?
« Reply #11 on: April 21, 2006, 08:39:45 PM »
No need to apologise when you're right Chuck :).

As far as being left behind, most of the things you need to do with the db in later versions are pretty much the same, the biggest difference is with MFC and new 'features' such as Tables.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Inserts Table Generation ?
« Reply #12 on: April 21, 2006, 08:53:28 PM »
......   Sometimes I worry about my skills becoming outdated due to the fact we'll probably never upgrade.  I'm screwed.

I think just keeping the wetware wet puts you ahead of the norm .. anything after that is a bonus

Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #13 on: April 21, 2006, 09:09:45 PM »
Once I get a chance, I will be uploading some portions of the code I came up.... if we are talking about this new objects, just do a search on the net, and see if it is out there a real world sample.... or get into the help or the sample sln that comes in the sdk, pure mickey mouse, nothing good, at all...

The person that types the helps, have no idea or thinks every programmer must be a mind reader or magician to really understand or decipher.... what they are intended to let others know....

 :roll:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Inserts Table Generation ?
« Reply #14 on: April 21, 2006, 09:54:51 PM »
Luis,
Have a look at c:\ObjectARX 2007\samples\entity\Table\
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--