C#如何在新开线程中操作CAD?
using System;using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Colors;
namespace ClassLibrary2
{
public class Class1
{
public void tt()
{
Thread th=new Thread(new ThreadStart(Edit2)):
th.Start();
}
public void Edit2()//修改设备内容
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
try
{
ed.WriteMessage(DateTime.Now.ToString());
trans.Commit();
docLock.Dispose();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
Debug.WriteLine(ex.Message);
}
finally
{
trans.Dispose();
}
}
}
}
AutoCAD2006+vs2005
会报错。
在网上找了一下,有一个解决方法,却不存在了。请各位老师指点一下。
AutoCAD本身操作不支持多线程,只能将一些计算或是读取数据,放到多线程里 因为我想做个定时刷新CAD属性块的内容,现在只能输入一次命令她刷新一次。有没有办法做呢? CAD本身有定时保存文件的功能,是不是能找到这样的方法呢?
页:
[1]