Author Topic: Inserts Table Generation ?  (Read 12888 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: 3314
  • (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: 3314
  • (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: 3314
  • (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: 3314
  • (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<--

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Inserts Table Generation ?
« Reply #15 on: April 21, 2006, 09:58:54 PM »
.. and ditto for 2006
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 #16 on: April 21, 2006, 10:03:25 PM »
It must be the same but updated for the new properties and methods for the AcDbTable Class, I'm still using a2005.

I went and read like 20 or more times the one that comes with SDK 2005, and the only portion of code that was good is the part I used for the merging of the title row area, the rest it is very confused... and intended for blocks with attributes.


Thanks!

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #17 on: April 22, 2006, 11:46:50 AM »
OK, we need code, here is what I end up using and works without any problems:

I am using some macros, to avoid some typing and they are very simple to reproduce, HTH

Code: [Select]
// by www.geometricad.com - LE
static int InsertsTable () {
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);
// headers titles
pTable->setTextString(1,0,"Preview");
pTable->setTextString(1,1,"Name");
pTable->setTextString(1,2,"Number");
if (pTable->generateLayout() == Acad::eOk) {
acutPrintf("\nTable updated.");
AcDbObjectId curSpaceId=CURDB()->currentSpaceId();
AcDbBlockTableRecord *pBlkRec = NULL;
if (acdbOpenObject(pBlkRec, curSpaceId, AcDb::kForWrite)==Acad::eOk) {
pBlkRec->appendAcDbEntity(pTable);
pBlkRec->close();
pTable->close();
}
Acad::ErrorStatus es;
AcDbObjectId objId;
ads_name ename;
acdbEntLast(ename);
acdbGetObjectId(objId,ename);
AcDbObjectPointer<AcDbTable> pTable(objId, AcDb::kForWrite);
if ((es = pTable.openStatus()) == Acad::eOk) {
int row = 2;
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());
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) {
int cnt;
cnt = ids.length();
itoa(cnt,text,10);
}
if (pTable->insertRows(pTable->numRows(), pTable->rowHeight(1)) == Acad::eOk) {
pTable->setBlockTableRecordId(row,0,pBlockTableRecord->objectId(),true);
pTable->setAlignment(row,0,AcDb::kMiddleCenter);
pTable->setTextString(row,1,bName);
pTable->setAlignment(row,1,AcDb::kMiddleCenter);
pTable->setTextHeight(row,1,1.65);
pTable->setTextString(row,2,text);
pTable->setAlignment(row,2,AcDb::kMiddleCenter);
pTable->setTextHeight(row,2,1.65);
} else {
acutPrintf("\nIt is not a TABLE or it can not be opened: %s",
acadErrorStatusText(es));
}
row = (row + 1);
}
delete pBTIterator;
if (pTable->generateLayout() == Acad::eOk) {
acutPrintf("\nTable updated.");
}
}
}
}
« Last Edit: April 22, 2006, 11:56:36 AM by LE »

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #18 on: April 22, 2006, 11:53:41 AM »
And here is the other try to first populate the table and later appending the object into the current data base, but does not work, it produces the table on the drawing, and after some seconds, autocad just close....  :-(

Code: [Select]
//by www.geometricad.com - LE
static int InsertsTable () {
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);
// headers titles
pTable->setTextString(1,0,"Preview");
pTable->setTextString(1,1,"Name");
pTable->setTextString(1,2,"Number");
int row = 2;
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());
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) {
int cnt;
cnt = ids.length();
itoa(cnt,text,10);
}
if ((pTable->insertRows(pTable->numRows(),
pTable->rowHeight(1)) == Acad::eOk) &&
(pTable->generateLayout() == Acad::eOk)) {
pTable->setBlockTableRecordId(row,0,pBlockTableRecord->objectId(),true);
pTable->setAlignment(row,0,AcDb::kMiddleCenter);
pTable->setTextString(row,1,bName);
pTable->setAlignment(row,1,AcDb::kMiddleCenter);
pTable->setTextHeight(row,1,1.65);
pTable->setTextString(row,2,text);
pTable->setAlignment(row,2,AcDb::kMiddleCenter);
pTable->setTextHeight(row,2,1.65);
} else {
acutPrintf("\nIt is not a TABLE or it can not be opened: %s",
acadErrorStatusText(es));
}
row = (row + 1);
}
delete pBTIterator;
//if (pTable->generateLayout() == Acad::eOk) {
// acutPrintf("\nTable updated.");
AcDbObjectId curSpaceId=CURDB()->currentSpaceId();
AcDbBlockTableRecord *pBlkRec = NULL;
if (acdbOpenObject(pBlkRec, curSpaceId, AcDb::kForWrite) == Acad::eOk) {
pBlkRec->appendAcDbEntity(pTable);
pBlkRec->close();
pTable->close();
}
//}
}

