Replies: 9 comments 18 replies
-
|
It works with the @command(flags=Ap.CmdFlags.SESSION)
def doit_pytest():
pytest.main([__file__]) |
Beta Was this translation helpful? Give feedback.
-
|
@command
def doit5():
import faulthandler
faulthandler.enable()
test_1()maybe it's worth adding an option to enable faulthandler [system]
optimization_level = 0
faulthandler = true
[user]
disable_onload = false |
Beta Was this translation helpful? Give feedback.
-
|
seems I needed to add some attributes to eStdout and eStderr, now doit5 and doit_pytest work in autocad |
Beta Was this translation helpful? Give feedback.
-
|
I didn't receive any Windows fatal exception: access violation yet |
Beta Was this translation helpful? Give feedback.
-
|
This also causes tested on zwcad 2025 and 2027 from __future__ import annotations
from pathlib import Path
from pyrx import Ap, Ax, command
from pyrx.console import console
doc_path = Path(__file__).parent / "Drawing1.dwg"
def open_doc_by_path(doc_path: Path, read_only: bool = False) -> Ap.Document:
axdoc = Ax.AcadApplication().documents().open(str(doc_path), read_only)
doc = doc_for_ax_doc(axdoc)
return doc
def doc_for_ax_doc(axdoc: Ax.AcadDocument) -> Ap.Document:
doc_man = Ap.DocManager()
for doc in doc_man.documents():
if doc.acadDocument() == axdoc:
return doc
raise ValueError(
f"No Ap.Document found for Ax.AcadDocument with fullName '{axdoc.fullName()}'"
)
def close_doc_by_path(doc_path: Path):
doc_man = Ap.DocManager()
if not doc_man.isApplicationContext():
raise RuntimeError("close_doc_by_path can only be called from an application context")
for doc in doc_man.documents():
if Path(doc.fileName()) == doc_path:
doc_man.appContextCloseDocument(doc)
def test_1():
doc_1 = open_doc_by_path(doc_path, read_only=False)
doc_2 = open_doc_by_path(doc_path, read_only=True)
close_doc_by_path(doc_path)
@command(flags=Ap.CmdFlags.SESSION)
def doit7():
test_1()
@command(flags=Ap.CmdFlags.SESSION)
def doit7_pytest():
import pytest
with console():
pytest.main([__file__, "-v", "-s"])
input("Press Enter to continue...")
@command(flags=Ap.CmdFlags.SESSION)
def doit7_faulthandler():
import faulthandler
with console():
faulthandler.enable()
test_1()
input("Press Enter to continue...") |
Beta Was this translation helpful? Give feedback.
-
|
here is the drawing I'm testing with |
Beta Was this translation helpful? Give feedback.
-
|
I tested it on your file, restarted the computer - still the same |
Beta Was this translation helpful? Give feedback.
-
|
I think it has to do with the behavior or opening the same document twice. AutoCAD allows this and is able to track the document state Interesting is that if I reverse the order, for doc in reversed(doc_man.documents()):
if Path(doc.fileName()) == doc_path:
doc_man.appContextCloseDocument(doc) |
Beta Was this translation helpful? Give feedback.
-
|
C++ test for ref // reported https://github.com/CEXT-Dan/PyRx/discussions/531
static void openDocAppCtx(const AcString& fullpath)
{
if (auto es = acDocManager->appContextOpenDocument(fullpath); es != eOk)
acutPrintf(L"\nError %ls: ", acadErrorStatusText(es));
}
static void closeDocAppCtx(const AcString& fullpath)
{
using dociter = std::unique_ptr<AcApDocumentIterator>;
for (dociter iter(acDocManager->newAcApDocumentIterator()); !iter->done(); iter->step())
{
auto doc = iter->document();
if (doc != nullptr)
{
if (fullpath.compareNoCase(doc->fileName()) == 0)
{
if (auto es = acDocManager->appContextCloseDocument(doc); es != eOk)
acutPrintf(L"\nError %ls: ", acadErrorStatusText(es));
}
}
}
}
static void closeDocAppCtxRev(const AcString& fullpath)
{
using dociter = std::unique_ptr<AcApDocumentIterator>;
std::vector<AcApDocument*> docs;
for (dociter iter(acDocManager->newAcApDocumentIterator()); !iter->done(); iter->step())
docs.push_back(iter->document());
std::reverse(docs.begin(), docs.end());
for (auto doc : docs)
{
if (doc != nullptr)
{
if (fullpath.compareNoCase(doc->fileName()) == 0)
{
if (auto es = acDocManager->appContextCloseDocument(doc); es != eOk)
acutPrintf(L"\nError %ls: ", acadErrorStatusText(es));
}
}
}
}
static void AcRxPyApp_idoit1(void) // ACRX_CMD_SESSION
{
AcString fullpath = L"M:\\Dev\\Projects\\PyRxGit\\PySamples\\Drawing1.dwg";
openDocAppCtx(fullpath);
openDocAppCtx(fullpath);
int flag = 0;
acedGetInt(L"\nPress 0 to leave open, 1 to close: ", &flag);
if (flag)
closeDocAppCtxRev(fullpath);
} |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
DOITexecutes without any problem,DOIT_PYTESTreportsWindows fatal exception: access violationBeta Was this translation helpful? Give feedback.
All reactions