青蛙
拿到了一种遍历数据库的方式,然后发现这个东西遍历数据库奇慢.
这是因为他用了句柄来作为遍历的方式,
而句柄是递增模式的,直到递增到 db.Handseed.Value ,但是这个值非常大,有long长度的14位那么大….而且是递增的….
所以千万不要用这种方法遍历数据库…..
/// <summary>/// 句柄遍历数据库/// http://www.theswamp.org/index.php?topic=39272.0/// https://through-the-interface.typepad.com/through_the_interface/2013/06/dgn-clean-up-tool-on-its-way.html/// </summary>[CommandMethod("FastIteration", CommandFlags.Modal)]public void FastIteration(){Document doc = Acap.DocumentManager.MdiActiveDocument;Database db = doc.Database;Editor ed = doc.Editor;DateTime start = DateTime.Now;long linshi = 0;long amount = 0;using (Transaction tr = db.TransactionManager.StartTransaction()){try{for (amount = db.BlockTableId.Handle.Value; amount < db.Handseed.Value; amount++){//ObjectId id = ObjectId.Null;//Below slow code is commented://try {// id = TargetDb.GetObjectId(false, new Handle(i), 0);//}//catch {// ++exceptCount;// continue;//}TimeSpan len = DateTime.Now - start;if (len.Seconds != linshi && len.Seconds % 1 == 0)//满足一秒输出一次,免得卡死{linshi = len.Seconds;ed.WriteMessage($"\n\r数量: {amount},已经过了{len.Days}天,{len.Hours}小时,{len.Minutes}分,{len.Seconds}秒");//刷新内容Acap.UpdateScreen();//高版本要加这句令命令栏立即执行System.Windows.Forms.Application.DoEvents();}}}catch (System.Exception e){TimeSpan len = DateTime.Now - start;ed.WriteMessage($"\n\r错误:{amount}+{e.Message}" + $"\n\r数量: {amount},已经过了{len.Days}天,{len.Hours}小时,{len.Minutes}分,{len.Seconds}秒");}}}
edata
而且我发现一个问题,这个句柄,如果你保存了,可能会写入很多的附加对象,句柄就会浪费很多..
比如打开文件,句柄是2c5,继续画直线,2c6…. 2c7…2c8 如果保存了.就从 313 开始..
中间因保存,重新打开后句柄浪费了75个左右…
ctrl+c应该是先复制一个对象到 剪贴板,然后粘贴.
所以要多生成几次.
co 就不会乱增..
