wblockCloneObjects

wblockCloneObjects

Anonymous
Not applicable
2,332 Views
15 Replies
Message 1 of 16

wblockCloneObjects

Anonymous
Not applicable
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
2,333 Views
15 Replies
Replies (15)
Message 2 of 16

Anonymous
Not applicable
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 3 of 16

Anonymous
Not applicable
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 4 of 16

Anonymous
Not applicable
Hi Art,

So, you say: skip the IDMapping check?

Thank you for your reply.

Moshe

"Art Cooney" wrote in message
news:[email protected]...
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 5 of 16

Anonymous
Not applicable
No, I didn't say that. I have no idea why you are iterating the idMap and
checking isCloned() on each idPair, so I won't presume to tell you not to do
that. All I'm saying is that you can't expect all idPairs in the idMap to
be cloned.


"Moshe" wrote in message
news:[email protected]...
Hi Art,

So, you say: skip the IDMapping check?

Thank you for your reply.

Moshe

"Art Cooney" wrote in message
news:[email protected]...
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 6 of 16

Anonymous
Not applicable
Every AcDbIdPair in the map will have both a key and a value if you used
wblockcloneobjects. There's no need to worry about whether AutoCAD just
randomly ignored some of the ids you sent in. If there's a problem, wblock
will return an error. As Art pointed out, some of the objects might NOT be
cloned - but AutoCAD will still populate the map with the ID it translated
to. In other words, the value( ) will report the existing object id in the
destination drawing (like the NOD in Art's example), while the AcDbIdPairs
for cloned objects will report the new id that was created.

I use wblockcloneobjects extensively, but i've never gone through the map
and asked whether things were cloned.

-Rich


"Moshe" wrote in message
news:[email protected]...
Hi Art,

So, you say: skip the IDMapping check?

Thank you for your reply.

Moshe

"Art Cooney" wrote in message
news:[email protected]...
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 7 of 16

Anonymous
Not applicable
Rich Hi

Do I need to check, and How?

Remember, i'am using wblockCloneObject for rewrite Block & WBlock.
I have finished Block Command and now I started WBlock

Can i be sure that:
AcDbdatabase::wblock()
AcDbdatabase::wblockClone()
AcDbdatabase::wblockCloneObject()

is doing a full clone? what objects are skipped?
the objects i have to clone are only standard autocad objects, no custom
objects exist?

Thank you very much for your time

Moshe

"Justavian" wrote in message
news:[email protected]...
Every AcDbIdPair in the map will have both a key and a value if you used
wblockcloneobjects. There's no need to worry about whether AutoCAD just
randomly ignored some of the ids you sent in. If there's a problem, wblock
will return an error. As Art pointed out, some of the objects might NOT be
cloned - but AutoCAD will still populate the map with the ID it translated
to. In other words, the value( ) will report the existing object id in the
destination drawing (like the NOD in Art's example), while the AcDbIdPairs
for cloned objects will report the new id that was created.

I use wblockcloneobjects extensively, but i've never gone through the map
and asked whether things were cloned.

-Rich


"Moshe" wrote in message
news:[email protected]...
Hi Art,

So, you say: skip the IDMapping check?

Thank you for your reply.

Moshe

"Art Cooney" wrote in message
news:[email protected]...
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 8 of 16

Anonymous
Not applicable
What is the goal? Why do you want to know if it was cloned or not? As
specified previously, AutoCAD WILL ensure that everything requied has been
copied. Not only that, if w're talking about entities (as opposed to
symbols), it will either work or it won't. So if you try to copy a whole
series of lines and arcs and what not - the system isn't going to randomly
leave some of them out. You can be sure that the destination will contain
everything you need. Maybe i still don't really understand why you need to
know if there was a "full clone". If one of the objects you're copying
requires a layer, it WILL be in the destination drawing (and in the id map).
It will either copy the one from the source (if it doesn't exist in the
destination, or if you specify that AcDb::kDrcReplace), or it will use the
one that's already there.

I think that you might be confused. The isCloned( ) method does NOT
indicate that the function failed! It merely tells you that there was no
need to clone that item, since it already existed in the destination. So
back to the layer example. Say you're copying some items which reside on
the "SOME_LINES" layer. If the destination drawing also has a layer called
"SOME_LINES", AutoCAD will not clone the layer (all it checks is the name -
those layers might be different colors or use different linetypes). So the
map will contain an AcDbIdPair with the source AcDbObjectId for the
SOME_LINES layer, and the value() for that pair will be the existing
SOME_LINES id in the destination.

I'm also not sure about what you're asking with the three different
functions you listed. Remember that AcDbDatabase::wblock( ) doesn't use a
map (at least not directly), so you'd need to implement an editor reactor or
event reactor to catch the translated map. There doesn't seem to be a
AcDbDatabase::wblockClone() - just wblock() and wblockCloneObjects() (though
there is an AcDbObject::wblockClone). In my apps i only use the latter,
since that lets me have more control over what's happening. However,
wblock() actually just calls wblockCloneObjects()

I've used wblockCloneObjects to essentially completely reconstitue an entire
database, and i've never once had problems with things not being properly
cloned (other than my own coding mistakes). The only scenario that i can
imagine which would cause problems is if custom objects didn't have
ownerships or pointers set up correctly (since AutoCAD uses the
AcDbHardOwnershipId, AcDbHardPointerId, etc to determine what items are
required during the clone).

Sorry, this response rambles a little - but maybe somewhere in there i said
something that helped!


-Rich


"Moshe" wrote in message
news:[email protected]...
Rich Hi

Do I need to check, and How?

Remember, i'am using wblockCloneObject for rewrite Block & WBlock.
I have finished Block Command and now I started WBlock

Can i be sure that:
AcDbdatabase::wblock()
AcDbdatabase::wblockClone()
AcDbdatabase::wblockCloneObject()

is doing a full clone? what objects are skipped?
the objects i have to clone are only standard autocad objects, no custom
objects exist?

Thank you very much for your time

Moshe

"Justavian" wrote in message
news:[email protected]...
Every AcDbIdPair in the map will have both a key and a value if you used
wblockcloneobjects. There's no need to worry about whether AutoCAD just
randomly ignored some of the ids you sent in. If there's a problem, wblock
will return an error. As Art pointed out, some of the objects might NOT be
cloned - but AutoCAD will still populate the map with the ID it translated
to. In other words, the value( ) will report the existing object id in the
destination drawing (like the NOD in Art's example), while the AcDbIdPairs
for cloned objects will report the new id that was created.

I use wblockcloneobjects extensively, but i've never gone through the map
and asked whether things were cloned.

-Rich


"Moshe" wrote in message
news:[email protected]...
Hi Art,

So, you say: skip the IDMapping check?

Thank you for your reply.

Moshe

"Art Cooney" wrote in message
news:[email protected]...
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 9 of 16

Anonymous
Not applicable
Rich,

the goal was to make sure that every thing is cloned, now i understand the
meaning of isCloned() method.
but i fail in rewrite a WBlock command with wblockCloneObjects()

can you send me a simple code of wblockCloneObjects() to wblock a full
database
can you add how to set the AcDbHardOwnershipId, and or AcDbHardPointerId on
AcDbGroup so it will be also cloned
on the owner database

Thank you very much

Moshe


"Justavian" wrote in message
news:[email protected]...
What is the goal? Why do you want to know if it was cloned or not? As
specified previously, AutoCAD WILL ensure that everything requied has been
copied. Not only that, if w're talking about entities (as opposed to
symbols), it will either work or it won't. So if you try to copy a whole
series of lines and arcs and what not - the system isn't going to randomly
leave some of them out. You can be sure that the destination will contain
everything you need. Maybe i still don't really understand why you need to
know if there was a "full clone". If one of the objects you're copying
requires a layer, it WILL be in the destination drawing (and in the id map).
It will either copy the one from the source (if it doesn't exist in the
destination, or if you specify that AcDb::kDrcReplace), or it will use the
one that's already there.

I think that you might be confused. The isCloned( ) method does NOT
indicate that the function failed! It merely tells you that there was no
need to clone that item, since it already existed in the destination. So
back to the layer example. Say you're copying some items which reside on
the "SOME_LINES" layer. If the destination drawing also has a layer called
"SOME_LINES", AutoCAD will not clone the layer (all it checks is the name -
those layers might be different colors or use different linetypes). So the
map will contain an AcDbIdPair with the source AcDbObjectId for the
SOME_LINES layer, and the value() for that pair will be the existing
SOME_LINES id in the destination.

I'm also not sure about what you're asking with the three different
functions you listed. Remember that AcDbDatabase::wblock( ) doesn't use a
map (at least not directly), so you'd need to implement an editor reactor or
event reactor to catch the translated map. There doesn't seem to be a
AcDbDatabase::wblockClone() - just wblock() and wblockCloneObjects() (though
there is an AcDbObject::wblockClone). In my apps i only use the latter,
since that lets me have more control over what's happening. However,
wblock() actually just calls wblockCloneObjects()

I've used wblockCloneObjects to essentially completely reconstitue an entire
database, and i've never once had problems with things not being properly
cloned (other than my own coding mistakes). The only scenario that i can
imagine which would cause problems is if custom objects didn't have
ownerships or pointers set up correctly (since AutoCAD uses the
AcDbHardOwnershipId, AcDbHardPointerId, etc to determine what items are
required during the clone).

Sorry, this response rambles a little - but maybe somewhere in there i said
something that helped!


-Rich


"Moshe" wrote in message
news:[email protected]...
Rich Hi

Do I need to check, and How?

Remember, i'am using wblockCloneObject for rewrite Block & WBlock.
I have finished Block Command and now I started WBlock

Can i be sure that:
AcDbdatabase::wblock()
AcDbdatabase::wblockClone()
AcDbdatabase::wblockCloneObject()

is doing a full clone? what objects are skipped?
the objects i have to clone are only standard autocad objects, no custom
objects exist?

Thank you very much for your time

Moshe

"Justavian" wrote in message
news:[email protected]...
Every AcDbIdPair in the map will have both a key and a value if you used
wblockcloneobjects. There's no need to worry about whether AutoCAD just
randomly ignored some of the ids you sent in. If there's a problem, wblock
will return an error. As Art pointed out, some of the objects might NOT be
cloned - but AutoCAD will still populate the map with the ID it translated
to. In other words, the value( ) will report the existing object id in the
destination drawing (like the NOD in Art's example), while the AcDbIdPairs
for cloned objects will report the new id that was created.

I use wblockcloneobjects extensively, but i've never gone through the map
and asked whether things were cloned.

-Rich


"Moshe" wrote in message
news:[email protected]...
Hi Art,

So, you say: skip the IDMapping check?

Thank you for your reply.

Moshe

"Art Cooney" wrote in message
news:[email protected]...
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 10 of 16

Anonymous
Not applicable
> can you send me a simple code of wblockCloneObjects() to wblock a full
> database

A simple code? Ha! There's a dozen different symbol tables that have to be
cloned in order to clone a whole database - it's not simple. It looked to
me like you were on the right track, if you're just cloning entities (and
their dependencies). If you need to clone layers that are NOT automatically
cloned (say, for example, an empty layer), then you send those ids to
wblockCloneObjects, and the destination layer table. Very similar to
entities.

And as to the hardownership stuff, if you file out a hardownershipid during
any dwgOutFields( ), AutoCAD should see that as a required object and clone
it as well. But if you don't want to do that, then you need to make another
call to wblockCloneObjects( ) with the object id(s) of the group(s), and the
destination dictionary.

Try it out. If you can't get it to work, post the code and i'll help you
track down the problem.

-Rich



"Moshe" wrote in message
news:[email protected]...
Rich,

the goal was to make sure that every thing is cloned, now i understand the
meaning of isCloned() method.
but i fail in rewrite a WBlock command with wblockCloneObjects()

can you send me a simple code of wblockCloneObjects() to wblock a full
database
can you add how to set the AcDbHardOwnershipId, and or AcDbHardPointerId on
AcDbGroup so it will be also cloned
on the owner database

Thank you very much

Moshe


"Justavian" wrote in message
news:[email protected]...
What is the goal? Why do you want to know if it was cloned or not? As
specified previously, AutoCAD WILL ensure that everything requied has been
copied. Not only that, if w're talking about entities (as opposed to
symbols), it will either work or it won't. So if you try to copy a whole
series of lines and arcs and what not - the system isn't going to randomly
leave some of them out. You can be sure that the destination will contain
everything you need. Maybe i still don't really understand why you need to
know if there was a "full clone". If one of the objects you're copying
requires a layer, it WILL be in the destination drawing (and in the id map).
It will either copy the one from the source (if it doesn't exist in the
destination, or if you specify that AcDb::kDrcReplace), or it will use the
one that's already there.

