AcDbDatabase::insert( )

AcDbDatabase::insert( )

Anonymous
Not applicable
1,384 Views
9 Replies
Message 1 of 10

AcDbDatabase::insert( )

Anonymous
Not applicable
Can someone give me an example of this? I'm trying to use the first version
of this:

Acad::ErrorStatus insert(AcDbObjectId& blockId,
const char* pBlockName,
AcDbDatabase* pDb,
bool preserveSourceDatabase = true);

Here is the actual function call:
pCurDb->insert(objId, "chair18", pDbSource);

In case you're not familiar with those arguments, here's what they are:
AcDbObjectId& blockId - output the ID of the block that this function
inserts in your current database.
const char* pBlockName - input the name of the block to be used by the
new block table record in your current database
AcDbDatabase* pDb - input pointer to the source database that contains
the block you wanna read in
preserveSourceDatabase - boolean that determines whether the block read
in is retained in the source database

In my function call, pDbSource is a database that contains just that single
block. When i execute this, however, AutoCAD prints out "Block chair18
references itself" on the command prompt, and does not insert anything.

I also tried to send it some other random string instead of sending
"chair18" as the block name:
pCurDb->insert(objId, "randomString", pDbSource);

In this situation, the block IS read into my current DB. No references are
added in the drawing. When i type in "INSERT" at the command prompt,
"chair18" now shows up as a block that is available to be inserted (rather
than a "randomString" block, as i would expect). I could use the newly
inserted block to programatically insert a reference in my drawing at this
point. I'd really rather not just stick with the "oh well, it works - why
ask questions?" mentality, though - can anyone give me some insight as to
what the heck is going on?
0 Likes
1,385 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
Come on now, i know with all the genius programmers out there that someone's
gotta know how to use this function...

"Justavian" wrote in message
news:[email protected]...
> Can someone give me an example of this? I'm trying to use the first
version
> of this:
>
> Acad::ErrorStatus insert(AcDbObjectId& blockId,
> const char* pBlockName,
> AcDbDatabase* pDb,
> bool preserveSourceDatabase = true);
>
> Here is the actual function call:
> pCurDb->insert(objId, "chair18", pDbSource);
>
> In case you're not familiar with those arguments, here's what they are:
> AcDbObjectId& blockId - output the ID of the block that this function
> inserts in your current database.
> const char* pBlockName - input the name of the block to be used by the
> new block table record in your current database
> AcDbDatabase* pDb - input pointer to the source database that contains
> the block you wanna read in
> preserveSourceDatabase - boolean that determines whether the block
read
> in is retained in the source database
>
> In my function call, pDbSource is a database that contains just that
single
> block. When i execute this, however, AutoCAD prints out "Block chair18
> references itself" on the command prompt, and does not insert anything.
>
> I also tried to send it some other random string instead of sending
> "chair18" as the block name:
> pCurDb->insert(objId, "randomString", pDbSource);
>
> In this situation, the block IS read into my current DB. No references
are
> added in the drawing. When i type in "INSERT" at the command prompt,
> "chair18" now shows up as a block that is available to be inserted (rather
> than a "randomString" block, as i would expect). I could use the newly
> inserted block to programatically insert a reference in my drawing at this
> point. I'd really rather not just stick with the "oh well, it works - why
> ask questions?" mentality, though - can anyone give me some insight as to
> what the heck is going on?
>
>
0 Likes
Message 3 of 10

Anonymous
Not applicable
If you want the easy way do this

acedCommand(RTSTR, "insert", RTSTR, "chair18",RTNONE);


"Justavian" wrote in message
news:[email protected]...
> Come on now, i know with all the genius programmers out there that
someone's
> gotta know how to use this function...
>
> "Justavian" wrote in message
> news:[email protected]...
> > Can someone give me an example of this? I'm trying to use the first
> version
> > of this:
> >
> > Acad::ErrorStatus insert(AcDbObjectId& blockId,
> > const char* pBlockName,
> > AcDbDatabase* pDb,
> > bool preserveSourceDatabase = true);
> >
> > Here is the actual function call:
> > pCurDb->insert(objId, "chair18", pDbSource);
> >
> > In case you're not familiar with those arguments, here's what they are:
> > AcDbObjectId& blockId - output the ID of the block that this
function
> > inserts in your current database.
> > const char* pBlockName - input the name of the block to be used by
the
> > new block table record in your current database
> > AcDbDatabase* pDb - input pointer to the source database that
contains
> > the block you wanna read in
> > preserveSourceDatabase - boolean that determines whether the block
> read
> > in is retained in the source database
> >
> > In my function call, pDbSource is a database that contains just that
> single
> > block. When i execute this, however, AutoCAD prints out "Block chair18
> > references itself" on the command prompt, and does not insert anything.
> >
> > I also tried to send it some other random string instead of sending
> > "chair18" as the block name:
> > pCurDb->insert(objId, "randomString", pDbSource);
> >
> > In this situation, the block IS read into my current DB. No references
> are
> > added in the drawing. When i type in "INSERT" at the command prompt,
> > "chair18" now shows up as a block that is available to be inserted
(rather
> > than a "randomString" block, as i would expect). I could use the newly
> > inserted block to programatically insert a reference in my drawing at
this
> > point. I'd really rather not just stick with the "oh well, it works -
why
> > ask questions?" mentality, though - can anyone give me some insight as
to
> > what the heck is going on?
> >
> >
>
>
0 Likes
Message 4 of 10

