ObjectARX, threads problem??

ObjectARX, threads problem??

suparhigh12345
Contributor Contributor
476 Views
5 Replies
Message 1 of 6

ObjectARX, threads problem??

suparhigh12345
Contributor
Contributor

If I have a function called 'linedraw' whose purpose is to create an 'acdb' object, and that function runs on a different thread using std::thread, I encounter an error with an 'Unhandled Access Violation Reading' message. The primary goal of running this function on a separate thread is to prevent it from blocking the main AutoCAD application. However, when I attempt to call this function inside the ARX entry point as follows:

 

....

case AcRx::kInitAppMsg:

std::thread(linedraw).detach(); // !!!!!!!

break;

etc...

 

I encounter the mentioned error. My intention is to avoid blocking the main AutoCAD app, especially when dealing with functions that may run indefinitely, such as calculations. Is there a solution for this scenario? Additionally, if I have the 'linedraw' function that should be triggered automatically (not from the command window) and can be initiated from another void() function or an external UI, is there a way to achieve this without causing the AutoCAD application to become unresponsive?

0 Likes
Accepted solutions (3)
477 Views
5 Replies
Replies (5)
Message 2 of 6

daniel_cadext
Advisor
Advisor
Accepted solution

ObjectARX is not thread-safe and multithreading is not supported...

https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-85F9B4B9-1949-4BA2-AE95-8FB85CC5CE47

 

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

suparhigh12345
Contributor
Contributor

Does this mean that there is no way to utilize ObjectARX from a different thread, and is it impossible to include an infinite loop calculation as a function inside 'kInitAppMsg' without blocking the AutoCAD application?

0 Likes
Message 4 of 6

moogalm
Autodesk Support
Autodesk Support
Accepted solution

Yes, you can't call any AcDb* API from different thread other than main thread. 

Message 5 of 6

daniel_cadext
Advisor
Advisor

Maybe you can use an event, a command event, AcedWatchWinMsgFn or on idle

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

Alexander.Rivilis
Mentor
Mentor
Accepted solution

How to use threads in ObjectARX?

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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