I think that you might be confused. The isCloned( ) method does NOT
indicate that the function failed! It merely tells you that there was no
need to clone that item, since it already existed in the destination. So
back to the layer example. Say you're copying some items which reside on
the "SOME_LINES" layer. If the destination drawing also has a layer called
"SOME_LINES", AutoCAD will not clone the layer (all it checks is the name -
those layers might be different colors or use different linetypes). So the
map will contain an AcDbIdPair with the source AcDbObjectId for the
SOME_LINES layer, and the value() for that pair will be the existing
SOME_LINES id in the destination.

I'm also not sure about what you're asking with the three different
functions you listed. Remember that AcDbDatabase::wblock( ) doesn't use a
map (at least not directly), so you'd need to implement an editor reactor or
event reactor to catch the translated map. There doesn't seem to be a
AcDbDatabase::wblockClone() - just wblock() and wblockCloneObjects() (though
there is an AcDbObject::wblockClone). In my apps i only use the latter,
since that lets me have more control over what's happening. However,
wblock() actually just calls wblockCloneObjects()

I've used wblockCloneObjects to essentially completely reconstitue an entire
database, and i've never once had problems with things not being properly
cloned (other than my own coding mistakes). The only scenario that i can
imagine which would cause problems is if custom objects didn't have
ownerships or pointers set up correctly (since AutoCAD uses the
AcDbHardOwnershipId, AcDbHardPointerId, etc to determine what items are
required during the clone).

Sorry, this response rambles a little - but maybe somewhere in there i said
something that helped!


-Rich


"Moshe" wrote in message
news:[email protected]...
Rich Hi

Do I need to check, and How?

Remember, i'am using wblockCloneObject for rewrite Block & WBlock.
I have finished Block Command and now I started WBlock

Can i be sure that:
AcDbdatabase::wblock()
AcDbdatabase::wblockClone()
AcDbdatabase::wblockCloneObject()

is doing a full clone? what objects are skipped?
the objects i have to clone are only standard autocad objects, no custom
objects exist?

Thank you very much for your time

Moshe

