Deleting AutoCAD Layouts Causes Export to PDF to Fail

64 Views Asked by At

I have an AutoCAD.NET bundle which I use in Design Automation. As part of it's overall processing it deletes Layouts. The C# code used to delete the Layouts is:

using (Transaction trans = db.TransactionManager.StartTransaction())
{
// Get Layout Dictionary
DBDictionary layoutDict = (DBDictionary)trans.GetObject(db.LayoutDictionaryId, OpenMode.ForWrite);
// if the dictionary contains the space name, delete it
if (layoutDict.Contains(space.Name))
{
LayoutManager.Current.DeleteLayout(space.Name);
}
// Commit the transaction
trans.Commit();
}

This works properly when running in the AutoCAD application, the accoreconsole and in Platform Services using AutoCAD Design Automation; the Layout named by space.Name is removed.

My problem is when I try to execute a script to publish the Layouts to PDF. The script I use is:

DC_LOADDATA
"D:\Desktop\Testing\AutoCAD Tests\2024-01-29 Layouts\data\instructions.json"
DC_LAYOUT
SAVEAS
2018
"results\result.dwg"
TILEMODE 1
TILEMODE 0
PDFSHX 0
FILEDIA 0
-EXPORT
PDF
A
"results\result.pdf"
\<blank line\>

When I remove Layouts from the end of the Layout tabs:

Four Layout tabs with the last two highlighted in red

The script performs as expected in the accoreconsole, I get the "result.pdf" file and the console output is:

Command: TILEMODE
Enter new value for TILEMODE \<1\>: 1

Command: TILEMODE
Enter new value for TILEMODE \<1\>: 0
Regenerating layout.
Regenerating model - caching viewports.

Command: PDFSHX
Enter new value for PDFSHX \<0\>: 0

Command: FILEDIA
Enter new value for FILEDIA \<0\>: 0

Command: -EXPORT
Enter file format \[Dwf/dwfX/Pdf\] \<Pdf\>PDF
Enter plot area \[Current layout/All layouts\]\<All layouts\>: A

Enter file name \<result-Layout2-US.pdf\>: "results\\result.pdf"
Regenerating layout.
Regenerating model.
Effective plotting area:  17.00 wide by 11.00 high
Effective plotting area:  16.40 wide by 9.80 high

Plotting viewport 2.

Plotting viewport 1.
Regenerating layout.
Regenerating model.
Effective plotting area:  17.00 wide by 11.00 high
Effective plotting area:  16.40 wide by 9.80 high

Plotting viewport 2.

Plotting viewport 1.

However, when I remove Layouts from the begining of the layout tabs:

Four layout tab with the first two highlighted in red.

The script fails. In accoreconsole this is the output I get:

Command: TILEMODE
Enter new value for TILEMODE \<1\>: 1

Command: TILEMODE
Enter new value for TILEMODE \<1\>: 0
Regenerating layout.
Regenerating model - caching viewports.

Command: PDFSHX
Enter new value for PDFSHX \<0\>: 0

Command: FILEDIA
Enter new value for FILEDIA \<0\>: 0

Command: -EXPORT
Enter file format \[Dwf/dwfX/Pdf\] \<Pdf\>PDF
Enter plot area \[Current layout/All layouts\]\<All layouts\>: A

Command: "results\\result.pdf"
Unknown command "PDF"".  Press F1 for help.

Since the console is prompting for a Command after prompting to "Enter plot area", it seems that the script is failing there. I get the same results when I run the script in the AutoCAD application, or if I type these commands manually into the AutoCAD application. In the application, it just looks like the command line hangs, I get a blank line in the command entry and have to hit escape to get it back to saying "Type a command".

In addition, when running in Design Automation, I get the following as part of the output, with the part about "An unexpected error happened during phase Publishing of job" pointing to a failure of the -EXPORT.

\[02/01/2024 14:42:51\] End AutoCAD Core Engine standard output dump.
\[02/01/2024 14:42:51\] Error: AutoCAD Core Console output contains error(s).
\[02/01/2024 14:42:51\] End script phase.
\[02/01/2024 14:42:51\] Start upload phase.
\[02/01/2024 14:42:51\] Error: Non-optional output \[result.pdf\] is missing.
\[02/01/2024 14:42:51\] Error: An unexpected error happened during phase Publishing of job.
\[02/01/2024 14:42:51\] Job finished with result FailedMissingOutput

Why is it that removing Layouts from the end of the Layout tab works, but removing them from the begining causes the -EXPORT to fail, and more importantly, how do I fix this?

I have searched the web for a solution. Similar problems seemed to be fixed by toggling TILEMODE between Model Space and Paper space so I added this to my script. The results shows up in the output with line about "Regenerating layout.". I also make sure that I always have at least one Layout tab left.

I would expect to be able to Export the remaining Layout tabs to a PDF.
0

There are 0 best solutions below