0bjectARX2024 encountered an exception error with setCurrentLayout.

0bjectARX2024 encountered an exception error with setCurrentLayout.

mitsuru_shinohara_sx
Participant Participant
1,565 Views
10 Replies
Message 1 of 11

0bjectARX2024 encountered an exception error with setCurrentLayout.

mitsuru_shinohara_sx
Participant
Participant

When AutoCAD was upgraded from AutoCAD 2017 Mechanical to the 7th generation version of AutoCAD 2024 Mechanical,
An exception error occurred in setCurrentLayout at 0bjectARX2024.
Can you tell me how to deal with it?

 

The processing order is as follows:
①createLayout
②setDefaultPlotConfig
③updateLayoutTabs
④setCurrentLayout

The created layout is set to the current layout (layout to be processed).

0 Likes
Accepted solutions (2)
1,566 Views
10 Replies
Replies (10)
Message 2 of 11

tbrammer
Advisor
Advisor

Can you post sample code or even a sample project that allows to reproduce the problem?


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 3 of 11

mitsuru_shinohara_sx
Participant
Participant
The excerpted Sample code is described.
The process of creating a layout is performed in the following order:
=====================================================
<Ever pre-processing layout creation>
 
AcApLayoutManager *pLayoutManager = (AcApLayoutManager*)acdbHostApplicationServices()->layoutManager();
if(pLayoutManager != NULL){
AcDbObjectId layoutId = AcDbObjectId::kNull; //Layout ID
AcDbObjectId btrId = AcDbObjectId::kNull; //Block Table Record ID
 
//Generating Layouts
es = pLayoutManager->createLayout(cstrName.AllocSysString(),layoutId,btrId,pDb) ;
if(es == Acad::eOk ){
 
objID = layoutId ; //Layout ID
BTblReObjID = btrId ;  //Block Table Record ID
 
pLayoutManager->setDefaultPlotConfig(btrId);
pLayoutManager->updateLayoutTabs(); //renewal
pLayoutManager->setCurrentLayout(cstrName.AllocSysString());
 
//Adjusting the Layout - Adding to a Block
AcDbObjectPointer<AcDbLayout> pLayout(layoutId,AcDb::kForWrite) ; //layout
if(pLayout.openStatus() == Acad::eOk){
 
<From here, post-processing of layout creation>
===========================================
It worked fine until I upgraded from AutoCAD 2017 Mechanical to AutoCAD 2024 Mechanical.
 
Past efforts include:
[Past efforts]
(1)Check the error details with "try-catch". 
(2)Comment out the process that is causing the error.
(3)Run "existsLayout" and check the return value. (Check for the existence of the specified layout)
(4)Check the return value of "setCurrentLayout".
(5)Reverse the order of processing of "updateLayoutTabs" and "setCurrentLayout".
(6)Comment out the transaction processing that is performed before and after the layout creation process.
(7)Update the template to 2024.
(8)Review the AutoCAD environment (profiles, templates, print settings).
 
[Result]
(1)Try-catch does not confirm the error.
(2)I get an error with "setCurrentLayout" that I am processing elsewhere.
(3)Returns True (exists)
(4)Returns the unset state (zero if correct).
(5)The phenomenon remains unchanged.
(6)The phenomenon remains unchanged.
(7)The phenomenon remains unchanged.
(8)The phenomenon remains unchanged.


Please advise if there is a problem with the environment (profile, template, print settings).

 

0 Likes
Message 4 of 11

daniel_cadext
Advisor
Advisor

This works for me, maybe you just need to lock the document?

also you don't need the AllocSysString stuff

 

    static void AcRxPyApp_idoit(void)
    {
        AcAxDocLock lock; //Added a doc lock
        const CString cstrName{ L"WooHoo" }; //Get rid of the AllocSysString

        AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
        AcApLayoutManager* pLayoutManager = dynamic_cast<AcApLayoutManager*>(acdbHostApplicationServices()->layoutManager());

        AcDbObjectId layoutId;
        AcDbObjectId btrId;

        if (auto es = pLayoutManager->createLayout(cstrName, layoutId, btrId, pDb); es != eOk)
            acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));

        pLayoutManager->setDefaultPlotConfig(btrId);
        pLayoutManager->updateLayoutTabs();

        if (auto es = pLayoutManager->setCurrentLayout(cstrName, pDb); es != eOk)
            acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));

        AcDbObjectPointer<AcDbLayout> pLayout(layoutId, AcDb::kForWrite);
        if (auto es = pLayout.openStatus(); es != Acad::eOk)
            acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));

        acutPrintf(_T("\nYahoo! %ls"), acadErrorStatusText(Acad::eOk));
    }

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
Message 5 of 11