"Justavian" wrote in message
news:[email protected]...
Every AcDbIdPair in the map will have both a key and a value if you used
wblockcloneobjects. There's no need to worry about whether AutoCAD just
randomly ignored some of the ids you sent in. If there's a problem, wblock
will return an error. As Art pointed out, some of the objects might NOT be
cloned - but AutoCAD will still populate the map with the ID it translated
to. In other words, the value( ) will report the existing object id in the
destination drawing (like the NOD in Art's example), while the AcDbIdPairs
for cloned objects will report the new id that was created.

I use wblockcloneobjects extensively, but i've never gone through the map
and asked whether things were cloned.

-Rich


"Moshe" wrote in message
news:[email protected]...
Hi Art,

So, you say: skip the IDMapping check?

Thank you for your reply.

Moshe

"Art Cooney" wrote in message
news:[email protected]...
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 11 of 16

Anonymous
Not applicable
Rich,

As i said I tried to write and fail but with your help i going to try it
again

1. About ACDB_MODEL_SPACE: is it enough to Iterate it and
AcDbObject::wblockClone() each object and this will take
evrey table that is need (Blocks, Layers, Ltypes, TextStyle,
DimStyle, PageSetup) I don't mind about unused tables
(same as WBlock standard command don't).

2. About the AcDbGroup: untill now i didn't need to use groups
so hard/soft ownership/pointers are all new to me need more
help on this

3. Next week I will rewrite the new code & if it fails again. send you the
code

Thanx

Moshe


"Justavian" wrote in message
news:[email protected]...
> can you send me a simple code of wblockCloneObjects() to wblock a full
> database

A simple code? Ha! There's a dozen different symbol tables that have to be
cloned in order to clone a whole database - it's not simple. It looked to
me like you were on the right track, if you're just cloning entities (and
their dependencies). If you need to clone layers that are NOT automatically
cloned (say, for example, an empty layer), then you send those ids to
wblockCloneObjects, and the destination layer table. Very similar to
entities.

And as to the hardownership stuff, if you file out a hardownershipid during
any dwgOutFields( ), AutoCAD should see that as a required object and clone
it as well. But if you don't want to do that, then you need to make another
call to wblockCloneObjects( ) with the object id(s) of the group(s), and the
destination dictionary.

Try it out. If you can't get it to work, post the code and i'll help you
track down the problem.

-Rich



"Moshe" wrote in message
news:[email protected]...
Rich,

the goal was to make sure that every thing is cloned, now i understand the
meaning of isCloned() method.
but i fail in rewrite a WBlock command with wblockCloneObjects()

can you send me a simple code of wblockCloneObjects() to wblock a full
database
can you add how to set the AcDbHardOwnershipId, and or AcDbHardPointerId on
AcDbGroup so it will be also cloned
on the owner database

Thank you very much

Moshe


"Justavian" wrote in message
news:[email protected]...
What is the goal? Why do you want to know if it was cloned or not? As
specified previously, AutoCAD WILL ensure that everything requied has been
copied. Not only that, if w're talking about entities (as opposed to
symbols), it will either work or it won't. So if you try to copy a whole
series of lines and arcs and what not - the system isn't going to randomly
leave some of them out. You can be sure that the destination will contain
everything you need. Maybe i still don't really understand why you need to
know if there was a "full clone". If one of the objects you're copying
requires a layer, it WILL be in the destination drawing (and in the id map).
It will either copy the one from the source (if it doesn't exist in the
destination, or if you specify that AcDb::kDrcReplace), or it will use the
one that's already there.

I think that you might be confused. The isCloned( ) method does NOT
indicate that the function failed! It merely tells you that there was no
need to clone that item, since it already existed in the destination. So
back to the layer example. Say you're copying some items which reside on
the "SOME_LINES" layer. If the destination drawing also has a layer called
"SOME_LINES", AutoCAD will not clone the layer (all it checks is the name -
those layers might be different colors or use different linetypes). So the
map will contain an AcDbIdPair with the source AcDbObjectId for the
SOME_LINES layer, and the value() for that pair will be the existing
SOME_LINES id in the destination.

I'm also not sure about what you're asking with the three different
functions you listed. Remember that AcDbDatabase::wblock( ) doesn't use a
map (at least not directly), so you'd need to implement an editor reactor or
event reactor to catch the translated map. There doesn't seem to be a
AcDbDatabase::wblockClone() - just wblock() and wblockCloneObjects() (though
there is an AcDbObject::wblockClone). In my apps i only use the latter,
since that lets me have more control over what's happening. However,
wblock() actually just calls wblockCloneObjects()

I've used wblockCloneObjects to essentially completely reconstitue an entire
database, and i've never once had problems with things not being properly
cloned (other than my own coding mistakes). The only scenario that i can
imagine which would cause problems is if custom objects didn't have
ownerships or pointers set up correctly (since AutoCAD uses the
AcDbHardOwnershipId, AcDbHardPointerId, etc to determine what items are
required during the clone).

Sorry, this response rambles a little - but maybe somewhere in there i said
something that helped!


-Rich


"Moshe" wrote in message
news:[email protected]...
Rich Hi

Do I need to check, and How?

Remember, i'am using wblockCloneObject for rewrite Block & WBlock.
I have finished Block Command and now I started WBlock

Can i be sure that:
AcDbdatabase::wblock()
AcDbdatabase::wblockClone()
AcDbdatabase::wblockCloneObject()

is doing a full clone? what objects are skipped?
the objects i have to clone are only standard autocad objects, no custom
objects exist?

Thank you very much for your time

Moshe

"Justavian" wrote in message
news:[email protected]...
Every AcDbIdPair in the map will have both a key and a value if you used
wblockcloneobjects. There's no need to worry about whether AutoCAD just
randomly ignored some of the ids you sent in. If there's a problem, wblock
will return an error. As Art pointed out, some of the objects might NOT be
cloned - but AutoCAD will still populate the map with the ID it translated
to. In other words, the value( ) will report the existing object id in the
destination drawing (like the NOD in Art's example), while the AcDbIdPairs
for cloned objects will report the new id that was created.

I use wblockcloneobjects extensively, but i've never gone through the map
and asked whether things were cloned.

-Rich


"Moshe" wrote in message
news:[email protected]...
Hi Art,

So, you say: skip the IDMapping check?

Thank you for your reply.

Moshe

"Art Cooney" wrote in message
news:[email protected]...
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 12 of 16

Anonymous
Not applicable
Rich

I now recall that in the last code i wrote I wblockClone()
Lines + Attdefs and the new database was lake the TextStyle
as soon as i touch the attdef autocad crashed.

Moshe


"Justavian" wrote in message
news:[email protected]...
> can you send me a simple code of wblockCloneObjects() to wblock a full
> database

A simple code? Ha! There's a dozen different symbol tables that have to be
cloned in order to clone a whole database - it's not simple. It looked to
me like you were on the right track, if you're just cloning entities (and
their dependencies). If you need to clone layers that are NOT automatically
cloned (say, for example, an empty layer), then you send those ids to
wblockCloneObjects, and the destination layer table. Very similar to
entities.

And as to the hardownership stuff, if you file out a hardownershipid during
any dwgOutFields( ), AutoCAD should see that as a required object and clone
it as well. But if you don't want to do that, then you need to make another
call to wblockCloneObjects( ) with the object id(s) of the group(s), and the
destination dictionary.

Try it out. If you can't get it to work, post the code and i'll help you
track down the problem.

-Rich



"Moshe" wrote in message
news:[email protected]...
Rich,

the goal was to make sure that every thing is cloned, now i understand the
meaning of isCloned() method.
but i fail in rewrite a WBlock command with wblockCloneObjects()

can you send me a simple code of wblockCloneObjects() to wblock a full
database
can you add how to set the AcDbHardOwnershipId, and or AcDbHardPointerId on
AcDbGroup so it will be also cloned
on the owner database

Thank you very much

Moshe


