Custom entity?

Custom entity?

Anonymous
Not applicable
1,157 Views
8 Replies
Message 1 of 9

Custom entity?

Anonymous
Not applicable
I have developed several entities before but all of them in a dbx project. This time I just want to create an AcDbEntity derived class for a title block in the arx application, not a stand-alone dbx.

Is there a minimum of work that needs to be done? Below is what I have so far, but when I try to append an object of this class to the database, I get an exception error. The debug window shows the following line:

[code]
First-chance exception at 0x7c812a5b in acad.exe: Microsoft C++ exception: CInvalidArgException at memory location 0x0012f64c..
[/code]

Any suggestions?

[code]
#pragma once

class TitleBlock : public AcDbEntity
{
private:
AcDbExtents _page;
AcDbExtents _dwgArea;

public:
TitleBlock(void);
~TitleBlock(void);

virtual Adesk::Boolean worldDraw(AcGiWorldDraw* mode);
virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler);
virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const;
};

#include "StdAfx.h"
#include "TitleBlock.h"

TitleBlock::TitleBlock(void)
: AcDbEntity()
, _page(AcDbExtents(AcGePoint3d(0,0,0), AcGePoint3d(8.5,11,0)))
, _dwgArea(AcDbExtents(AcGePoint3d(2.0,3.75,0), AcGePoint3d(9.0,6.25,0)))
{
}

TitleBlock::~TitleBlock(void)
{
}

Adesk::Boolean TitleBlock::worldDraw(AcGiWorldDraw* mode)
{
assertReadEnabled();

AcGeVector3d x(_page.maxPoint().x - _page.minPoint().x, 0, 0);
AcGeVector3d y(0, _page.maxPoint().y - _page.minPoint().y, 0);

AcGePoint3d pts[5];
pts[0] = _page.minPoint();
pts[1] = pts[0] + x;
pts[2] = pts[0] + x + y;
pts[3] = pts[0] + y;
pts[4] = pts[0];

mode->geometry().polyline(5, pts);

x.set(_dwgArea.maxPoint().x - _dwgArea.minPoint().x, 0, 0);
y.set(0, _dwgArea.maxPoint().y - _dwgArea.minPoint().y, 0);

pts[0] = _dwgArea.minPoint();
pts[1] = pts[0] + x;
pts[2] = pts[0] + x + y;
pts[3] = pts[0] + y;
pts[4] = pts[0];

mode->geometry().polyline(5, pts);

return Adesk::kTrue;
}

Acad::ErrorStatus TitleBlock::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = AcDbEntity::dwgInFields(pFiler);
if(es != Acad::eOk)
return es;

AcGePoint3d min, max;
pFiler->readPoint3d(&min);
pFiler->readPoint3d(&max);
_page.set(min, max);

pFiler->readPoint3d(&min);
pFiler->readPoint3d(&max);
_dwgArea.set(min, max);

return pFiler->filerStatus();
}

Acad::ErrorStatus TitleBlock::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = AcDbEntity::dwgOutFields(pFiler);
if(es != Acad::eOk)
return es;

pFiler->writePoint3d(_page.minPoint());
pFiler->writePoint3d(_page.maxPoint());
pFiler->writePoint3d(_dwgArea.minPoint());
pFiler->writePoint3d(_dwgArea.maxPoint());

return pFiler->filerStatus();
}

Acad::ErrorStatus AddEntity(AcDbObjectId& objId, AcDbEntity* pEnt)
{
AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
if(!pDb)
return Acad::eInvalidBlockName;

AcDbBlockTable* pBt = NULL;
Acad::ErrorStatus es = pDb->getBlockTable(pBt, AcDb::kForRead);
if(es == Acad::eOk)
{
AcDbBlockTableRecord* pBtr = NULL;
es = pBt->getAt(ACDB_MODEL_SPACE, pBtr, AcDb::kForWrite);
if(es == Acad::eOk)
{
es = pBtr->appendAcDbEntity(objId, pEnt);
pBtr->close();
}
pBt->close();
}

return es;
}
[/code]

Mike B
0 Likes
1,158 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
Ok, after reviewing some notes, it seems that this should not be done like this. It should be created in a DBX dll if it is to have its own worldDraw(...). Is that a correct statement?

If done otherwise, then worldDraw(...) is not overriden and the object should be drawn using primative objects?

