嵌入式开发工作软件环境清单

VSCode

https://code.visualstudio.com/

Notepad++

https://www.notepad-plus-plus.org/downloads/

Putty 远程登录

https://www.putty.org/

https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

WinSCP

https://winscp.net/download/WinSCP-6.3.6-Setup.exe/download

Tortoisegit windows版

https://tortoisegit.org/download/

GitWindows客户端

https://gitforwindows.org/

QT5.9.9

由于限制了国内IP地址,需要梯子才能访问 https://download.qt.io/new_archive/qt/5.9/5.9.9/

https://download.qt.io/new_archive/qt/5.9/5.9.9/qt-opensource-windows-x86-5.9.9.exe

WinMerge 对比工具

https://winmerge.org/downloads/?lang=zh_cn

https://downloads.sourceforge.net/winmerge/WinMerge-2.16.46-x64-Setup.exe

Eclipse IDE For Embedded C/C++ Developers

https://www.eclipse.org/downloads/

串口调试软件 SSCOM5.13

http://www.daxia.com/

MySQL数据库管理软件 SQLyog 社区版

SQLyog Community Edition

【CAD插件开发】批量修改图纸中在文字(C++)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void ChangeTextInDrawing() {
    AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
    AcDbBlockTable* pBlockTable;
    pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
    AcDbBlockTableRecord* pModelSpace;
    pBlockTable->getAt(ACDB_MODEL_SPACE, pModelSpace, AcDb::kForRead);
 
    AcDbObjectIdArray entityIds;
    pModelSpace->getIDsOfClass(AcDb::kMText, entityIds);
    
    for (auto& id : entityIds) {
        AcDbEntity* pEntity;
        pDb->openObject(pEntity, id, AcDb::kForRead);
        if (pEntity->isKindOf(AcDbMText::desc())) {
            AcDbMText* pText = AcDbMText::cast(pEntity);
            const char* text = pText->textString();
            if (text) {
                std::string newText = std::string(text).replace(0, 5, "NEW"); // 示例:将前5个字符替换为"NEW"
                pText->setTextString(newText.c_str());
            }
            pText->downgradeOpen(); // 降级对象以关闭它,但不保存到数据库中
        }
        pEntity->close(); // 关闭实体对象
    }
    pModelSpace->close();
    pBlockTable->close();
}

【CAD二次开发】批量修改图纸日期和做着(C++)

C++进行二次开发来批量修改图纸中的日期和作者信息

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "aced.h"
#include "dbents.h"
#include "dbdictionary.h"
#include "dbdict.h"
#include "dbxutil.h"
#include "adscodes.h"
 
void updateDrawingInfo(const char* newDate, const char* newAuthor) {
    AcDbDatabase* pDb = acdbHost()->workingDatabase();
    AcDbDictionary* pDict = NULL;
    if (AcDbDictionary::cast(pDb->getNamedObjectsDictionary(), pDict) == Acad::eOk) {
        AcDbDictionaryEntryIterator* iter = NULL;
        if (pDict->getEntryIterator(iter) == Acad::eOk) {
            for (; !iter->done(); iter->next()) {
                AcRxClass* pClass = iter->objectClass();
                if (pClass == AcDbBlockTableRecord::desc()) {
                    AcDbBlockTableRecord* pRecord = AcDbBlockTableRecord::cast(iter->object());
                    if (pRecord && pRecord->isLayout()) { // 只修改布局的属性
                        pRecord->setXData(kDwgStampAppName, kDwgStampDate, newDate);
                        pRecord->setXData(kDwgStampAppName, kDwgStampAuthor, newAuthor);
                    }
                }
            }
            delete iter;
        }
    }
}

【CAD插件开发】批量打印图纸(C++)

实现图纸批量打印 使用C++ API遍历图纸中的所有图纸(通常是DWG文件)并执行打印操作:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "aced.h"
#include "dbdict.h"
#include "dbents.h"
#include "acedads.h"
#include "acedcmd.h"
#include "acdocman.h"
#include "adslib.h"
#include "dbfiler.h"
#include "adscodes.h"
#include <iostream>
 
void BatchPrint(const char* folderPath) {
    struct dirent *de;  // 目录项结构体
    DIR *dr = opendir(folderPath); // 打开目录
    if (dr == nullptr) {
        return; // 目录打开失败
    }
    while ((de = readdir(dr)) != nullptr) { // 读取目录项
        if (de->d_type == DT_REG) { // 只处理文件
            std::string fileName = de->d_name;
            if (fileName.find(".dwg") != std::string::npos) { // 检查文件扩展名是否为.dwg
                acDocManager->Open(folderPath, fileName.c_str(), NULL, NULL, NULL, NULL); // 打开图纸文件
                acDocManager->Document()->Print(); // 打印图纸
                acDocManager->CloseDocument(acDocManager->Document()); // 关闭图纸文件
            }
        }
    }
    closedir(dr); // 关闭目录流
}

【CAD插件开发】C++读取图纸图层

在使用CAD(计算机辅助设计)软件进行二次开发时,特别是在C++环境下,通常我们会使用一些专门的库来与CAD文件交互。对于AutoCAD,最常用的库是AutoCAD的官方开发库:ObjectARX和.NET的AutoCAD Map 3D。以下是一些基本步骤和示例代码,展示如何在C++中读取图纸的图层信息。