"Justavian" wrote in message
news:[email protected]...
What is the goal? Why do you want to know if it was cloned or not? As
specified previously, AutoCAD WILL ensure that everything requied has been
copied. Not only that, if w're talking about entities (as opposed to
symbols), it will either work or it won't. So if you try to copy a whole
series of lines and arcs and what not - the system isn't going to randomly
leave some of them out. You can be sure that the destination will contain
everything you need. Maybe i still don't really understand why you need to
know if there was a "full clone". If one of the objects you're copying
requires a layer, it WILL be in the destination drawing (and in the id map).
It will either copy the one from the source (if it doesn't exist in the
destination, or if you specify that AcDb::kDrcReplace), or it will use the
one that's already there.

I think that you might be confused. The isCloned( ) method does NOT
indicate that the function failed! It merely tells you that there was no
need to clone that item, since it already existed in the destination. So
back to the layer example. Say you're copying some items which reside on
the "SOME_LINES" layer. If the destination drawing also has a layer called
"SOME_LINES", AutoCAD will not clone the layer (all it checks is the name -
those layers might be different colors or use different linetypes). So the
map will contain an AcDbIdPair with the source AcDbObjectId for the
SOME_LINES layer, and the value() for that pair will be the existing
SOME_LINES id in the destination.

I'm also not sure about what you're asking with the three different
functions you listed. Remember that AcDbDatabase::wblock( ) doesn't use a
map (at least not directly), so you'd need to implement an editor reactor or
event reactor to catch the translated map. There doesn't seem to be a
AcDbDatabase::wblockClone() - just wblock() and wblockCloneObjects() (though
there is an AcDbObject::wblockClone). In my apps i only use the latter,
since that lets me have more control over what's happening. However,
wblock() actually just calls wblockCloneObjects()

I've used wblockCloneObjects to essentially completely reconstitue an entire
database, and i've never once had problems with things not being properly
cloned (other than my own coding mistakes). The only scenario that i can
imagine which would cause problems is if custom objects didn't have
ownerships or pointers set up correctly (since AutoCAD uses the
AcDbHardOwnershipId, AcDbHardPointerId, etc to determine what items are
required during the clone).

Sorry, this response rambles a little - but maybe somewhere in there i said
something that helped!


-Rich


"Moshe" wrote in message
news:[email protected]...
Rich Hi

Do I need to check, and How?

Remember, i'am using wblockCloneObject for rewrite Block & WBlock.
I have finished Block Command and now I started WBlock

Can i be sure that:
AcDbdatabase::wblock()
AcDbdatabase::wblockClone()
AcDbdatabase::wblockCloneObject()

is doing a full clone? what objects are skipped?
the objects i have to clone are only standard autocad objects, no custom
objects exist?

Thank you very much for your time

Moshe

"Justavian" wrote in message
news:[email protected]...
Every AcDbIdPair in the map will have both a key and a value if you used
wblockcloneobjects. There's no need to worry about whether AutoCAD just
randomly ignored some of the ids you sent in. If there's a problem, wblock
will return an error. As Art pointed out, some of the objects might NOT be
cloned - but AutoCAD will still populate the map with the ID it translated
to. In other words, the value( ) will report the existing object id in the
destination drawing (like the NOD in Art's example), while the AcDbIdPairs
for cloned objects will report the new id that was created.

I use wblockcloneobjects extensively, but i've never gone through the map
and asked whether things were cloned.

-Rich


"Moshe" wrote in message
news:[email protected]...
Hi Art,

So, you say: skip the IDMapping check?

Thank you for your reply.

Moshe

"Art Cooney" wrote in message
news:[email protected]...
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 13 of 16

Anonymous
Not applicable
You don't want to do the cloning yourself. Well, at least i don't think you
do! You should be using wblockCloneObjects( ). After looking at your code
i realized that there's at least one thing missing - you need to call
AcDbIdMapping::setDestDb( ) prior to any call to the wblockCloneObjects( ).
Here is a working example i just wrote that's doing something like yours (i
didn't try your code). This example will copy some selected entities (and
their dependencies, of course) to a new drawing, or to an existing drawing -
depending on what the boolean var at the top says.

Note that i check virtually every returned status for an error! This is a
good habit to get into. Granted, it's usually overkill. But if you try to
open an object and it fails, trying to access it a step later is going to
cause AutoCAD to crash. Better to just check everything.


// Clone the selected objects from the current document into some other
drawing.
// 1) Get some things to copy.
// 2) Open the destination drawing.
// 3) Retrieve the destination parent - in this case model space.
// 4) Set up the map.
// 5) Perform the clone.
// 6) Save the destination drawing.

Acad::ErrorStatus es;
CString sDestDwg("C:\\CopyToDwg.dwg");
bool bMakeNewDwg = true;

/***********************************************************************
STEP 1 - Get some things to copy
***********************************************************************/
ads_name ssSel;
long nRtCode = acedSSGet(NULL, NULL, NULL, NULL, ssSel);
if(nRtCode != RTNORM)
return;

long sslength;
acedSSLength(ssSel, &sslength);

AcDbObjectIdArray idsSel;
for(int i = 0; i {
ads_name ent;
acedSSName(ssSel, i, ent);

AcDbObjectId objId;
acdbGetObjectId(objId, ent);

idsSel.append(objId);
}
acedSSFree(ssSel);


/***********************************************************************
STEP 2 - Open the destination drawing.
***********************************************************************/
AcDbDatabase *pSrcDb = curDoc()->database();

AcDbDatabase *pDestDb = NULL;
if(bMakeNewDwg)
{
pDestDb = new AcDbDatabase(true, true);
}
else
{
pDestDb = new AcDbDatabase(false, true);
es = pDestDb->readDwgFile(sDestDwg, _SH_DENYNO);
if(es != Acad::eOk)
{
acutPrintf("Error reading drawing file: %s\n", acadErrorStatusText(es));
delete pDestDb;
return;
}
}

/***********************************************************************
STEP 3 - Retrieve the destination parent.
***********************************************************************/
AcDbObjectId idDestParent;
AcDbObjectId idBlkTbl = pDestDb->blockTableId();

AcDbBlockTable *pBlkTbl = NULL;
es = acdbOpenObject(pBlkTbl, idBlkTbl, AcDb::kForRead);
if(es != Acad::eOk)
{
acutPrintf("Error retrieving block table: %s\n", acadErrorStatusText(es));
delete pDestDb;
return;
}

es = pBlkTbl->getAt(ACDB_MODEL_SPACE, idDestParent);
pBlkTbl->close();

if(es != Acad::eOk)
{
acutPrintf("Error getting model space id: %s\n", acadErrorStatusText(es));
delete pDestDb;
return;
}

/***********************************************************************
STEP 4 - Set up the map.
***********************************************************************/
AcDbIdMapping idMap;
idMap.setDestDb(pDestDb);

/***********************************************************************
STEP 5 - Perform the clone.
***********************************************************************/
es = pSrcDb->wblockCloneObjects(idsSel, idDestParent, idMap,
AcDb::kDrcIgnore, false);
if(es != Acad::eOk)
{
acutPrintf("Error cloning selected objects: %s\n",
acadErrorStatusText(es));
delete pDestDb;
return;
}

/***********************************************************************
STEP 6 - Save the destination drawing.
***********************************************************************/
es = pDestDb->saveAs(sDestDwg);
delete pDestDb;

if(es != Acad::eOk)
acutPrintf("Error saving drawing after clone: %s\n",
acadErrorStatusText(es));









"Moshe" wrote in message
news:[email protected]...
Rich,

As i said I tried to write and fail but with your help i going to try it
again

1. About ACDB_MODEL_SPACE: is it enough to Iterate it and
AcDbObject::wblockClone() each object and this will take
evrey table that is need (Blocks, Layers, Ltypes, TextStyle,
DimStyle, PageSetup) I don't mind about unused tables
(same as WBlock standard command don't).

2. About the AcDbGroup: untill now i didn't need to use groups
so hard/soft ownership/pointers are all new to me need more
help on this

3. Next week I will rewrite the new code & if it fails again. send you the
code

Thanx

Moshe


"Justavian" wrote in message
news:[email protected]...
> can you send me a simple code of wblockCloneObjects() to wblock a full
> database

A simple code? Ha! There's a dozen different symbol tables that have to be
cloned in order to clone a whole database - it's not simple. It looked to
me like you were on the right track, if you're just cloning entities (and
their dependencies). If you need to clone layers that are NOT automatically
cloned (say, for example, an empty layer), then you send those ids to
wblockCloneObjects, and the destination layer table. Very similar to
entities.

And as to the hardownership stuff, if you file out a hardownershipid during
any dwgOutFields( ), AutoCAD should see that as a required object and clone
it as well. But if you don't want to do that, then you need to make another
call to wblockCloneObjects( ) with the object id(s) of the group(s), and the
destination dictionary.

Try it out. If you can't get it to work, post the code and i'll help you
track down the problem.

-Rich



"Moshe" wrote in message
news:[email protected]...
Rich,

the goal was to make sure that every thing is cloned, now i understand the
meaning of isCloned() method.
but i fail in rewrite a WBlock command with wblockCloneObjects()

can you send me a simple code of wblockCloneObjects() to wblock a full
database
can you add how to set the AcDbHardOwnershipId, and or AcDbHardPointerId on
AcDbGroup so it will be also cloned
on the owner database

Thank you very much

Moshe


"Justavian" wrote in message
news:[email protected]...
What is the goal? Why do you want to know if it was cloned or not? As
specified previously, AutoCAD WILL ensure that everything requied has been
copied. Not only that, if w're talking about entities (as opposed to
symbols), it will either work or it won't. So if you try to copy a whole
series of lines and arcs and what not - the system isn't going to randomly
leave some of them out. You can be sure that the destination will contain
everything you need. Maybe i still don't really understand why you need to
know if there was a "full clone". If one of the objects you're copying
requires a layer, it WILL be in the destination drawing (and in the id map).
It will either copy the one from the source (if it doesn't exist in the
destination, or if you specify that AcDb::kDrcReplace), or it will use the
one that's already there.

