[讨论]dxf文件操作
operFilePath=“D:\\1.dxf”;doc=Autodesk..ApplicationServices.Application.DocumentManager.Open(operFilePath, false);
打开这个dxf文件后,进行一些绘图操作,然后如何保存成"D:\\1.dxf”;并且版本还是用1.dxf的原来的版本?
doc.CloseAndSave(operFilePath);会保存成1.dxf.dwg。并且版本不是1.dxf的原来的版本,而是当前cad的保存版本设置。
倒是想到一个办法,就是通过operDb.DxfOut(tempFilePath, 14, dwgSaveVer);或者operDb.SaveAs(tempFilePath, dwgSaveVer);
然后关闭当前打开的operFilePath文档,再删除operFilePath,然后将tempFilePath改名成operFilePath。
难道就没有别的办法了吗?
Document.CloseAndSave Method
Closes the document and saves it to fileName.
Document.CloseAndDiscard Method
Closes the document without saving it. 谢谢!
已经有办法了,保存文档的时候,在CAD的选项里面有个另存为的设置,Document.CloseAndSave Method是按照这个设置来保存的,并且自动加上dwg.或dxf后缀。
现在还有个问题,能否有程序去读取这个选项的另存为的下拉列表,在界面上的combox下拉框中列出同样的选项,在combox中选择了之后,由程序去设置CAD的这个另存为选项?也就是不需要人去手动到cad里进行设置。
另外,现在还有一个问题.我打开dwg文件,然后进行操作后,CAD的选项里面另存为的设置成dwg或dxf,都可以保存成功
打开dxf文件,然后进行操作后,CAD的选项里面另存为的设置成dwg,也可以保存成功
但是打开dxf文件,然后进行操作后,CAD的选项里面另存为的设置成dxf,保存出错!
但是如果dxf保存成另外一个不是已经打开的dxf文件,就可以保存!很奇怪,为什么打开的dxf,再保存自己就不可以了呢?
想了个办法,dxf先保存成临时文件,再修改临时文件的名称!
for (iDwg = 0; iDwg
lok.Dispose();
//savepath = System.IO.Path.GetDirectoryName(operFilePath) + System.IO.Path.GetFileNameWithoutExtension(operFilePath);
savepath = folderPath+System.IO.Path.GetFileNameWithoutExtension(operFilePath);
//doc.CloseAndSave(savepath);
}
FS.FileSystemObject fso=new FS.FileSystemObject();
try
{
doc.CloseAndSave(savepath);
}
catch (System.Exception eRR)
{
doc.CloseAndSave(temppath);
if (fso.FileExists(operFilePath))
{
fso.DeleteFile(operFilePath, true);
}
fso.MoveFile(temppath, operFilePath);
}
试下db.CloseInput()?
试过了,没用,无论把db.CloseInput(true)加在什么地方都没用,只要是打开dxf然后保存成dxf就不行。
已经解决了,这样打开dxf,保存成dxf,dwg,dwt,打开dwg,保存成dxf,dwg,dwt都可以了,不报错了,保存版本和AutoCAD的设置时一致的。
for (iDwg = 0; iDwg
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
//db.CloseInput(true);
DocumentLock lok = doc.LockDocument();
Utils.ZoomObjects(true);//范围缩放视图
lok.Dispose();
//db.Save();
labelExecuteCondition.Text = "正在范围缩放" + System.IO.Path.GetFileName(operFilePath) + "视图,请等待……";
labelExecuteCondition.Visible = true;
finish = (int)((Double)(iDwg + 1) / (Double)(dwgCount) * 100);
progressBar1.Value = finish;
progressBar1.Visible = true;
this.Update();
//savepath = System.IO.Path.GetDirectoryName(operFilePath) + System.IO.Path.GetFileNameWithoutExtension(operFilePath);
//savepath = folderPath+System.IO.Path.GetFileNameWithoutExtension(operFilePath);
//savepath = "D:\\杂记\\1";
savepath = operFilePath;
doc.CloseAndSave(savepath);
}
到这里,我的东西就全做完了
页:
[1]