Alexander Rivilis

  • Bull Frog
  • Posts: 212
  • Programmer from Kyiv (Ukraine)
Re: Inserts Table Generation ?
« Reply #19 on: April 22, 2006, 02:47:32 PM »
Ohhh, Luis!
Look this code:
Code: [Select]
  static void TableInsertTable(void)
  {
      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);
      // headers titles
      pTable->setTextString(1,0,"Preview");
      pTable->setTextString(1,1,"Name");
      pTable->setTextString(1,2,"Number");
      int row = 2;
      AcDbBlockTablePointer pBlockTable(acdbCurDwg(), AcDb::kForRead);
      if (pBlockTable.openStatus() != Acad::eOk) return;
      AcDbBlockTableIterator *pBTIterator = NULL;
      Acad::ErrorStatus es = pBlockTable->newIterator(pBTIterator, true, true);
      if (es != Acad::eOk || !pBTIterator) {
        acutPrintf("\npBlockTable->newIterator(pBTIterator, true, true)=%s",acadErrorStatusText(es));
        return;
      }
      for (; !pBTIterator->done(); pBTIterator->step()) {
        AcDbObjectId BTRId;
        es = pBTIterator->getRecordId(BTRId);
        if (es != Acad::eOk) {
          acutPrintf("\npBTIterator->getRecordId(BTRId)=%s",acadErrorStatusText(es));
          delete pBTIterator;
          return;
        }
        AcDbBlockTableRecordPointer pBlockTableRecord(BTRId, AcDb::kForRead);
        if (pBlockTableRecord.openStatus() != Acad::eOk) return;
        if (pBlockTableRecord->isAnonymous() || // no anonymous blocks
            pBlockTableRecord->isFromExternalReference() || // no xref's
            pBlockTableRecord->isFromOverlayReference() || // no overlaid xref's
            pBlockTableRecord->isLayout()) { // no block layouts *MODEL_SPACE, *PAPER_SPACE...
            continue;
          }
          const char *bName;
          es = pBlockTableRecord->getName(bName);
          if (es != Acad::eOk) {
            acutPrintf("\npBlockTableRecord->getName(bName)=%s",acadErrorStatusText(es));
            delete pBTIterator;
            return;
          }
          char text [256]="";;
          AcDbObjectIdArray ids;
          if (pBlockTableRecord->getBlockReferenceIds(ids) == Acad::eOk) {
            int cnt;
            cnt = ids.length();
            sprintf(text,"%d",cnt);
          }
          if ((pTable->insertRows(pTable->numRows(),pTable->rowHeight(1)) == Acad::eOk) &&
              (pTable->generateLayout() == Acad::eOk)) {
              pTable->setBlockTableRecordId(row,0,pBlockTableRecord->objectId(),true);
              pTable->setAlignment(row,0,AcDb::kMiddleCenter);
              pTable->setTextString(row,1,bName);
              pTable->setAlignment(row,1,AcDb::kMiddleCenter);
              pTable->setTextHeight(row,1,1.65);
              pTable->setTextString(row,2,text);
              pTable->setAlignment(row,2,AcDb::kMiddleCenter);
              pTable->setTextHeight(row,2,1.65);
            } else {
              acutPrintf("\nIt is not a TABLE or it can not be opened: %s",
                acadErrorStatusText(es));
            }
            row = (row + 1);
      }
      delete pBTIterator;
      //-----------------------------------------------------------
      // You *MUST* close BlockTable before open
      // any BlockTableRecord for Write
      //-----------------------------------------------------------
      pBlockTable->close();
      AcDbObjectId curSpaceId = acdbCurDwg()->currentSpaceId();
      AcDbBlockTableRecord *pBlkRec = NULL;
      if (acdbOpenObject(pBlkRec, curSpaceId, AcDb::kForWrite) == Acad::eOk) {
        pBlkRec->appendAcDbEntity(pTable);
        pBlkRec->close();
        pTable->close();
      }
    }

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #20 on: April 22, 2006, 03:19:17 PM »
Thank you Alexander;

