eWrongDatabase on Database.Wblock 自 AutoCAD 2017 起
你好,我有一个问题。从今天开始,我测试我的代码以将autocadversion从2014年更改为2017年。
在2014年工作正常,但在2017年抛出eWrongDatase错误。我的失败是什么?
2014年的代码工作:
// objectIds selected by typevalue selection on editor
selectedIds = new ObjectIdCollection(acPromptSelectionResult.Value.GetObjectIds());
if (selectedIds != null)
{
if (selectedIds.Count > 0)
{
String newFilename = "";
if (item.UseCurrentDwgName)
{
newFilename = System.IO.Path.GetFileName(myTransaction.AcDocument.Name);
newFilename = newFilename.Remove(newFilename.Length - 4);
if (!ClassStringTools.IsNullOrWhiteSpace(item.Prefix))
newFilename = item.Prefix + newFilename;
if (!ClassStringTools.IsNullOrWhiteSpace(item.Postfix))
newFilename += item.Postfix;
newFilename += ".dwg";
}
else
{
newFilename = item.ManualSeparationName;
if (!newFilename.ToLower().EndsWith(".dwg"))
newFilename += ".dwg";
}
if (System.IO.Directory.Exists(item.Path))
{
newFilename = ClassFileTools.addBackslashIfMissing(item.Path) + newFilename;
Database oldACDatabase = HostApplicationServices.WorkingDatabase;
using (Document newDoc = DocumentCollectionExtension.Add(Application.DocumentManager, AppSettingsSeparation.getSettings().NewDWGTemplate))
//Application.DocumentManager.Add(AppSettingsSeparation.getSettings().NewDWGTemplate))
{
Boolean canWrite = true;
using (DocumentLock newDocLoc = newDoc.LockDocument())
{
using (Database newDb = newDoc.Database)
{
try
{
if (System.IO.File.Exists(newFilename))
{
if (!ClassFileTools.DeleteToRecycleBin(newFilename))
canWrite = false;
}
if (canWrite)
{
// -------- now chrashed -----
myTransaction.AcDatabase.Wblock(newDb, selectedIds, Point3d.Origin, DuplicateRecordCloning.Ignore);
// <<< this crashed.
}
}
catch (System.Exception ex)
{
clEditor.LogException(ex);
Log.LogException(ex);
}
}
}
if (canWrite)
{
try
{
clTransaction newTransaction = clSingletonTransaktionsManager.Instance.getTransaction(newDoc, TRANSACTIONNAME); // is my transactionmanager
clDatabase.purgeGeoPlaceMarker(newTransaction);
if (iAmNotAutoCAD)
clKillProxy.cleanCivilObjects(newTransaction);
clSingletonTransaktionsManager.Instance.CommitTransaction(newTransaction);
clTransaction.lockDatabase(newDoc);
newDoc.Database.SaveAs(newFilename, DwgVersion.Newest);
newDoc.CloseAndDiscard();
result = true;
}
catch (System.Exception ex)
{
Log.LogException(ex);
clEditor.LogException(ex);
result = false;
}
}
else
{
newDoc.CloseAndDiscard();
result = false;
}
}
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = sourceDocument;
}
}
}
}
有任何机构在2017年工作的例子吗?
问候马里奥
**** Hidden Message *****
请参阅发生崩溃的代码行中的红色粗体部分。您没有显示“myTransaction”对象是什么(我只能猜测它是一个可能继承或包含事务类的自定义类),以及它的属性 AcDatabase 是什么(以及如何获取它)。根据代码逻辑,AcDatabase 应该是当前图形(在代码打开要阻止的数据的新图形之前)。
您没有显示的另一个关键内容是执行代码的上下文:应用程序上下文或文档上下文。同样,根据代码的最后一行判断,您将MdiDocument设置为“sourceDocument”,我猜您在应用程序上下文中运行代码(您设置了CommandFlags.Session标志)。
由于 Acad2014 版本(即 2015 及更高版本)之后的 Acad2014 的主要变化是删除了 Fiber,如果在执行命令/自定义应用程序期间活动文档发生更改,这将导致问题,我怀疑这是崩溃的可能原因,因为您声称它适用于 Acad2014。
从我的代码逻辑中可以看出,我认为您的代码不需要在应用程序上下文中运行,因为您打开了一个新文档以将数据复制到其中,因此它不必是 MdiActiveDocument。是的,如果没有 CommandFlags.Sessioon 标志,在文档上下文中运行的代码仍然可以在 AutoCAD 中打开文档,新打开的文档根本不会成为 MdiActiveDocument。虽然如果你有 CommandFlas.Session,那么喵喳地打开的文档会自动变成 NdiActiveDocument。
在没有看到更多相关代码的情况下,我建议您尝试以下两种方法之一:
1.删除“CommandFlags.Session”标志(如果您使用了它
),或者2.更改此行
myTransaction.AcDatabase.Wblock(....);
到
sourceDatabase.Wblock(...);//假设变量“sourceDatabase”被正确地指向从中选择实体的有效数据库。 你好,袁,
谢谢你的回答。解决方案是“删除会话标志”。
@显示到“我的事务”...是我自己的transactionmanager。在过去的11年里,我从2007年开始在autocad上编程。在这段时间里,发展了许多图书馆....
如果新autocad版本中的这些库有问题,从post中混合出我自己的库代码是很棘手的。非常感谢和问候马里奥
页:
[1]