明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3521|回复: 6

[讨论]dxf文件操作

[复制链接]
发表于 2009-10-11 00:14 | 显示全部楼层 |阅读模式

operFilePath=“D:\\1.dxf”;

doc=Autodesk.AutoCAD.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。

难道就没有别的办法了吗?

发表于 2009-10-11 10:18 | 显示全部楼层
Document.CloseAndSave Method
 Closes the document and saves it to fileName.
Document.CloseAndDiscard Method
 Closes the document without saving it.
 楼主| 发表于 2009-10-11 17:41 | 显示全部楼层

谢谢!

已经有办法了,保存文档的时候,在CAD的选项里面有个另存为的设置,Document.CloseAndSave Method是按照这个设置来保存的,并且自动加上dwg.或dxf后缀。

现在还有个问题,能否有程序去读取这个选项的另存为的下拉列表,在界面上的combox下拉框中列出同样的选项,在combox中选择了之后,由程序去设置CAD的这个另存为选项?也就是不需要人去手动到cad里进行设置。

 楼主| 发表于 2009-10-11 19:23 | 显示全部楼层
本帖最后由 作者 于 2009-10-11 20:17:54 编辑

另外,现在还有一个问题.我打开dwg文件,然后进行操作后,CAD的选项里面另存为的设置成dwg或dxf,都可以保存成功

打开dxf文件,然后进行操作后,CAD的选项里面另存为的设置成dwg,也可以保存成功

但是打开dxf文件,然后进行操作后,CAD的选项里面另存为的设置成dxf,保存出错!

但是如果dxf保存成另外一个不是已经打开的dxf文件,就可以保存!很奇怪,为什么打开的dxf,再保存自己就不可以了呢?

想了个办法,dxf先保存成临时文件,再修改临时文件的名称!

for (iDwg = 0; iDwg < dwgCount; iDwg++)
            {
                operFilePath = dwgFilesRoute[iDwg].ToString();//获得操作图形路径               
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(operFilePath, false);
                Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;               
                //DocumentLock lok = doc.LockDocument();
                Utils.ZoomObjects(true);//范围缩放,引入using Autodesk.AutoCAD.Internal;acmgdinternal

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);
                }

发表于 2009-10-11 20:24 | 显示全部楼层

试下db.CloseInput()?

 楼主| 发表于 2009-10-11 21:32 | 显示全部楼层
试过了,没用,无论把db.CloseInput(true)加在什么地方都没用,只要是打开dxf然后保存成dxf就不行。
 楼主| 发表于 2009-10-11 21:54 | 显示全部楼层
本帖最后由 作者 于 2009-10-11 22:19:39 编辑

已经解决了,这样打开dxf,保存成dxf,dwg,dwt,打开dwg,保存成dxf,dwg,dwt都可以了,不报错了,保存版本和AutoCAD的设置时一致的。

for (iDwg = 0; iDwg < dwgCount; iDwg++)
            {
                operFilePath = dwgFilesRoute[iDwg].ToString();//获得操作图形路径
                if (fileType=="DWG")
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(operFilePath, false);
                }
                else//DXF
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(operFilePath, true);
                }
               

                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);

}

到这里,我的东西就全做完了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-18 14:56 , Processed in 0.300654 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表