mitsuru_shinohara_sx
Participant
Participant


I tried executing the method.

The phenomenon remains unchanged.

 

An exception error is printed on line
"es = pLayoutManager->setCurrentLayout(cstrName, pDb)"

"acutprintf" cannot be output because "autoCAD" exits due to an exception error.

 

The debugger seems to return eOK(0).

 

The content of the exception error is "An unhandled exception occurred in 0x00007FFD3033C583 (accore.dll) (in acad.exe): 0xC0000005: An access violation occurred while reading location 0x0000000000000318. "

 

I also tried the case where "AcAxDocLock lock;" was added to "es = pLayoutManager->setCurrentLayout(cstrName, pDb)".

The phenomenon remains unchanged.

0 Likes
Message 6 of 11

daniel_cadext
Advisor
Advisor

How are you running this code, is it in a command context?

is pDb the active drawing or is this a side database?

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

daniel_cadext
Advisor
Advisor

The only other thing I can think of is calling acdbDoSetupForLayouts and acdbClearSetupForLayouts

 

 AcAxDocLock lock; //Added a doc lock
 const CString cstrName{ L"WooHoo" }; //Get rid of the AllocSysString

 AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();

 Adesk::ULongPtr contextHandle = 0;
 acdbDoSetupForLayouts(pDb, contextHandle);

 AcApLayoutManager* pLayoutManager = dynamic_cast<AcApLayoutManager*>(acdbHostApplicationServices()->layoutManager());

 AcDbObjectId layoutId;
 AcDbObjectId btrId;

 if (auto es = pLayoutManager->createLayout(cstrName, layoutId, btrId, pDb); es != eOk)
     acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));

 pLayoutManager->setDefaultPlotConfig(btrId);
 pLayoutManager->updateLayoutTabs();

 if (auto es = pLayoutManager->setCurrentLayout(cstrName, pDb); es != eOk)
     acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));

 AcDbObjectPointer<AcDbLayout> pLayout(layoutId, AcDb::kForWrite);
 if (auto es = pLayout.openStatus(); es != Acad::eOk)
     acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));

 acdbClearSetupForLayouts(contextHandle);

 acutPrintf(_T("\nYahoo! %ls"), acadErrorStatusText(Acad::eOk));
Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 8 of 11

mitsuru_shinohara_sx
Participant
Participant

I interpret that the command context = executed from the AutoCAD command.


>How are you running this code, is it in a command context?

I ran it via a self-made command.
I called a method just before the code in question.


>is pDb the active drawing or is this a side database?
The active drawing.
Only one "dwg" file is open at runtime.

0 Likes
Message 9 of 11

tbrammer
Advisor
Advisor

Have you tried to execute Daniel's code in "pure" AutoCAD / AutoCAD Mechanical 2024? I mean without any non Autodesk modules loaded and from a small ARX project that contains his code only?

If this works the root of the problem is probably in one of the other modules. Maybe a reactor, an overrule or a redefined command.

It it doesn't work there is probably a problem with your AutoCAD installation. Try to reinstall or repair it or try it on a diiferent machine.


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 10 of 11

mitsuru_shinohara_sx
Participant
Participant
Accepted solution

We also thought that this problem could be in other modules.
However, due to the black box, it is difficult.
If we find out anything, we will contact you.

0 Likes
Message 11 of 11

mitsuru_shinohara_sx
Participant
Participant
Accepted solution

This case has been resolved.
It turns out that there is an error in the other module.
I coordinated with the vendor and asked them to fix that module.
Now I have confirmed that it works without any issues.

Thank you very much for your advice and countermeasures.

0 Likes