I think that you might be confused. The isCloned( ) method does NOT
indicate that the function failed! It merely tells you that there was no
need to clone that item, since it already existed in the destination. So
back to the layer example. Say you're copying some items which reside on
the "SOME_LINES" layer. If the destination drawing also has a layer called
"SOME_LINES", AutoCAD will not clone the layer (all it checks is the name -
those layers might be different colors or use different linetypes). So the
map will contain an AcDbIdPair with the source AcDbObjectId for the
SOME_LINES layer, and the value() for that pair will be the existing
SOME_LINES id in the destination.

I'm also not sure about what you're asking with the three different
functions you listed. Remember that AcDbDatabase::wblock( ) doesn't use a
map (at least not directly), so you'd need to implement an editor reactor or
event reactor to catch the translated map. There doesn't seem to be a
AcDbDatabase::wblockClone() - just wblock() and wblockCloneObjects() (though
there is an AcDbObject::wblockClone). In my apps i only use the latter,
since that lets me have more control over what's happening. However,
wblock() actually just calls wblockCloneObjects()

I've used wblockCloneObjects to essentially completely reconstitue an entire
database, and i've never once had problems with things not being properly
cloned (other than my own coding mistakes). The only scenario that i can
imagine which would cause problems is if custom objects didn't have
ownerships or pointers set up correctly (since AutoCAD uses the
AcDbHardOwnershipId, AcDbHardPointerId, etc to determine what items are
required during the clone).

Sorry, this response rambles a little - but maybe somewhere in there i said
something that helped!


-Rich


"Moshe" wrote in message
news:[email protected]...
Rich Hi

Do I need to check, and How?

Remember, i'am using wblockCloneObject for rewrite Block & WBlock.
I have finished Block Command and now I started WBlock

Can i be sure that:
AcDbdatabase::wblock()
AcDbdatabase::wblockClone()
AcDbdatabase::wblockCloneObject()

is doing a full clone? what objects are skipped?
the objects i have to clone are only standard autocad objects, no custom
objects exist?

Thank you very much for your time

Moshe

"Justavian" wrote in message
news:[email protected]...
Every AcDbIdPair in the map will have both a key and a value if you used
wblockcloneobjects. There's no need to worry about whether AutoCAD just
randomly ignored some of the ids you sent in. If there's a problem, wblock
will return an error. As Art pointed out, some of the objects might NOT be
cloned - but AutoCAD will still populate the map with the ID it translated
to. In other words, the value( ) will report the existing object id in the
destination drawing (like the NOD in Art's example), while the AcDbIdPairs
for cloned objects will report the new id that was created.

I use wblockcloneobjects extensively, but i've never gone through the map
and asked whether things were cloned.

-Rich


"Moshe" wrote in message
news:[email protected]...
Hi Art,

So, you say: skip the IDMapping check?

Thank you for your reply.

Moshe

"Art Cooney" wrote in message
news:[email protected]...
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 14 of 16

Anonymous
Not applicable
About groups: trying to clone groups from one database to another. I was
sure that i had done that at some point, but i tried to write a quick
example, and although wblockCloneObjects returns Acad::eOk, it doesn't
actually seem to execute the clone. I don't have time to try to track down
my old code which (i think) does it correctly.

That being said, constructing a new group is extremely easy. So if you
can't clone the group, you can always reconstitue it in the other drawing.

Here's the example that's in the ObjectARX Reference:
AcDbGroup *pGroup = new AcDbGroup;
AcDbObjectId groupObjectId;
AcDbDictionary *pGroupDict = NULL;

acdbCurDwg()->getGroupDictionary(pGroupDict, AcDb::kForWrite);
pGroupDict->setAt("GroupName", pGroup, groupObjectId);
pGroupDict->close();

pGroup->append(objectId1); // objectId1 and objectId2
// are objId's of the
pGroup->append(objectId2); // entities which will be in the group.

pGroup->close();

"Moshe" wrote in message
news:[email protected]...
Rich,

As i said I tried to write and fail but with your help i going to try it
again

1. About ACDB_MODEL_SPACE: is it enough to Iterate it and
AcDbObject::wblockClone() each object and this will take
evrey table that is need (Blocks, Layers, Ltypes, TextStyle,
DimStyle, PageSetup) I don't mind about unused tables
(same as WBlock standard command don't).

2. About the AcDbGroup: untill now i didn't need to use groups
so hard/soft ownership/pointers are all new to me need more
help on this

3. Next week I will rewrite the new code & if it fails again. send you the
code

Thanx

Moshe


"Justavian" wrote in message
news:[email protected]...
> can you send me a simple code of wblockCloneObjects() to wblock a full
> database

A simple code? Ha! There's a dozen different symbol tables that have to be
cloned in order to clone a whole database - it's not simple. It looked to
me like you were on the right track, if you're just cloning entities (and
their dependencies). If you need to clone layers that are NOT automatically
cloned (say, for example, an empty layer), then you send those ids to
wblockCloneObjects, and the destination layer table. Very similar to
entities.

And as to the hardownership stuff, if you file out a hardownershipid during
any dwgOutFields( ), AutoCAD should see that as a required object and clone
it as well. But if you don't want to do that, then you need to make another
call to wblockCloneObjects( ) with the object id(s) of the group(s), and the
destination dictionary.

Try it out. If you can't get it to work, post the code and i'll help you
track down the problem.

-Rich



"Moshe" wrote in message
news:[email protected]...
Rich,

the goal was to make sure that every thing is cloned, now i understand the
meaning of isCloned() method.
but i fail in rewrite a WBlock command with wblockCloneObjects()

can you send me a simple code of wblockCloneObjects() to wblock a full
database
can you add how to set the AcDbHardOwnershipId, and or AcDbHardPointerId on
AcDbGroup so it will be also cloned
on the owner database

Thank you very much

Moshe


"Justavian" wrote in message
news:[email protected]...
What is the goal? Why do you want to know if it was cloned or not? As
specified previously, AutoCAD WILL ensure that everything requied has been
copied. Not only that, if w're talking about entities (as opposed to
symbols), it will either work or it won't. So if you try to copy a whole
series of lines and arcs and what not - the system isn't going to randomly
leave some of them out. You can be sure that the destination will contain
everything you need. Maybe i still don't really understand why you need to
know if there was a "full clone". If one of the objects you're copying
requires a layer, it WILL be in the destination drawing (and in the id map).
It will either copy the one from the source (if it doesn't exist in the
destination, or if you specify that AcDb::kDrcReplace), or it will use the
one that's already there.

