Addon not loading in zero document state

Addon not loading in zero document state

prakash.muthu
Advocate Advocate
902 Views
9 Replies
Message 1 of 10

Addon not loading in zero document state

prakash.muthu
Advocate
Advocate

Hi,

 

The .arx file not loading in startup when application started with zero document state. The same addon getting loaded on opening document. Is this AutoCAD behavior or any solution available. 

Thank you.

0 Likes
903 Views
9 Replies
Replies (9)
Message 2 of 10

Alexander.Rivilis
Mentor
Mentor

In kInitAppMsg message you cannot use document as far as AcApDocManager::curDocument() == 0 and acdbHostApplicationServices()->workingDatabase() == 0  in zero document state.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 3 of 10

prakash.muthu
Advocate
Advocate

The intension is not to use document in kInitAppMsg. Just to load addon arx and linked dll's in application startup.

0 Likes
Message 4 of 10

prakash.muthu
Advocate
Advocate

Still didn't get any solution for this problem. Is it AutoCAD restriction to load arx only when document in open. How about listening to app events without opening document. 

0 Likes
Message 5 of 10

daniel_cadext
Advisor
Advisor

You use acedRegisterOnIdleWinMsg in kInitAppMsg, do initialization,

then acedRemoveOnIdleWinMsg inside of AcedOnIdleMsgFn if it’s not needed

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 6 of 10

prakash.muthu
Advocate
Advocate

kInitAppMsg not getting called when application starts with startup 2 and start mode 0. Its getting called on creating new document or opening disk file.

0 Likes
Message 7 of 10

daniel_cadext
Advisor
Advisor

I thought it's always called, how would you call acrxLockApplication, or acrxBuildClassHierarchy() and other functions?

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 8 of 10

prakash.muthu
Advocate
Advocate

Not using mentioned methods. 

0 Likes
Message 9 of 10

daniel_cadext
Advisor
Advisor

Pretty sure kInitAppMsg is always called, you’re just not seeing it. Try making a sample with this code

 

//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"

//----------------------------------------------------------------------------
#define szRDS _RXST("")

//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class ArxTemplate : public AcRxArxApp
{
public:
    ArxTemplate() : AcRxArxApp()
    {
    }

    virtual AcRx::AppRetCode On_kInitAppMsg(void* pkt)
    {
        AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg(pkt);
        acedRegisterOnIdleWinMsg(OnIdle);
        return (retCode);
    }

    virtual AcRx::AppRetCode On_kUnloadAppMsg(void* pkt)
    {
        AcRx::AppRetCode retCode = AcRxArxApp::On_kUnloadAppMsg(pkt);
        acedRemoveOnIdleWinMsg(OnIdle);
        return (retCode);
    }

    virtual AcRx::AppRetCode On_kLoadDwgMsg(void* pkt) override
    {
        AcRx::AppRetCode retCode = AcRxDbxApp::On_kLoadDwgMsg(pkt);
        return retCode;
    }

    virtual void RegisterServerComponents()
    {
    }

    static void OnIdle()
    {
        static bool initOnce = false;
        if (!initOnce)
        {
            acedAlert(_T("\init once"));
            initOnce = true;
        }
    }

    static void ArxTemplate_doit(void)
    {

    }
};

//-----------------------------------------------------------------------------
#pragma warning( disable: 4838 ) //prevents a cast compiler warning, 
IMPLEMENT_ARX_ENTRYPOINT(ArxTemplate)
ACED_ARXCOMMAND_ENTRY_AUTO(ArxTemplate, ArxTemplate, _doit, doit, ACRX_CMD_TRANSPARENT, NULL)
#pragma warning( pop )
Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 10 of 10

prakash.muthu
Advocate
Advocate

Thanks @daniel_cadext  for the code sample. 
We also using similar code. The problem is not with kInitAppMsg. The arx file bundled in packagecontents not getting loaded when opening AutoCAD with startup 2. Same code getting called as mentioned in sample after opening a document. Maybe AutoCAD behavior to load addons when document in open.

0 Likes