惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
爱范儿
爱范儿
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
Latest news
Latest news
The Hacker News
The Hacker News
Cyberwarzone
Cyberwarzone
博客园 - 【当耐特】
Project Zero
Project Zero
小众软件
小众软件
T
Tailwind CSS Blog
量子位
博客园 - 聂微东
I
Intezer
美团技术团队
S
SegmentFault 最新的问题
T
Tor Project blog
Spread Privacy
Spread Privacy
V
Vulnerabilities – Threatpost
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Jina AI
Jina AI
罗磊的独立博客
B
Blog RSS Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Troy Hunt's Blog
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
宝玉的分享
宝玉的分享
C
Cisco Blogs
L
LINUX DO - 热门话题
Last Week in AI
Last Week in AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
AI
AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Azure Blog
Microsoft Azure Blog
L
LINUX DO - 最新话题
Know Your Adversary
Know Your Adversary
GbyAI
GbyAI
Engineering at Meta
Engineering at Meta
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
The Register - Security
The Register - Security
L
LangChain Blog
博客园 - 叶小钗
T
Tenable Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

博客园 - 人生为卒

CAD缺失字体如何处理 Excel 快速拖动公式的方法 微信小程序隐私审核 微信小程序创建流程 mysql 查询数据库的所有表格字段 Excel 根据单元格值设置行颜色 cmd安装Windows服务 log4.config MySq 表内存占用情况 C# 检测并重启windows服务,IIS应用池 redis 服务安装 Windows系统下本地MQTT服务器搭建,及开机自启 Navicat设置备份文件存储路径 Windows自动录屏功能 spring中常用注解 Windows系统 nacos 部署 解决不能访问GitHub的问题 Java 打包到部署子工程出错 Java-Maven基础
CAD二次开发入门:WPF类库
人生为卒 · 2024-08-14 · via 博客园 - 人生为卒

参考学习视频:https://www.bilibili.com/video/BV16Y411v7kr/?spm_id_from=333.337.search-card.all.click&vd_source=fbb64ea20b269b753497bf6c2499fc29

 第一步:创建WPF类库,并写CAD调用方法

 修改输出类型为:类库

 添加CAD开发需要的类库

main页面添加以下内容:

    <Grid>
        <Button Height="50" Click="Button_Click" Margin="285,184,157,185" Content="打开程序" Tag=""/>
        <TextBox x:Name="txtPath" HorizontalAlignment="Left" Height="23" Margin="245,110,0,0" TextWrapping="Wrap" Text="D:\Program Files (x86)\Tencent\WeChat\WeChat.exe" VerticalAlignment="Top" Width="450"/>
    </Grid>

main后台添加以下内容:

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string Path = "";
            try
            {
                Path = @"D:\Program Files (x86)\Tencent\WeChat\WeChat.exe";
                if (!string.IsNullOrEmpty(txtPath.Text))
                {
                    Path = txtPath.Text;
                }
                System.Diagnostics.Process.Start(Path);
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.CurrentDocument.Editor.WriteMessage("启动成功:" + Path);
            }
            catch (Exception ex)
            {

                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.CurrentDocument.Editor.WriteMessage("路径:" + Path + ",启动异常," + ex.Message);
            }
        }

新增一个类,写CAD可执行方法,OpenExe :

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfApp4
{
     public class Class1
    {
       [CommandMethod("OpenExe")] 
       public void OpenExe()
        {
            MainWindow main = new MainWindow();
            Application.ShowModelessWindow(main);
        }
    }
}

程序开发完成,生成动态库 dll:

  第二步:打开CAD,引用生成的动态库,并调用方法打开画面

CAD引用dll,使用指令【NETLOAD】,之后选择dll: 

 CAD调用wpf动态库的方法: 

命令输入方法名:openexe

 执行命令后,CAD自动打开WPF的画面

第三步:启动CAD,进行代码联调