Mike B
0 Likes
Message 3 of 9

Anonymous
Not applicable
No, that's not a correct statement. You don't need to put custom entity
stuff into a dbx unless you intend for that dbx to be able to be loaded into
non-Acad based host applications. If you only intend to work with AutoCAD
or AutoCAD based host applications, then there's no reason not to just put
it all into an arx module.


wrote in message news:5609623@discussion.autodesk.com...
Ok, after reviewing some notes, it seems that this should not be done like
this. It should be created in a DBX dll if it is to have its own
worldDraw(...). Is that a correct statement?

If done otherwise, then worldDraw(...) is not overriden and the object
should be drawn using primative objects?

Mike B
0 Likes
Message 4 of 9

Anonymous
Not applicable
The object does not have to be defined in a DBX. You can put custom objects
into an ARX if you wish. However, i would suggest you go ahead and use the
wizard to create your custom object. Otherwise, you may end up forgetting
to put in macros like ACRX_DECLARE_MEMBERS, and
ACDB_REGISTER_OBJECT_ENTRY_AUTO, etc. Once you're more acquainted with
custom objects, you can probably skip the wizard part and do it manually (or
copy from another example you have).

Once the custom object has been created, you should be able to just copy it
over to your ARX.

I'm not sure what your last question means. All objects in AutoCAD are
drawn using primitive objects.

-Rich



wrote in message news:5609623@discussion.autodesk.com...
Ok, after reviewing some notes, it seems that this should not be done like
this. It should be created in a DBX dll if it is to have its own
worldDraw(...). Is that a correct statement?

If done otherwise, then worldDraw(...) is not overriden and the object
should be drawn using primative objects?

Mike B
0 Likes
Message 5 of 9

Anonymous
Not applicable
Art, thanks for your response. I am wondering however, if you disagreed with my statements (which I am agreeing with you on some points), why didn't you answer my first post where I asked "Is there a minimum of work that needs to be done?"?

The only thing I disagree with your post on is that "there's no readon not to just put it all into an arx module".

I would think it is better to create most custom objects in a dbx since this supports reuse and if the object is to be used in more than one arx application, it would be better for maintenance as well.

Mike B
0 Likes
Message 6 of 9

Anonymous
Not applicable
All I was trying to say is that there's no technical requirement to put a
custom object's code into a dbx unless you want it to be able to be loaded
into non-acad based host applications. Sure, they may be other reasons why
you might want to use a dbx.

I didn't answer your question about a minimum of work because I don't have
time to properly answer that - just saying "yes there is a minimum" doesn't
seem to me to be a proper answer.

wrote in message news:5611600@discussion.autodesk.com...
Art, thanks for your response. I am wondering however, if you disagreed with
my statements (which I am agreeing with you on some points), why didn't you
answer my first post where I asked "Is there a minimum of work that needs to
be done?"?

The only thing I disagree with your post on is that "there's no readon not
to just put it all into an arx module".

I would think it is better to create most custom objects in a dbx since this
supports reuse and if the object is to be used in more than one arx
application, it would be better for maintenance as well.

Mike B
0 Likes
Message 7 of 9

Anonymous
Not applicable
Understood, thanks for replying. I guess I could create a custom object using the wizard and look at the basic setup. Not sure if this would help though, may just confuse the issue because some things the wizard creates may be only required because it is a dbx project. Not sure, but....

Mike B
0 Likes
Message 8 of 9

Anonymous
Not applicable
Mike:

Recent versions of the wizard can create custom objects in an ARX project,
so just use the wizard and be done with it. 🙂
--
Owen Wengerd
President, ManuSoft ==> http://www.manusoft.com
VP Americas, CADLock, Inc. ==> http://www.cadlock.com
0 Likes
Message 9 of 9

Anonymous
Not applicable
Mike;

I do not have to much experience with custom objects, but was able to use
them in some of my commands, here is a link to a follow up of the very basic
requirements:

http://www.theswamp.org/index.php?topic=8563.0

It is a project of a simple custom line, just to expose what is needed, and
all as normal ARX project and no wizard was used.

HTH.



wrote in message news:5611865@discussion.autodesk.com...
Understood, thanks for replying. I guess I could create a custom object
using the wizard and look at the basic setup. Not sure if this would help
though, may just confuse the issue because some things the wizard creates
may be only required because it is a dbx project. Not sure, but....

Mike B
0 Likes