ObjectARX Custom Entity Creation Failed: accore.pdb Not Loaded

furqananees2007
Observer
Observer

ObjectARX Custom Entity Creation Failed: accore.pdb Not Loaded

furqananees2007
Observer
Observer

I'm currently working with AutoCAD 2021 and have installed the ObjectARX 2021 SDK. To get familiar with the SDK, I explored the sample projects provided, specifically "custobj_dg" and "polysamp". By analyzing the structure of these examples, I gained a deeper understanding of the SDK's framework and was able to develop my own C++ code.

#pragma once

#include <Windows.h>
#include <rxobject.h>
#include <rxregsvc.h>
#include <aced.h>
#include <dbsymtb.h>
#include <dbapserv.h>
#include <adslib.h>
#include "tchar.h"
#include <dbobjptr.h>


void initApp();
void unloadApp();
Acad::ErrorStatus postToDb(AcDbEntity* ent);
Acad::ErrorStatus postToDb(AcDbEntity* ent, AcDbObjectId& objId);
extern "C"
AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*);

class MyCustomEnt : public AcDbEntity
{
public:
    ACRX_DECLARE_MEMBERS(MyCustomEnt);

        MyCustomEnt() : mRadius(0), mCenter(0,0,0) {};
        MyCustomEnt(const double& rad, AcGePoint3d& center) : mRadius(rad), mCenter(center) {};

    // Override necessary methods
    virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const override;
    virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler) override;

    void setCircleParameters(const AcGePoint3d& center, double radius);


protected:
    virtual Adesk::Boolean      subWorldDraw(AcGiWorldDraw* mode);

    

private:
    // Store circle data
    AcGePoint3d mCenter;
    double mRadius;
};

ACRX_DXF_DEFINE_MEMBERS(MyCustomEnt, AcDbObject, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 0, MyCustomEnt, SAMP2);


void MyCustomEnt::setCircleParameters(const AcGePoint3d& center, double radius)
{
    assertWriteEnabled();
    mCenter = center;
    mRadius = radius;
}

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

    // Write the center point and radius
    pFiler->writePoint3d(mCenter);
    pFiler->writeDouble(mRadius);

    return pFiler->filerStatus();
}

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

    // Read the center point and radius
    pFiler->readPoint3d(&mCenter);
    pFiler->readDouble(&mRadius);

    return pFiler->filerStatus();
}


Adesk::Boolean MyCustomEnt::subWorldDraw(AcGiWorldDraw* pWorldDraw)
{
    assertReadEnabled();

    // Define the offsets for the four circles
    AcGeVector3d offsets[] = {
        AcGeVector3d(mRadius * 2, 0.0, 0.0),
        AcGeVector3d(-mRadius * 2, 0.0, 0.0),
        AcGeVector3d(0.0, mRadius * 2, 0.0),
        AcGeVector3d(0.0, -mRadius * 2, 0.0)
    };

    // Draw each circle
    for (int i = 0; i < 4; ++i)
    {
        AcGePoint3d circleCenter = mCenter + offsets[i];
        pWorldDraw->geometry().circle(circleCenter, mRadius, AcGeVector3d::kZAxis);
    }

    return Adesk::kTrue;
}



void addMyCustomEntToDrawing()
{
    // Create a new instance of MyCustomEnt
    MyCustomEnt* pMyCustomEnt = new MyCustomEnt();
    pMyCustomEnt->setCircleParameters(AcGePoint3d(0.0, 0.0, 0.0), 5.0); // Example parameters

    postToDb(pMyCustomEnt);

    //// Close the custom entity to decrement its reference count
    Acad::ErrorStatus es = pMyCustomEnt->close();
}


Acad::ErrorStatus
postToDb(AcDbEntity* ent)
//
//  Append specified entity to current space of current drawing.
//
{
    AcDbObjectId objId;

    return postToDb(ent, objId);
}
Acad::ErrorStatus
postToDb(AcDbEntity* ent, AcDbObjectId& objId)
{

    Acad::ErrorStatus      es;
    AcDbBlockTable* pBlockTable;
    AcDbBlockTableRecord* pSpaceRecord;

    if ((es = acdbHostApplicationServices()->workingDatabase()->
        getSymbolTable(pBlockTable, AcDb::kForRead))
        != Acad::eOk) {
        return es;
    }

    if ((es = pBlockTable->getAt(ACDB_MODEL_SPACE,
        pSpaceRecord,
        AcDb::kForWrite)) != Acad::eOk) {
        return es;
    }

    

    if ((es = pSpaceRecord->appendAcDbEntity(objId, ent)) != Acad::eOk) {
        return es;
    }

    if ((es = pSpaceRecord->close()) != Acad::eOk) {
        return es;
    }
    if ((es = pBlockTable->close()) != Acad::eOk) {
        return es;
    }
    return ent->close();
}



void
initApp()
{
    acedRegCmds->addCommand(_T("MyCustomEnt_CMDS"),
        _T("FOUR_CIRCLES"), _T("FCC"), ACRX_CMD_MODAL,
        addMyCustomEntToDrawing);

    MyCustomEnt::rxInit();
    acrxBuildClassHierarchy();
}
//
//
// The clean up function called from the acrxEntryPoint() function during the
// kUnloadAppMsg case removes this application's
// command set from the command stack and removes this application's
// custom classes from the ACRX runtime class hierarchy.
//
void
unloadApp()
{
    acedRegCmds->removeGroup(_T("MyCustomEnt_CMDS"));   
    deleteAcRxClass(MyCustomEnt::desc());
}
//
// END CODE APPEARING IN SDK DOCUMENT.
//
//
// ARX entry point
//
AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
    switch (msg) {
    case AcRx::kInitAppMsg:
        acrxDynamicLinker->unlockApplication(appId);
		acrxDynamicLinker->registerAppMDIAware(appId);
        initApp();
        break;
    case AcRx::kUnloadAppMsg:
        unloadApp();
    }
    return AcRx::kRetOK;
}

 

Upon reaching line 118, continuing the debugging process triggers an exception as soon as the execution exits the "addMyCustomEntToDrawing()" method.

 

furqananees2007_3-1735241031167.pngfurqananees2007_4-1735241040482.png

 

Could you please help me identify the issue in my code? I'm unsure if I've made an error or if there are any missing external references or files.

 

0 Likes
Reply
67 Views
1 Reply
Reply (1)

owenwengerd
Advisor
Advisor

Check the second argument to your ACRX_DXF_DEFINE_MEMBERS macro. It should be AcDbEntity to match the class declaration.

--
Owen Wengerd
ManuSoft