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).