- 积分
- 306
- 明经币
- 个
- 注册时间
- 2012-5-29
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 James.W.H.Li 于 2012-7-27 12:11 编辑
最近在做处理历史图纸的工作,过程如下:
1、打开原图纸,剔除不需处理的信息,另存为*-1.dwg;
2、打开原图纸,剔除需要处理的信息,另存为*-2.dwg;
3、打开*-1.dwg,执行explode命令,另存为*-3.dwg;
4、打开*-3.dwg,提取处理的信息,另存为*.xls;
5、打开*-2.dwg,添加从*.xls中读取的信息,另存为*-new.dwg。
编写的程序前2步执行良好,但是第3步发生问题,炸碎的图形保存后,仍是炸碎前的样子。不知道问题出在哪里,请大家伙提供宝贵意见和指导,谢谢!
第3步的程序如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.EditorInput;
[assembly: CommandClass(typeof(CNPTCAD.testGetInfoFromDwg))]
namespace CNPTCAD
{
class testGetInfoFromDwg
{
[CommandMethod("testGetInfoFromDwg",CommandFlags.Session)]
//[CommandMethod("testGetInfoFromDwg")]
public static void DotestGetInfoFromDwg()
{
OpenFileDialog openFileDialog3 = new OpenFileDialog();
openFileDialog3.Multiselect = false;
openFileDialog3.Filter = "AutoCAD files (*.dwg)|*.dwg";
openFileDialog3.FilterIndex = 0;
openFileDialog3.RestoreDirectory = true;
openFileDialog3.Title = "test";
if (openFileDialog3.ShowDialog() == DialogResult.OK)
{
String filename = openFileDialog3.FileName;
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(filename, false);
DocumentLock doclock = doc.LockDocument();
int flag = 0;
if(flag == 0){
doc.SendStringToExecute("_ai_selall\n", false, false, true);
flag = 1;
//Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(flag.ToString());
}
if(flag == 1){
doc.SendStringToExecute("explode\n", false, false, true);
flag = 2;
//Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(flag.ToString());
}
if (flag == 2)
{
doc.Database.SaveAs(filename.Substring(0, filename.Length - 10) + "_3.dwg", DwgVersion.Newest);
flag = 3;
//Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(flag.ToString());
}
doclock.Dispose();
//下面这句屏蔽的话,可以看到原图形确实被炸碎了
//doc.CloseAndDiscard();
}
}
}
}
|
|