Qt ObjectARX 2022

发布时间 2023-10-17 11:43:28作者: 一杯清酒邀明月

QT中的ARX配置

LoadQtDlls.pro

 1 TARGET = QTARXLoadQtDlls
 2 #the sdk include path
 3 INCLUDEPATH += "D:\ObjectARX 2022\inc"
 4 INCLUDEPATH += "D:\ObjectARX 2022\inc-x64"
 5  
 6 #rxapi.lib; acdb21.lib; acge21.lib; acad.lib; ac1st21.lib; accore.lib;
 7 LIBS+= -L"D:\ObjectARX 2022\lib-x64" -lrxapi
 8 LIBS+= -L"D:\ObjectARX 2022\lib-x64" -lacdb24
 9 LIBS+= -L"D:\ObjectARX 2022\lib-x64" -lacge24
10 LIBS+= -L"D:\ObjectARX 2022\lib-x64" -lacad
11 LIBS+= -L"D:\ObjectARX 2022\lib-x64" -lac1st24
12 LIBS+= -L"D:\ObjectARX 2022\lib-x64" -laccore
13  
14 #DEF_FILE
15 DEF_FILE += $$PWD/AcRxDefault.def
16  
17 #use md dll
18 QMAKE_CXXFLAGS += /MD
19  
20 #change .dll to .arx
21 TARGET_EXT = .arx
22  
23 #remove _DEBUG
24 DEFINES -= _DEBUG 
25 DEFINES += _OBJECT_ARX_VERSION_X64_=2022
26  
27 QT       += core
28 QT       += gui
29 QT       += widgets
30 QT       += qml
31  
32 #Qt project template
33 TEMPLATE = lib
34  
35 SOURCES += this_main.cpp \
36     form.cpp
37  
38 RESOURCES += \
39     images.qrc
40  
41 DESTDIR = $$PWD/../../release/Autocad2022
42  
43 FORMS += \
44     form.ui
45  
46 HEADERS += \
47     form.h

ARX入口书写

this_main.cpp

 1 #pragma warning( push)
 2 #pragma warning (disable: 4189 4100 )
 3 #include <Windows.h>
 4 #include <arxHeaders.h>
 5 #pragma warning( pop)
 6  
 7 #include <string_view>
 8  
 9 using namespace std::string_literals;
10  
11 #include <QtWidgets>
12 #include <QtQml>
13 #include<QMessageBox>
14  
15 inline void HellowWorld() {
16     acutPrintf(LR"(Hellow Word!
17 )");
18 }
19 inline void HellowWorldARX() {
20 //    QJSEngine varE;
21 //    varE.evaluate( QString("1+1") );
22     {
23         QMessageBox varBox ;
24         varBox.setText(("Hellow World!"));
25         varBox.exec() ;
26     }
27     auto varDataTime = QDateTime::currentDateTime().toString().toStdWString();
28     varDataTime = LR"(Hellow World!)" + varDataTime ;
29     acutPrintf(varDataTime.c_str());
30 }
31  
32 namespace {
33     namespace _cpp_private {
34 const std::string qtApplicationPath ="123";/*!!!*/
35 //#if _OBJECT_ARX_VERSION_X64_ == 2018
36 //            u8R"(D:\Program Files\AutoCAD 2018\acad.exe)"s;
37 //#else
38 //            u8R"(D:\Program Files\AutoCAD 2022\AutoCAD 2022\acad.exe)";
39 //#endif
40         inline int & getArgc() {
41             static int ans;
42             ans = 1;
43             return ans;
44         }
45         inline char** getArgv() {
46             static char acadpath[] =u8R"(D:\Program Files\AutoCAD 2022\AutoCAD 2022\acad.exe)";
47             static char *argv[] = { nullptr };
48             std::copy(qtApplicationPath.begin(), qtApplicationPath.end(),
49                 static_cast<char*>(acadpath));
50             argv[0] = static_cast<char *>(acadpath);
51             return argv;
52         }
53     }
54 }/*namespace*/
55  
56 extern "C" AcRx::AppRetCode
57 acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt) {
58     switch (msg) {
59     case AcRx::kInitAppMsg: {
60         acrxDynamicLinker->unlockApplication(pkt);
61         acrxRegisterAppMDIAware(pkt);
62         /*****************************************/
63         {
64             if (qApp == nullptr) {
65                 /*create the qt applicaton and never destory it*/
66                 auto varQtApplication =
67                     new QApplication(_cpp_private::getArgc(), _cpp_private::getArgv());
68                 (void)varQtApplication;
69             }
70             {
71                 /*force to load images plugins*/
72                 QImage varImage{ QString(":/png/this.png") };
73                 varImage.width();
74                 varImage.height();
75             }
76  
77         }
78         /*****************************************/
79         acedRegCmds->addCommand(
80             L"SSTD_GLOBAL_CMD_GROUP",
81             L"HellowWorld",
82             L"HellowWorld",
83             ACRX_CMD_MODAL,
84             &HellowWorldARX);
85     }break;
86     case AcRx::kUnloadAppMsg: {}break;
87     default:break;
88     }
89     return AcRx::kRetOK;
90 }
91  
92 /********************************/

代码结构

结果展示

 this.png

生成的arx

细节注意

arx同级目录的dll

arx同级目录的dll是qt编译出的,不然无法加载

使用的命令D:\Qt\5.15.2\msvc2019_64>windeployqt.exe C:\Users\yhx\Downloads\ObjectArxAutocad2018Vs2017Qt59-master\ObjectArxAutocad2018Vs2017Qt59-master\release\Autocad2022\QTARXLoadQtDlls.arx

CAD加载arx
使用命令arx

QT项目配置