Anonymous
Not applicable
Look at the sample app ArxDbg.

Jim Awe
Autodesk, Inc.


"Justavian" wrote in message
news:[email protected]...
> Come on now, i know with all the genius programmers out there that
someone's
> gotta know how to use this function...
>
> "Justavian" wrote in message
> news:[email protected]...
> > Can someone give me an example of this? I'm trying to use the first
> version
> > of this:
> >
> > Acad::ErrorStatus insert(AcDbObjectId& blockId,
> > const char* pBlockName,
> > AcDbDatabase* pDb,
> > bool preserveSourceDatabase = true);
> >
> > Here is the actual function call:
> > pCurDb->insert(objId, "chair18", pDbSource);
> >
> > In case you're not familiar with those arguments, here's what they are:
> > AcDbObjectId& blockId - output the ID of the block that this
function
> > inserts in your current database.
> > const char* pBlockName - input the name of the block to be used by
the
> > new block table record in your current database
> > AcDbDatabase* pDb - input pointer to the source database that
contains
> > the block you wanna read in
> > preserveSourceDatabase - boolean that determines whether the block
> read
> > in is retained in the source database
> >
> > In my function call, pDbSource is a database that contains just that
> single
> > block. When i execute this, however, AutoCAD prints out "Block chair18
> > references itself" on the command prompt, and does not insert anything.
> >
> > I also tried to send it some other random string instead of sending
> > "chair18" as the block name:
> > pCurDb->insert(objId, "randomString", pDbSource);
> >
> > In this situation, the block IS read into my current DB. No references
> are
> > added in the drawing. When i type in "INSERT" at the command prompt,
> > "chair18" now shows up as a block that is available to be inserted
(rather
> > than a "randomString" block, as i would expect). I could use the newly
> > inserted block to programatically insert a reference in my drawing at
this
> > point. I'd really rather not just stick with the "oh well, it works -
why
> > ask questions?" mentality, though - can anyone give me some insight as
to
> > what the heck is going on?
> >
> >
>
>
0 Likes
Message 5 of 10

Anonymous
Not applicable
"Justavian" wrote in
news:[email protected]:

> Come on now, i know with all the genius programmers out there that
> someone's gotta know how to use this function...

You created a block definition from your database, but no block reference.
This is created separately. Lookup AcDbBlockReference.

-
Joel Lucsy ([email protected])
0 Likes
Message 6 of 10

380806348
Community Visitor
Community Visitor

1. You may using file name (Prefix) as your BlockName. Such as XXX.dwg, ..., BlockName="XXX".

2. Your file, such as chair18.dwg, contains the block "chair18".

 

0 Likes
Message 7 of 10

zrobert
Advocate
Advocate

Hi;

 

ObjectARX documentation say;

This function mimics the AutoCAD INSERT command. First a new block table record is created in the database executing this function. This new block table record is given the name pointed to by pBlockName and the blockId argument is filled in with its object ID. Then, all the Model Space entities in the database pointed to by pDb are copied into the new block table record. 

The preserveSourceDatabase argument determines whether the source database pDb is left intact or not. The default value of the argument is true. In that case, objects from the source database are copied to the destination database and the source database is not changed. If the caller passes false for this argument, objects from the source database could be physically moved into the destination database. The latter runs faster, but it leaves the source database dependent on the destination database. The caller should make sure that the source database is deleted either immediately or at least before the destination database is deleted. 

When preserveSourceDatabase is false, the deep clone context is AcDb::kInsert during the cloning that occurs during AcDbDatabase::insert(). When preserveSourceDatabase is true, the deep clone context is AcDb::kInsertCopy during the cloning that occurs during AcDbDatabase::insert(). 

Returns Acad::eOk if operation is successful. 

Returns Acad::eSelfReference (and does not complete the insert process) if the database pointed to by pDb contains a block table record with the name pBlockName, even if that block table record is not referenced by entities in the pDb Model Space.

 

So, the pBlockName argument is not the name of the block you want to "copy" into your destination database, but the name of the block table record created in the destination database and containing all the Model Space entities in the database pointed to by pDb.

0 Likes
Message 8 of 10

zrobert
Advocate
Advocate

If you want to copy an individual named block from database to database, try the overloaded Insert function.

 

Acad::ErrorStatus insert(
    AcDbObjectId& blockId,
    const ACHAR* pSourceBlockName,
    const ACHAR* pDestinationBlockName,
    AcDbDatabase* pDb,
    bool preserveSourceDatabase = true
);

0 Likes
Message 9 of 10

Alexander.Rivilis
Mentor
Mentor

@zrobert 

You did not pay attention that the post of @Anonymous  was written in 2002 (19 years ago) 😉

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

Message 10 of 10

zrobert
Advocate
Advocate

Oops ... yes, I saw the date now... 🤐

0 Likes