使用最新版ODA试用版创建dwg文件

工程软件实在是变化太慢,16年接触这个oda,现在都2021年了,仍然变化不大,读取cad还是需要这个oda。希望国产cad(完全是自己的核心库,并非使用什么oda)软件早点发展壮大。有种我们现在不开发,我们的子孙后代还得趟这个坑的感觉(长津湖看多了)。

个人的技术没办法实现这个目标,只能搞应用了,只为减少后来者的时间。

1、官网申请oda的sdk

Home | Open Design Alliance

2、申请60天的试用期并成功激活,邮件里有教程,按教程操作即可。

3、生成开发激活码(照下面的链接操作,需要登录)

ODA (Login)

4、以下以C#生成dwg为例

sdk包里有个CDevGuideExamplesProject的程序,里面有各种生成dwg文件的方法。以生成直线为例,修改里面的dwg版本,我电脑是14版本,所以生成的文件也改为14版本。

然后创建一个项目,其中注意有个ActivationData.cs类,就是第3步生成的。

 最后上代码:

static void Main(string[] args)
        {
            String strPath = Environment.GetEnvironmentVariable("PATH");
            String strPathModules = ""; // System.Environment.CurrentDirectory;
            Environment.SetEnvironmentVariable("PATH", strPathModules + ";" + strPath);

            Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature); // 第三步的激活码
            Teigha.Runtime.Services tdSrv = new Teigha.Runtime.Services();
            LineEx lineEx = new LineEx(@"D:\test\odatest\"); // 创建线
            tdSrv.Dispose(); // 关闭服务
        }

生成的dwg文件。

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要在Qt中读取DWG文件中的坐标信息,可以使用DWG阅读器库,例如ODA的Teigha库。以下是一些示例代码,演示如何使用Teigha库和Qt读取DWG文件中的坐标信息: ```cpp #include <QtWidgets/QApplication> #include <QtWidgets/QMainWindow> #include <OdaCommon.h> #include <Gi/GiViewport.h> #include <Gi/GiGeometrySimplifier.h> #include <Gi/GiSubEntityTraits.h> #include <Gs/Gs.h> #include <Ge/GeMatrix3d.h> #include <RxVariantValue.h> #include <RxObjectImpl.h> #include <RxModule.h> class DwgViewer : public QMainWindow, public OdGiGeometrySimplifier { public: DwgViewer(QWidget *parent = 0) : QMainWindow(parent) { OdRxModulePtr pMod = ::odrxDynamicLinker()->loadModule(OdString("TD_Root")); if (pMod.isNull()) throw std::runtime_error("Cannot load Teigha module"); OdRxModulePtr pRenderMod = ::odrxDynamicLinker()->loadModule(OdString("TD_Gs")); if (pRenderMod.isNull()) throw std::runtime_error("Cannot load Teigha render module"); m_pGsDevice = OdGsDevicePtr(OdGsDevice::createObject(), OdRxObjectImpl<OdGsDevice>); m_pGsView = OdGsViewPtr(OdGsView::createObject(), OdRxObjectImpl<OdGsView>); m_pGsView->setViewport(m_pGsDevice->createViewport()); this->setCentralWidget(m_pGsView->viewport()->widget()); this->resize(800, 600); OdDbDatabasePtr pDb = OdDbDatabase::createObject(); if (pDb.isNull()) throw std::runtime_error("Cannot create database"); if (pDb->readDwgFile(OdString("<filepath>")) != eOk) throw std::runtime_error("Cannot read DWG file"); OdDbBlockTablePtr pBlockTable = pDb->getBlockTable(); if (!pBlockTable.isNull()) { OdDbBlockTableRecordPtr pRecord; if (pBlockTable->getAt(OdString("Model_Space"), pRecord) != eOk) throw std::runtime_error("Cannot get Model_Space"); OdDbBlockTableRecordIteratorPtr pIterator = pRecord->newIterator(); while (!pIterator->done()) { OdDbEntityPtr pEntity = pIterator->entity(); if (!pEntity.isNull()) { pEntity->subOpen(); pEntity->subWorldDraw(this); pEntity->subClose(); } pIterator->step(); } } m_pGsView->setViewportBorderWidth(0); m_pGsView->add(OdGsDevicePtr(m_pGsDevice)); m_pGsDevice->setBackgroundColor(ODRGB(255, 255, 255)); m_pGsView->invalidate(); m_pGsView->update(); } virtual void polylineOut(OdInt32 nbPoints, const OdGePoint3d* pVertexList) { // 处理每个多边形的坐标信息 for (int i = 0; i < nbPoints; ++i) { OdGePoint3d point = pVertexList[i]; // 处理坐标点,例如打印它们 qDebug() << point.x << point.y << point.z; } } private: OdGsDevicePtr m_pGsDevice; OdGsViewPtr m_pGsView; }; int main(int argc, char *argv[]) { QApplication a(argc, argv); try { DwgViewer viewer; viewer.show(); a.exec(); } catch (const std::exception& ex) { qDebug() << ex.what(); return 1; } return 0; } ``` 请注意,上面的示例代码仅演示了如何读取DWG文件中的坐标信息,并打印出来。您可以根据您的实际需求,对代码进行更改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值