I think that you might be confused. The isCloned( ) method does NOT
indicate that the function failed! It merely tells you that there was no
need to clone that item, since it already existed in the destination. So
back to the layer example. Say you're copying some items which reside on
the "SOME_LINES" layer. If the destination drawing also has a layer called
"SOME_LINES", AutoCAD will not clone the layer (all it checks is the name -
those layers might be different colors or use different linetypes). So the
map will contain an AcDbIdPair with the source AcDbObjectId for the
SOME_LINES layer, and the value() for that pair will be the existing
SOME_LINES id in the destination.

I'm also not sure about what you're asking with the three different
functions you listed. Remember that AcDbDatabase::wblock( ) doesn't use a
map (at least not directly), so you'd need to implement an editor reactor or
event reactor to catch the translated map. There doesn't seem to be a
AcDbDatabase::wblockClone() - just wblock() and wblockCloneObjects() (though
there is an AcDbObject::wblockClone). In my apps i only use the latter,
since that lets me have more control over what's happening. However,
wblock() actually just calls wblockCloneObjects()

I've used wblockCloneObjects to essentially completely reconstitue an entire
database, and i've never once had problems with things not being properly
cloned (other than my own coding mistakes). The only scenario that i can
imagine which would cause problems is if custom objects didn't have
ownerships or pointers set up correctly (since AutoCAD uses the
AcDbHardOwnershipId, AcDbHardPointerId, etc to determine what items are
required during the clone).

Sorry, this response rambles a little - but maybe somewhere in there i said
something that helped!


-Rich


"Moshe" wrote in message
news:[email protected]...
Rich Hi

Do I need to check, and How?

Remember, i'am using wblockCloneObject for rewrite Block & WBlock.
I have finished Block Command and now I started WBlock

Can i be sure that:
AcDbdatabase::wblock()
AcDbdatabase::wblockClone()
AcDbdatabase::wblockCloneObject()

is doing a full clone? what objects are skipped?
the objects i have to clone are only standard autocad objects, no custom
objects exist?

Thank you very much for your time

Moshe

"Justavian" wrote in message
news:[email protected]...
Every AcDbIdPair in the map will have both a key and a value if you used
wblockcloneobjects. There's no need to worry about whether AutoCAD just
randomly ignored some of the ids you sent in. If there's a problem, wblock
will return an error. As Art pointed out, some of the objects might NOT be
cloned - but AutoCAD will still populate the map with the ID it translated
to. In other words, the value( ) will report the existing object id in the
destination drawing (like the NOD in Art's example), while the AcDbIdPairs
for cloned objects will report the new id that was created.

I use wblockcloneobjects extensively, but i've never gone through the map
and asked whether things were cloned.

-Rich


"Moshe" wrote in message
news:[email protected]...
Hi Art,

So, you say: skip the IDMapping check?

Thank you for your reply.

Moshe

"Art Cooney" wrote in message
news:[email protected]...
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 15 of 16

Anonymous
Not applicable
Rich,

You been most helpful, thank you very much
I will try it later on this weekend and report
to you what came out.

bye, Moshe


"Justavian" wrote in message
news:[email protected]...
You don't want to do the cloning yourself. Well, at least i don't think you
do! You should be using wblockCloneObjects( ). After looking at your code
i realized that there's at least one thing missing - you need to call
AcDbIdMapping::setDestDb( ) prior to any call to the wblockCloneObjects( ).
Here is a working example i just wrote that's doing something like yours (i
didn't try your code). This example will copy some selected entities (and
their dependencies, of course) to a new drawing, or to an existing drawing -
depending on what the boolean var at the top says.

Note that i check virtually every returned status for an error! This is a
good habit to get into. Granted, it's usually overkill. But if you try to
open an object and it fails, trying to access it a step later is going to
cause AutoCAD to crash. Better to just check everything.


// Clone the selected objects from the current document into some other
drawing.
// 1) Get some things to copy.
// 2) Open the destination drawing.
// 3) Retrieve the destination parent - in this case model space.
// 4) Set up the map.
// 5) Perform the clone.
// 6) Save the destination drawing.

Acad::ErrorStatus es;
CString sDestDwg("C:\\CopyToDwg.dwg");
bool bMakeNewDwg = true;

/***********************************************************************
STEP 1 - Get some things to copy
***********************************************************************/
ads_name ssSel;
long nRtCode = acedSSGet(NULL, NULL, NULL, NULL, ssSel);
if(nRtCode != RTNORM)
return;

long sslength;
acedSSLength(ssSel, &sslength);

