Why embedded entity in my custom entity cannot be wblockcloned?

Why embedded entity in my custom entity cannot be wblockcloned?

Anonymous
Not applicable
1,094 Views
7 Replies
Message 1 of 8

Why embedded entity in my custom entity cannot be wblockcloned?

Anonymous
Not applicable
My custom entity is derived from AcDbEntity.An AcDb2dPolyline entity is embedded in it.I do it as Art Cooney wrote on http://discussion.autodesk.com/thread.jspa?messageID=5910438.
I erase the 2dPolyline after it is embedded in my custom entity.But I find the HardPointId is NULL after I re-open the saved DWG file.So I create an anonymous Block and move the 2dPolyline to the block.Now it works fine except that I find the embedded 2dPolyline's owner is eWasErased.
One problem is the erased 2dPolyline cannot be saved in *.dxf file although I have overrided the dxfInFields/dxfOutFields methods.
Another problem is that when I copy the custom entity from current database to another database,I find the embedeed 2dPolyline is not copied and the custom entity's HardPointId which references to the 2dPolyline is NULL.But I have overrided the wblockClone method.
Can anybody help me? Thanks in advance.
I hope Art Cooney will give me more advice.
0 Likes
1,095 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
MyAcDbEntity.h
0 Likes
Message 3 of 8

Anonymous
Not applicable
MyAcDbEntity.cpp
0 Likes
Message 4 of 8

Anonymous
Not applicable

>>I erase
the 2dPolyline after it is embedded in my custom entity.But I find the
HardPointId is NULL after I re-open the saved DWG file

 

That's as it should be - erased objects are not
saved to dwg or dxf.

 

Anonymous blocks are also removed if they have
nothing referencing them.  If you want an unreferenced BlockTableRecord to
stay, then don't make it anonymous.

 

If you don't want the entity to be seen, then you
could set it to be invisible using the AcDbEntity::setVisibility()
method.

 

wblock won't clone erased referenced
objects.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
My
custom entity is derived from AcDbEntity.An AcDb2dPolyline entity is embedded
in it.I do it as Art Cooney wrote on
http://discussion.autodesk.com/thread.jspa?messageID=5910438.
I erase the
2dPolyline after it is embedded in my custom entity.But I find the HardPointId
is NULL after I re-open the saved DWG file.So I create an anonymous Block and
move the 2dPolyline to the block.Now it works fine except that I find the
embedded 2dPolyline's owner is eWasErased.
One problem is the era
sed
2dPolyline cannot be saved in *.dxf file although I have overrided the
dxfInFields/dxfOutFields methods.
Another problem is that when I copy the
custom entity from current database to another database,I find the embedeed
2dPolyline is not copied and the custom entity's HardPointId which references
to the 2dPolyline  is NULL.But I have overrided the wblockClone
method.
Can anybody help me? Thanks in advance.
I hope Art Cooney will
give me more advice.
0 Likes
Message 5 of 8

Anonymous
Not applicable
Thanks for your reply.
Now,I have moved the embedded 2dPolyline to an unanonymous block and set it to be invisible.So the 2dPolyline should be an unerased entity, but it still doesn't be copied when I
copy and paste the custom entity between two databases.
MyAcDbEntity::wblockClone() code is the same as the Poly sample.
I don't know why it is not wblockCloned together with the custom entity.
0 Likes
Message 6 of 8

Anonymous
Not applicable
Why are you overriding wblockClone()? That is a very very difficult method
to implement correctly, so I wouldn't override it unless you really need to.

wrote in message news:5938893@discussion.autodesk.com...
Thanks for your reply.
Now,I have moved the embedded 2dPolyline to an unanonymous block and set it
to be invisible.So the 2dPolyline should be an unerased entity, but it
still doesn't be copied when I
copy and paste the custom entity between two databases.
MyAcDbEntity::wblockClone() code is the same as the Poly sample.
I don't know why it is not wblockCloned together with the custom entity.
0 Likes
Message 7 of 8

Anonymous
Not applicable
Of course I don't want to override wblockClone().As you said,it is so difficult to implement correctly.But it is depressed that even the custom entity will not be copied if not overriding. I have to do so.
Now In wblockClone(),I try to call wblockClone() of the embedded 2dPolyline's owner(ie. the unanonymous block)directly.Fortunately I find it does work.
Old code:
pSubObject->wblockClone(pClone->database(),pClonedSubObject,idMap, Adesk::kFalse);
New code:
AcDbObject* pBlock;
acdbOpenAcDbObject(pBlock, pSubObject->ownerId(), AcDb::kForRead);
pBlock->wblockClone(pClone->database(),pClonedSubObject,idMap, Adesk::kFalse);
pBlock->close();

It looks very difficult,but it is so simple now.I don't know whether it is correct or not.
0 Likes
Message 8 of 8

Anonymous
Not applicable
The default wblockClone should end up automatically copying all objects that
have hardpointers to them, so if your main entity files out a hard pointer
to the 2dPolyline, then you should not need to override wblockClone() nor
call it on the 2dPolyline.

wrote in message news:5938979@discussion.autodesk.com...
Of course I don't want to override wblockClone().As you said,it is so
difficult to implement correctly.But it is depressed that even the custom
entity will not be copied if not overriding. I have to do so.
Now In wblockClone(),I try to call wblockClone() of the embedded
2dPolyline's owner(ie. the unanonymous block)directly.Fortunately I find it
does work.
Old code:
pSubObject->wblockClone(pClone->database(),pClonedSubObject,idMap,
Adesk::kFalse);
New code:
AcDbObject* pBlock;
acdbOpenAcDbObject(pBlock, pSubObject->ownerId(), AcDb::kForRead);
pBlock->wblockClone(pClone->database(),pClonedSubObject,idMap,
Adesk::kFalse);
pBlock->close();

It looks very difficult,but it is so simple now.I don't know whether it is
correct or not.
0 Likes