从 Ribbon Revit 2015 放置设备:交易已经开始
Place Equipment From Ribbon Revit 2015: Transaction already started
堆栈,
我正在编写一个适用于 Autodesk Revit (2015) 的外部应用程序。我在功能区上创建了一个按钮,允许用户放置一个特殊设备,稍后我将使用它来读取并传递到另一个进程。我使用“TheBuildingCoder”'Family API' 示例来执行此操作。功能区上的按钮在 ProgramData 目录的 .addin 文件中设置了一个外部命令...
<AddIn Type="Command">
<Assembly>C:\GSN Programs\MyDll.dll</Assembly>
<AddInId>{97715E4F-EA48-4690-8C62-B5D4836FF452}</AddInId>
<FullClassName>RcarsPlugIn.PlaceEquipment</FullClassName>
<VendorId>MyCompany, LLC</VendorId>
<Text>Place Equipment</Text>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<Discipline>Any</Discipline>
<LanguageType>Unknown</LanguageType>
</AddIn>
按下按钮时,我将命令数据放入一个全局变量中以在整个程序中使用...
If IsNothing(gv_oGo) Then
gv_oGo = New clsGeneralOperations
gv_oGo.CachedCommandData = exCommandData
gv_oGo.UiApp = exCommandData.Application.ActiveUIDocument.Application
End If
有了缓存的 CommandData,我移动到通过用户选择来放置设备...
uiDoc = gv_oGo.UiApp.ActiveUIDocument
oSym = oRF.FindElement(doc, GetType(FamilySymbol), "MyEQUIP")
uiDoc.PromptForFamilyInstancePlacement(oSym)
Public Function FindElement(doc As Document, targetType As Type, sTargetName As String) As Element
Return New FilteredElementCollector(doc).OfClass(targetType).FirstOrDefault(Function(e) e.Name.Equals(sTargetName))
End Function
这就是问题所在。我收到一条从 Revit 发回的错误消息,指出 "Placement is not permitted in an already modifiable document. The active transaction must be closed first." 问题是,我还没有开始其他事务。功能区上的按钮是 Revit 启动时第一个触摸的按钮。
有没有办法遍历打开的交易并找到打开的交易?文档是否处于某种我不理解的状态?我不确定在这里转向哪个方向...任何帮助将不胜感激。
谢谢,
奔跑...
好的,一个澄清问题 - 异常发生在
uiDoc.PromptForFamilyInstancePlacement(oSym)
行正确吗?如果是这样,请尝试使用子事务来完成您的命令:
Document doc = uiDoc.Document;
using (SubTransaction subtr_fam = new SubTransaction(doc))
{
try
{
uiDoc.PromptForFamilyInstancePlacement(oSym);
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace.ToString());
}
}
堆栈,
我正在编写一个适用于 Autodesk Revit (2015) 的外部应用程序。我在功能区上创建了一个按钮,允许用户放置一个特殊设备,稍后我将使用它来读取并传递到另一个进程。我使用“TheBuildingCoder”'Family API' 示例来执行此操作。功能区上的按钮在 ProgramData 目录的 .addin 文件中设置了一个外部命令...
<AddIn Type="Command">
<Assembly>C:\GSN Programs\MyDll.dll</Assembly>
<AddInId>{97715E4F-EA48-4690-8C62-B5D4836FF452}</AddInId>
<FullClassName>RcarsPlugIn.PlaceEquipment</FullClassName>
<VendorId>MyCompany, LLC</VendorId>
<Text>Place Equipment</Text>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<Discipline>Any</Discipline>
<LanguageType>Unknown</LanguageType>
</AddIn>
按下按钮时,我将命令数据放入一个全局变量中以在整个程序中使用...
If IsNothing(gv_oGo) Then
gv_oGo = New clsGeneralOperations
gv_oGo.CachedCommandData = exCommandData
gv_oGo.UiApp = exCommandData.Application.ActiveUIDocument.Application
End If
有了缓存的 CommandData,我移动到通过用户选择来放置设备...
uiDoc = gv_oGo.UiApp.ActiveUIDocument
oSym = oRF.FindElement(doc, GetType(FamilySymbol), "MyEQUIP")
uiDoc.PromptForFamilyInstancePlacement(oSym)
Public Function FindElement(doc As Document, targetType As Type, sTargetName As String) As Element
Return New FilteredElementCollector(doc).OfClass(targetType).FirstOrDefault(Function(e) e.Name.Equals(sTargetName))
End Function
这就是问题所在。我收到一条从 Revit 发回的错误消息,指出 "Placement is not permitted in an already modifiable document. The active transaction must be closed first." 问题是,我还没有开始其他事务。功能区上的按钮是 Revit 启动时第一个触摸的按钮。
有没有办法遍历打开的交易并找到打开的交易?文档是否处于某种我不理解的状态?我不确定在这里转向哪个方向...任何帮助将不胜感激。
谢谢, 奔跑...
好的,一个澄清问题 - 异常发生在
uiDoc.PromptForFamilyInstancePlacement(oSym)
行正确吗?如果是这样,请尝试使用子事务来完成您的命令:
Document doc = uiDoc.Document;
using (SubTransaction subtr_fam = new SubTransaction(doc))
{
try
{
uiDoc.PromptForFamilyInstancePlacement(oSym);
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace.ToString());
}
}