【CAD插件开发】读取外面块和图层

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
[CommandMethod("GetLayerPro")]
public static void GetLayerPro()
{
    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
    //新建一个数据库对象以读取Dwg文件          
    Database db = new Database(false, true);
    string fileName = "C:\\Drawing3.dwg";
    //如果指定文件名的文件存在          
    if(System.IO.File.Exists(fileName))
    {
        //把文件读入到数据库中          
        db.ReadDwgFile(fileName, System.IO.FileShare.Read, true, null);
        using(Transaction trans = db.TransactionManager.StartTransaction())
        {
            //获取数据库的图层表对象      
            LayerTable lt = (LayerTable) trans.GetObject(db.LayerTableId, OpenMode.ForRead);
            //循环遍历每个图层                   
            foreach(ObjectId layerId in lt)
            {
                LayerTableRecord ltr = (LayerTableRecord) trans.GetObject(layerId, OpenMode.ForRead);
                if(ltr != null)
                {
                    Autodesk.AutoCAD.Colors.Color layerColor = ltr.Color;
                    ed.WriteMessage("\n图层名称为:" + ltr.Name);
                    ed.WriteMessage("\n图层颜色为:" + layerColor.ToString());
                }
            }
            trans.Commit();
        }
    }
}


[CommandMethod("GetEntitiesFromLayer")]
public static void GetEntitiesFromLayer(string layerName)
{
    Database db = HostApplicationServices.WorkingDatabase;
    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
    using(Transaction trans = db.TransactionManager.StartTransaction())
    {
        LayerTable lt = (LayerTable) trans.GetObject(db.LayerTableId, OpenMode.ForRead);
        if(lt.Has(layerName))
        {
            BlockTableRecord ltr = (BlockTableRecord) trans.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
            foreach(ObjectId objId in ltr)
            {
                Entity ent = (Entity) trans.GetObject(objId, OpenMode.ForRead);
                // 假设该图层中有一个圆       
                Circle myCircle = (Circle) ent;
                if(ent.Layer == layerName && myCircle != null)
                {
                    Point3d cirCenter = myCircle.Center;
                    ed.WriteMessage("\n圆心为:" + cirCenter.ToString());
                }
            }
        }
        trans.Commit();
    }
}

【CAD插件开发】获取地质图纸中的钻孔信息

功能

通过CAD二次开发获取块名称、编号、位置、属性等息。

代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 public void GetCADLocationData()
 {
     // 获取当前文档和数据库
     Document doc = Application.DocumentManager.MdiActiveDocument;
     Database db = doc.Database;
     Editor ed = doc.Editor;
     // 开始事务
     using(Transaction tr = db.TransactionManager.StartTransaction())
     {
         // 打开模型空间块表记录
         BlockTable blockTable = (BlockTable) tr.GetObject(db.BlockTableId, OpenMode.ForRead);
         BlockTableRecord btr = (BlockTableRecord) tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead);
         // 遍历模型空间中的所有对象
         int n = 1;
         foreach(ObjectId id in btr)
             {
                 // 检查是否为块参照
                 Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity;
                 BlockReference blockRef = ent as BlockReference;
                 //ed.WriteMessage("1234");
                 //ed.WriteMessage(blockRef.Name);
                 if(ent != null && ent is BlockReference && blockRef.Name == "钻孔")
                 {
                     // 输出块名称、编号
                     ed.WriteMessage($ "\n块名称: {blockRef.Name + " - " + n}");
                     // 输出块坐标XY
                     ed.WriteMessage($ "\n块位置: {blockRef.Position.ToString()}");
                     // 遍历块中的每个属性
                     foreach(ObjectId attrId in blockRef.AttributeCollection)
                     {
                         DBObject obj = tr.GetObject(attrId, OpenMode.ForRead);
                         if(obj is AttributeReference)
                         {
                             AttributeReference attribute = obj as AttributeReference;
                             // 输出属性值--钻孔号、高程值
                             ed.WriteMessage($ "\n{attribute.Tag+": "+ attribute.TextString}");
                         }
                     }
                     n++;
                 }
             }
             // 提交事务
         tr.Commit();
     }
 }

运行截图

Image

中望CAD.NET二次开发

开发环境

  • 中望CAD版本:2021
  • VS版本:2015

1.创建类库项目

.NET Framework4.7

2.添加类库

ZwDatabaseMgd.dll ZwManaged.dll

这两个DLL位于中望CAD安装目录下,复制本地属性改为False

3.导入命名空间

1
2
3
4
using ZwSoft.ZwCAD.Runtime;
using ZwSoft.ZwCAD.ApplicationServices;
using ZwSoft.ZwCAD.DatabaseServices;
using ZwSoft.ZwCAD.EditorInput;

4.定义命令

1
2
3
4
5
6
7
8
9
[CommandMethod("test")]
public void test()
       {
           DocumentCollection docs = Application.DocumentManager;
           Document doc = docs.MdiActiveDocument;
           Editor ed = doc.Editor;
           Database db = doc.Database;
           ed.WriteMessage("test");
       }

5.编译程序

6.启动中望cad

7.在命令行中输入test,命令行中会显示“test”

中望CAD插件开发环境配置

中望CAD软件开发具有高效稳定的开发环境、丰富的API接口、广泛的用户支持、多平台兼容性。其中,高效稳定的开发环境是最为关键的一点。

中望CAD提供了一个全面的开发平台,支持多种编程语言(如LISP、VBA、.NET和C++),使得开发者能够快速、稳定地创建和集成各种应用。