20033535 发表于 2010-9-27 17:12:00

[求助]如何批量处理一个目录下的所有DWG文件

如题,如下代码复制代码打开test文件夹下的DWG文件后,addTitle(doc)也没有报错,但是没有预期后的执行效果;
如下处理单个文件:   

      public void bxcl()
      {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            addTitle(doc);
      }
可以正常执行。
加上参数CommandFlags.Session以后,程序可以正常运行,感谢lzh741206的指点
但是我觉得即使不加CommandMethod 的参数CommandFlags.Session程序也应该能够正常运行啊。
我感觉即使在一个session里面,打开操作其他Document并保存也是可行的,但是根据我代码的实际运行情况来看不可行。
我的代码哪里有问题?
对于cad的session正确理解是什么?

20033535 发表于 2010-9-27 17:25:00

谁能给个打开某一目录下所有的dwg文件并处理的例子啊?

20033535 发表于 2010-9-27 17:52:00

是不是要用到长事务?

雪山飞狐_lzh 发表于 2010-9-27 17:54:00

20033535 发表于 2010-9-27 20:11:00


一言中的啊
问题解决,看来我的要去了解示例方法和静态方法的知识了
我还是想知道我那代码不能运行的详细原因。

雪山飞狐_lzh 发表于 2010-9-27 20:45:00


ActionMacro = 0x8000000 This bit commands that are defined as a result of recording a series of actions with the ActionRecorder.
Defun = 0x800 This flag can only be set by the Visual LISP engine. Command can be invoked as a LISP function and can therefore use acedGetArgs() to receive arguments from LISP and can use the acedRetXxx() functions to return values to LISP.
DocExclusiveLock = 0x100000 Document will be exclusively locked when command is invoked. If this bit is not set, then the document will be share locked when the command is invoked.
DocReadLock = 0x80000 Document will be read locked when command is invoked. If this bit is not set, then the document will be write locked when the command is invoked.
Interruptible = 0x400000 The command may be interrupted when prompting for user input while it is calling any of the acedGetxxx methods.
Modal = 0 Command cannot be invoked while another command is active.
NoActionRecording = 0x4000000 This flag causes the ActionRecorder to ignore the associated command
NoBlockEditor = 0x2000000 The command is blocked during a bedit session.
NoHistory = 0x800000 The command will not be added to AutoCAD’s repeat-last-command functionality.
NoPaperSpace = 0x40 Command cannot be invoked when in paperspace.
NoTileMode = 0x20 Command cannot be invoked when TILEMODE == 1.
NoUndoMarker = 0x1000000 The command and its undo markers will not be added to the undo file. This is intended for commands that don't modify the database, and therefore should not show up in the undo file.
Redraw = 4 When the pickfirst set or grip set are retrieved, they are not cleared within AutoCAD.
Command can retrieve the pickfirst set and the grip set by using the ads_ssgetfirst function.
Command can retrieve the pickfirst set via ads_ssget("I.").
Command can set both the pickfirst and grip sets using the ads_sssetfirst function. Objects in these sets are redrawn with the proper grip handles and highlighting upon completion of the command.
Session = 0x200000 The command will be run in the application execution context rather than the current document context, with the different capabilities and limitations that entails. It should be used sparingly.
Transparent = 1 Command can be invoked while another command is active.
ads_sssetfirst() cannot be used when this flag is set
Undefined = 0x200 Command can only be invoked via the cmdGroupName.cmdGlobalName syntax.
UsePickSet = 2 When the pickfirst set is retrieved, it is cleared within AutoCAD.
Command is able to retrieve the pickfirst set via the functions ads_ssgetfirst() or ads_ssget("I.").
Command can set the pickfirst set via ads_sssetfirst(), but it only stays set until the command ends.
Command cannot retrieve nor set grips.

20033535 发表于 2010-9-28 19:24:00

对每一个Document执行下面的操作
DocumentLock doclock = doc.LockDocument();
addTitle(doc);
doclock.Dispose();
没有预期的效果。(执行过程没有报错误,但是执行不能反映到该doc中去)
但是对于当前打开的文档
Document doc = Application.DocumentManager.MdiActiveDocument;
addTitle(doc);
又能够正常运行。
页: [1]
查看完整版本: [求助]如何批量处理一个目录下的所有DWG文件