AcDbObjectIdArray idsSel;
for(int i = 0; i {
ads_name ent;
acedSSName(ssSel, i, ent);

AcDbObjectId objId;
acdbGetObjectId(objId, ent);

idsSel.append(objId);
}
acedSSFree(ssSel);


/***********************************************************************
STEP 2 - Open the destination drawing.
***********************************************************************/
AcDbDatabase *pSrcDb = curDoc()->database();

AcDbDatabase *pDestDb = NULL;
if(bMakeNewDwg)
{
pDestDb = new AcDbDatabase(true, true);
}
else
{
pDestDb = new AcDbDatabase(false, true);
es = pDestDb->readDwgFile(sDestDwg, _SH_DENYNO);
if(es != Acad::eOk)
{
acutPrintf("Error reading drawing file: %s\n", acadErrorStatusText(es));
delete pDestDb;
return;
}
}

/***********************************************************************
STEP 3 - Retrieve the destination parent.
***********************************************************************/
AcDbObjectId idDestParent;
AcDbObjectId idBlkTbl = pDestDb->blockTableId();

AcDbBlockTable *pBlkTbl = NULL;
es = acdbOpenObject(pBlkTbl, idBlkTbl, AcDb::kForRead);
if(es != Acad::eOk)
{
acutPrintf("Error retrieving block table: %s\n", acadErrorStatusText(es));
delete pDestDb;
return;
}

es = pBlkTbl->getAt(ACDB_MODEL_SPACE, idDestParent);
pBlkTbl->close();

if(es != Acad::eOk)
{
acutPrintf("Error getting model space id: %s\n", acadErrorStatusText(es));
delete pDestDb;
return;
}

/***********************************************************************
STEP 4 - Set up the map.
***********************************************************************/
AcDbIdMapping idMap;
idMap.setDestDb(pDestDb);

/***********************************************************************
STEP 5 - Perform the clone.
***********************************************************************/
es = pSrcDb->wblockCloneObjects(idsSel, idDestParent, idMap,
AcDb::kDrcIgnore, false);
if(es != Acad::eOk)
{
acutPrintf("Error cloning selected objects: %s\n",
acadErrorStatusText(es));
delete pDestDb;
return;
}

/***********************************************************************
STEP 6 - Save the destination drawing.
***********************************************************************/
es = pDestDb->saveAs(sDestDwg);
delete pDestDb;

if(es != Acad::eOk)
acutPrintf("Error saving drawing after clone: %s\n",
acadErrorStatusText(es));









"Moshe" wrote in message
news:[email protected]...
Rich,

As i said I tried to write and fail but with your help i going to try it
again

1. About ACDB_MODEL_SPACE: is it enough to Iterate it and
AcDbObject::wblockClone() each object and this will take
evrey table that is need (Blocks, Layers, Ltypes, TextStyle,
DimStyle, PageSetup) I don't mind about unused tables
(same as WBlock standard command don't).

2. About the AcDbGroup: untill now i didn't need to use groups
so hard/soft ownership/pointers are all new to me need more
help on this

3. Next week I will rewrite the new code & if it fails again. send you the
code

Thanx

Moshe


"Justavian" wrote in message
news:[email protected]...
> can you send me a simple code of wblockCloneObjects() to wblock a full
> database

A simple code? Ha! There's a dozen different symbol tables that have to be
cloned in order to clone a whole database - it's not simple. It looked to
me like you were on the right track, if you're just cloning entities (and
their dependencies). If you need to clone layers that are NOT automatically
cloned (say, for example, an empty layer), then you send those ids to
wblockCloneObjects, and the destination layer table. Very similar to
entities.

And as to the hardownership stuff, if you file out a hardownershipid during
any dwgOutFields( ), AutoCAD should see that as a required object and clone
it as well. But if you don't want to do that, then you need to make another
call to wblockCloneObjects( ) with the object id(s) of the group(s), and the
destination dictionary.

Try it out. If you can't get it to work, post the code and i'll help you
track down the problem.

-Rich



"Moshe" wrote in message
news:[email protected]...
Rich,

the goal was to make sure that every thing is cloned, now i understand the
meaning of isCloned() method.
but i fail in rewrite a WBlock command with wblockCloneObjects()

can you send me a simple code of wblockCloneObjects() to wblock a full
database
can you add how to set the AcDbHardOwnershipId, and or AcDbHardPointerId on
AcDbGroup so it will be also cloned
on the owner database

Thank you very much

Moshe


"Justavian" wrote in message
news:[email protected]...
What is the goal? Why do you want to know if it was cloned or not? As
specified previously, AutoCAD WILL ensure that everything requied has been
copied. Not only that, if w're talking about entities (as opposed to
symbols), it will either work or it won't. So if you try to copy a whole
series of lines and arcs and what not - the system isn't going to randomly
leave some of them out. You can be sure that the destination will contain
everything you need. Maybe i still don't really understand why you need to
know if there was a "full clone". If one of the objects you're copying
requires a layer, it WILL be in the destination drawing (and in the id map).
It will either copy the one from the source (if it doesn't exist in the
destination, or if you specify that AcDb::kDrcReplace), or it will use the
one that's already there.

I think that you might be confused. The isCloned( ) method does NOT
indicate that the function failed! It merely tells you that there was no
need to clone that item, since it already existed in the destination. So
back to the layer example. Say you're copying some items which reside on
the "SOME_LINES" layer. If the destination drawing also has a layer called
"SOME_LINES", AutoCAD will not clone the layer (all it checks is the name -
those layers might be different colors or use different linetypes). So the
map will contain an AcDbIdPair with the source AcDbObjectId for the
SOME_LINES layer, and the value() for that pair will be the existing
SOME_LINES id in the destination.

I'm also not sure about what you're asking with the three different
functions you listed. Remember that AcDbDatabase::wblock( ) doesn't use a
map (at least not directly), so you'd need to implement an editor reactor or
event reactor to catch the translated map. There doesn't seem to be a
AcDbDatabase::wblockClone() - just wblock() and wblockCloneObjects() (though
there is an AcDbObject::wblockClone). In my apps i only use the latter,
since that lets me have more control over what's happening. However,
wblock() actually just calls wblockCloneObjects()

I've used wblockCloneObjects to essentially completely reconstitue an entire
database, and i've never once had problems with things not being properly
cloned (other than my own coding mistakes). The only scenario that i can
imagine which would cause problems is if custom objects didn't have
ownerships or pointers set up correctly (since AutoCAD uses the
AcDbHardOwnershipId, AcDbHardPointerId, etc to determine what items are
required during the clone).

Sorry, this response rambles a little - but maybe somewhere in there i said
something that helped!


-Rich


"Moshe" wrote in message
news:[email protected]...
Rich Hi

Do I need to check, and How?

Remember, i'am using wblockCloneObject for rewrite Block & WBlock.
I have finished Block Command and now I started WBlock

Can i be sure that:
AcDbdatabase::wblock()
AcDbdatabase::wblockClone()
AcDbdatabase::wblockCloneObject()

is doing a full clone? what objects are skipped?
the objects i have to clone are only standard autocad objects, no custom
objects exist?

Thank you very much for your time

Moshe