Yes it works!, I notice the lines where you made the changes, I will repass them, so in the future I will be able to write better code,  nice!

I was very close!

Just a minor notice, after running this new function into one command, if you call the command ERASE and by simple picking a point in any part of the screen, without touching the table, this one is selected, you know why?.... if I run the function I had before this does not happen.

Quote
ERASE
Select objects: 1 found

Again thanks.

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #21 on: April 22, 2006, 04:51:16 PM »
Also, is there a chance to get the real number of inserts when using the function: getBlockReferenceIds() as it is being use is not providing the right number of AcDbBlockReferences known as inserts.

Thanks.

Alexander Rivilis

  • Bull Frog
  • Posts: 212
  • Programmer from Kyiv (Ukraine)
Re: Inserts Table Generation ?
« Reply #22 on: April 22, 2006, 05:51:15 PM »
IMHO It is look like AutoCAD bug. It is interesting that if you comment this code:
Code: [Select]
//  pTable->setBlockTableRecordId(row,0,blkId,true);
command ERASE nоt picked this table in other part of screen. Sometimes after REGENALL or MOVE this table - it is look ok, sometimes no... :(
Quote
Also, is there a chance to get the real number of inserts when using the function: getBlockReferenceIds() as it is being use is not providing the right number of AcDbBlockReferences known as inserts.
I have not any problem with getBlockReferenceIds(). If you have INSERT in other block and need to culculate it - try getBlockReferenceIds(ids, false);

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #23 on: April 22, 2006, 06:11:20 PM »
[getBlockReferenceIds(ids, false);

Nope;

It is not giving the right number of blocks.... every time I ran the routine, it gives a different number....  :-(

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #24 on: April 22, 2006, 11:43:47 PM »
Enough for today on this, to be continue

LE

Alexander Rivilis

  • Bull Frog
  • Posts: 212
  • Programmer from Kyiv (Ukraine)
Re: Inserts Table Generation ?
« Reply #25 on: April 23, 2006, 05:36:09 AM »
[getBlockReferenceIds(ids, false);

Nope;

It is not giving the right number of blocks.... every time I ran the routine, it gives a different number....  :-(

Code: [Select]
      AcDbObjectId  modelSpaceId, paperSpaceId;
      pBlockTable->getAt(ACDB_MODEL_SPACE, modelSpaceId);
      pBlockTable->getAt(ACDB_PAPER_SPACE, paperSpaceId);
      pBlockTable->close();

Code: [Select]
        char text [256]="";
        AcDbObjectIdArray ids;
        if (pBlockTableRecord->getBlockReferenceIds(ids) == Acad::eOk) {
          int cnt = 0;
          for (int i=0; i < ids.length(); i++) {
            AcDbObjectPointer<AcDbBlockReference> pRef(ids[i],kForRead);
            if (pRef.openStatus() == Acad::eOk &&
               (pRef->blockId() == modelSpaceId || pRef->blockId() == paperSpaceId)) {
              cnt++;                 
            }
          }
          sprintf(text,"%d",cnt);
        }

Other words - getBlockReferenceIds also calculate references to blocks in your's table. With this code we calculate only references in model and paper spaces.

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #26 on: April 23, 2006, 11:22:52 AM »
Quote
Other words - getBlockReferenceIds also calculate references to blocks in your's table. With this code we calculate only references in model and paper spaces.

Thanks!

Is now providing the right number of inserts...  :-)

Alexander Rivilis

  • Bull Frog
  • Posts: 212
  • Programmer from Kyiv (Ukraine)
Re: Inserts Table Generation ?
« Reply #27 on: April 23, 2006, 12:59:11 PM »
Is now providing the right number of inserts...  :-)
Yes for my test dwg-file. Try with your's. :)
Another solution:
Code: [Select]
        char text [256]="";
        AcDbObjectIdArray ids;
        if (pBlockTableRecord->getBlockReferenceIds(ids) == Acad::eOk) {
          int cnt = 0;
          for (int i=0; i < ids.length(); i++) {
            AcDbObjectPointer<AcDbBlockReference> pRef(ids[i],AcDb::kForRead);
            if (pRef.openStatus() == Acad::eOk) {
              AcDbBlockTableRecordPointer pBtr(pRef->blockId(),AcDb::kForRead);
              if (pBtr.openStatus() == Acad::eOk && pBtr->isLayout()) {
                cnt++;                 
              }
            }
          }
          sprintf(text,"%d",cnt);
        }
« Last Edit: April 23, 2006, 01:19:07 PM by Rivilis »

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #28 on: April 23, 2006, 03:31:16 PM »
Code: [Select]
        char text [256]="";
        AcDbObjectIdArray ids;
        if (pBlockTableRecord->getBlockReferenceIds(ids) == Acad::eOk) {
          int cnt = 0;
          for (int i=0; i < ids.length(); i++) {
            AcDbObjectPointer<AcDbBlockReference> pRef(ids[i],AcDb::kForRead);
            if (pRef.openStatus() == Acad::eOk) {
              AcDbBlockTableRecordPointer pBtr(pRef->blockId(),AcDb::kForRead);
              if (pBtr.openStatus() == Acad::eOk && pBtr->isLayout()) {
                cnt++;                 
              }
            }
          }
          sprintf(text,"%d",cnt);
        }

I like it.... I will use this instead...  Thanks!

A question.... I had on my code the same names for two variables [the ones in blue], is there any problems by doing that.... so far I am running the routine and it is working pretty good!

Quote
      AcDbObjectPointer<AcDbBlockReference> pRef(objId,AcDb::kForRead);
      if (pRef.openStatus() == Acad::eOk) {
         AcDbBlockTableRecordPointer pBtr(pRef->blockTableRecord(),AcDb::kForRead);
         if ((pBtr.openStatus () == Acad::eOk) &&
            // filter xref's and overlaid xref's
            (!pBtr->isFromExternalReference() ||
            !pBtr->isFromOverlayReference())) {
               const char *bName;
               es = pBtr->getName(bName);
               if (es != Acad::eOk) {
                  acutPrintf("\nBlock name error =%s",acadErrorStatusText(es));
                  return;
               }
               char text [256]="";
               AcDbObjectIdArray ids;
               if (pBtr->getBlockReferenceIds(ids) == Acad::eOk) {
                  int cnt = 0;
                  for (int i=0; i < ids.length(); i++) {            
                     AcDbObjectPointer<AcDbBlockReference> pRef(ids,AcDb::kForRead);
                     if (pRef.openStatus() == Acad::eOk) {
                        AcDbBlockTableRecordPointer pBtr(pRef->blockId(),AcDb::kForRead);
                        if (pBtr.openStatus() == Acad::eOk && pBtr->isLayout()) {
                           cnt++;
                        }
                     }
                  }
                  sprintf(text,"%d",cnt);
               }

Alexander Rivilis

  • Bull Frog
  • Posts: 212
  • Programmer from Kyiv (Ukraine)
Re: Inserts Table Generation ?
« Reply #29 on: April 23, 2006, 04:48:27 PM »
Quote
A question.... I had on my code the same names for two variables [the ones in blue], is there any problems by doing that.... so far I am running the routine and it is working pretty good!
No problem. :) These variables has different "area of visibility". It is described in any C++ handbook. Read it!

LE

  • Guest
Re: Inserts Table Generation ?
« Reply #30 on: April 23, 2006, 09:30:52 PM »
These variables has different "area of visibility". It is described in any C++ handbook. Read it!

Got it!

 :kewl: