外部启动CAD

 static void Main(string[] args)
        {
             // 连接至 AutoCAD 应用程序   
            RegistryKey RegK = Registry.LocalMachine;
            RegistryKey software = RegK.OpenSubKey("Software\\Autodesk\\AutoCAD\\R17.1", false);

            if (software == null)
            {
                Console.WriteLine("AutoCAD 2008启动失败!");
                return;
            }
            // 判断注册表文件是否已经存在
            //if (IsReg) 
            //{
                Console.WriteLine("注册表文件已存在,AutoCAD 2008正常启动..");
                //Console.ReadLine();
                System.Type AcadType = System.Type.GetTypeFromProgID("AutoCAD.Application");
                Object acad= System.Activator.CreateInstance(AcadType);
                AcadType.InvokeMember("visible", System.Reflection.BindingFlags.SetProperty, null, acad, new object[] { true });
                Object documents = AcadType.InvokeMember("Documents", System.Reflection.BindingFlags.GetProperty, null, acad, null);
                Object document = documents.GetType().InvokeMember("Add", System.Reflection.BindingFlags.InvokeMethod, null, documents, null);
                //Autodesk.AutoCAD.Interop.AcadApplicationClass ICad = new AcadApplicationClass();
                //ICad.Visible = true;
                //ICad.WindowState =Autodesk.AutoCAD.Interop.
                //return;
            //} 
    }
        // 注册表文件是否存在
        static bool IsReg
        {
            get 
            {
                RegistryKey Key = Registry.LocalMachine.OpenSubKey("Software\\Autodesk\\AutoCAD\\R17.1\\ACAD-6002:804\\Applications\\SmartSoft", false);
                
                if (Key == null)
                    return false;

                Key.Close();
                return true;
            }
        }             
        }

转载于:https://www.cnblogs.com/chinaHunk/archive/2011/01/09/1931333.html

CAD VBA(Visual Basic for Applications)是AutoCAD软件中使用的一种编程技术,它允许用户自动化CAD操作,提高工作效率。在CAD中插入外部参照是一个常见的操作,它允许用户将一个或多个图形文件(如DWG或DWF文件)链接到当前工作图纸中,这样可以将其他图纸的内容作为参考。以下是使用VBA插入外部参照的基本步骤: 1. 启动AutoCAD,打开你想要插入外部参照的图纸。 2. 打开VBA编辑器(通常可以通过在AutoCAD命令行输入`VBAIDE`命令来打开)。 3. 在VBA编辑器中创建一个新的宏或打开一个已有的宏,编写VBA代码来实现插入外部参照的功能。 下面是一个简单的VBA示例代码,用于在AutoCAD中插入一个外部参照: ```vb Sub InsertXref() ' 定义变量 Dim acadApp As Object Dim acadDoc As Object Dim xrefName As String Dim insertPoint(0 To 2) As Double ' 设置外部参照文件名和插入点 xrefName = "C:\path\to\your\file.dwg" insertPoint(0) = 0 ' X坐标 insertPoint(1) = 0 ' Y坐标 insertPoint(2) = 0 ' Z坐标(对于2D图纸通常为0) ' 连接到AutoCAD应用程序 On Error Resume Next Set acadApp = GetObject(, "AutoCAD.Application") If acadApp Is Nothing Then MsgBox "无法连接到AutoCAD应用程序" Exit Sub End If On Error GoTo 0 ' 获取当前文档 Set acadDoc = acadApp.ActiveDocument ' 插入外部参照 acadDoc.InsertXref xrefName, insertPoint, False, False, False End Sub ``` 请注意,这段代码需要根据实际情况进行调整,包括文件路径、插入点等参数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值