"Justavian" wrote in message
news:[email protected]...
Every AcDbIdPair in the map will have both a key and a value if you used
wblockcloneobjects. There's no need to worry about whether AutoCAD just
randomly ignored some of the ids you sent in. If there's a problem, wblock
will return an error. As Art pointed out, some of the objects might NOT be
cloned - but AutoCAD will still populate the map with the ID it translated
to. In other words, the value( ) will report the existing object id in the
destination drawing (like the NOD in Art's example), while the AcDbIdPairs
for cloned objects will report the new id that was created.

I use wblockcloneobjects extensively, but i've never gone through the map
and asked whether things were cloned.

-Rich


"Moshe" wrote in message
news:[email protected]...
Hi Art,

So, you say: skip the IDMapping check?

Thank you for your reply.

Moshe

"Art Cooney" wrote in message
news:[email protected]...
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes
Message 16 of 16

Anonymous
Not applicable
Rich

Yes I know i can create new groups in the new database
infact that what i am doing now, i tought it is more easy to clone

Thanx , Moshe

"Justavian" wrote in message
news:[email protected]...
About groups: trying to clone groups from one database to another. I was
sure that i had done that at some point, but i tried to write a quick
example, and although wblockCloneObjects returns Acad::eOk, it doesn't
actually seem to execute the clone. I don't have time to try to track down
my old code which (i think) does it correctly.

That being said, constructing a new group is extremely easy. So if you
can't clone the group, you can always reconstitue it in the other drawing.

Here's the example that's in the ObjectARX Reference:
AcDbGroup *pGroup = new AcDbGroup;
AcDbObjectId groupObjectId;
AcDbDictionary *pGroupDict = NULL;

acdbCurDwg()->getGroupDictionary(pGroupDict, AcDb::kForWrite);
pGroupDict->setAt("GroupName", pGroup, groupObjectId);
pGroupDict->close();

pGroup->append(objectId1); // objectId1 and objectId2
// are objId's of the
pGroup->append(objectId2); // entities which will be in the group.

pGroup->close();

"Moshe" wrote in message
news:[email protected]...
Rich,

As i said I tried to write and fail but with your help i going to try it
again

1. About ACDB_MODEL_SPACE: is it enough to Iterate it and
AcDbObject::wblockClone() each object and this will take
evrey table that is need (Blocks, Layers, Ltypes, TextStyle,
DimStyle, PageSetup) I don't mind about unused tables
(same as WBlock standard command don't).

2. About the AcDbGroup: untill now i didn't need to use groups
so hard/soft ownership/pointers are all new to me need more
help on this

3. Next week I will rewrite the new code & if it fails again. send you the
code

Thanx

Moshe


"Justavian" wrote in message
news:[email protected]...
> can you send me a simple code of wblockCloneObjects() to wblock a full
> database

A simple code? Ha! There's a dozen different symbol tables that have to be
cloned in order to clone a whole database - it's not simple. It looked to
me like you were on the right track, if you're just cloning entities (and
their dependencies). If you need to clone layers that are NOT automatically
cloned (say, for example, an empty layer), then you send those ids to
wblockCloneObjects, and the destination layer table. Very similar to
entities.

And as to the hardownership stuff, if you file out a hardownershipid during
any dwgOutFields( ), AutoCAD should see that as a required object and clone
it as well. But if you don't want to do that, then you need to make another
call to wblockCloneObjects( ) with the object id(s) of the group(s), and the
destination dictionary.

Try it out. If you can't get it to work, post the code and i'll help you
track down the problem.

-Rich



"Moshe" wrote in message
news:[email protected]...
Rich,

the goal was to make sure that every thing is cloned, now i understand the
meaning of isCloned() method.
but i fail in rewrite a WBlock command with wblockCloneObjects()

can you send me a simple code of wblockCloneObjects() to wblock a full
database
can you add how to set the AcDbHardOwnershipId, and or AcDbHardPointerId on
AcDbGroup so it will be also cloned
on the owner database

Thank you very much

Moshe


"Justavian" wrote in message
news:[email protected]...
What is the goal? Why do you want to know if it was cloned or not? As
specified previously, AutoCAD WILL ensure that everything requied has been
copied. Not only that, if w're talking about entities (as opposed to
symbols), it will either work or it won't. So if you try to copy a whole
series of lines and arcs and what not - the system isn't going to randomly
leave some of them out. You can be sure that the destination will contain
everything you need. Maybe i still don't really understand why you need to
know if there was a "full clone". If one of the objects you're copying
requires a layer, it WILL be in the destination drawing (and in the id map).
It will either copy the one from the source (if it doesn't exist in the
destination, or if you specify that AcDb::kDrcReplace), or it will use the
one that's already there.

I think that you might be confused. The isCloned( ) method does NOT
indicate that the function failed! It merely tells you that there was no
need to clone that item, since it already existed in the destination. So
back to the layer example. Say you're copying some items which reside on
the "SOME_LINES" layer. If the destination drawing also has a layer called
"SOME_LINES", AutoCAD will not clone the layer (all it checks is the name -
those layers might be different colors or use different linetypes). So the
map will contain an AcDbIdPair with the source AcDbObjectId for the
SOME_LINES layer, and the value() for that pair will be the existing
SOME_LINES id in the destination.

I'm also not sure about what you're asking with the three different
functions you listed. Remember that AcDbDatabase::wblock( ) doesn't use a
map (at least not directly), so you'd need to implement an editor reactor or
event reactor to catch the translated map. There doesn't seem to be a
AcDbDatabase::wblockClone() - just wblock() and wblockCloneObjects() (though
there is an AcDbObject::wblockClone). In my apps i only use the latter,
since that lets me have more control over what's happening. However,
wblock() actually just calls wblockCloneObjects()

I've used wblockCloneObjects to essentially completely reconstitue an entire
database, and i've never once had problems with things not being properly
cloned (other than my own coding mistakes). The only scenario that i can
imagine which would cause problems is if custom objects didn't have
ownerships or pointers set up correctly (since AutoCAD uses the
AcDbHardOwnershipId, AcDbHardPointerId, etc to determine what items are
required during the clone).

Sorry, this response rambles a little - but maybe somewhere in there i said
something that helped!


-Rich


"Moshe" wrote in message
news:[email protected]...
Rich Hi

Do I need to check, and How?

Remember, i'am using wblockCloneObject for rewrite Block & WBlock.
I have finished Block Command and now I started WBlock

Can i be sure that:
AcDbdatabase::wblock()
AcDbdatabase::wblockClone()
AcDbdatabase::wblockCloneObject()

is doing a full clone? what objects are skipped?
the objects i have to clone are only standard autocad objects, no custom
objects exist?

Thank you very much for your time

Moshe

"Justavian" wrote in message
news:[email protected]...
Every AcDbIdPair in the map will have both a key and a value if you used
wblockcloneobjects. There's no need to worry about whether AutoCAD just
randomly ignored some of the ids you sent in. If there's a problem, wblock
will return an error. As Art pointed out, some of the objects might NOT be
cloned - but AutoCAD will still populate the map with the ID it translated
to. In other words, the value( ) will report the existing object id in the
destination drawing (like the NOD in Art's example), while the AcDbIdPairs
for cloned objects will report the new id that was created.

I use wblockcloneobjects extensively, but i've never gone through the map
and asked whether things were cloned.

-Rich


"Moshe" wrote in message
news:[email protected]...
Hi Art,

So, you say: skip the IDMapping check?

Thank you for your reply.

Moshe

"Art Cooney" wrote in message
news:[email protected]...
Not all objects in the idmap will be cloned. For example, if an object in a
dictionary is cloned, that will add the object's owning dictionary to the
idMap, which will in turn add the dictionary's owner to the idMap, and so on
up to the Named Objects Dictionary. So, the NOD will be added to the idMap,
but we don't clone the NOD since it is already in every drawing.

"Moshe" wrote in message
news:[email protected]...
Hi,

More info...

Actually, the Clone is Done and the program works well, I would like to know
why the check for the clone is fail?

Moshe

"Moshe" wrote in message
news:[email protected]...
Hi All,

In the following code I am trying to clone some objects, from current
database to a temporary one
the code is fails in IdMapping check for the cloned objects

What's is wrong?


void cloneMyObjects()
{
AcDbObjectIdArray ObjIdArr;
AcDbobjectId ObjId;
ads_name ent, ss;
long i, len;

// allocating memory
acedSSGet(NULL, NULL, NULL, NULL, ss);
ObjIdArr.setLogicalLength(0);
acedSSLength(ss, &len);
for (i = 0L; i < len; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(ObjId, ent);
ObjIdArr.append(ObjId);
}

acedSSFree(ss); // dispose memory

AcDbDatabase *pTempDb;
AcDbBlockTable *pBlockTable;
AcDbObjectId BlkRecId;
AcDbIdmapping idMap;

// allocating memory, open new database
pTempDb = new AcDbDatabase(true);

// allocating memory, open block table for write
pTempDb->getBlockTable(pBlockTable, AcDb::kForWrite);

// get model space objectId
pBlockTable->getAt(ACDB_MODEL_SPACE, BlkRecId);

pBlockTable->close(); // dispose memory

acdbHostApplicationServices()->workingDatabase()
->wblockCloneObjects(ObjIdArr, BlkRecId, idMap, AcDb::kDrcIgnore);

AcDbIdMappingIter Iter(idMap); // initializing iterator
AcDbIdPair idPair;

for (Iter.start(); !Iter.done(); Iter.next())
{
Iter.getMap(idPair);
if (!idPair.isCloned()) // here it fails, object
is not cloned: Why???
{
acedAlert("Fail to clone object.");
break;
}
}

delete pTempDb; // dispose memory
}

Thanks for your time.

Moshe
0 Likes