【Revit】Revit⼆次开发错误及警告屏蔽弹窗⽅法public class BeeFaceFailureHandler : IFailuresPreprocessor
{
public string ErrorMessage { set; get; }
public string ErrorSeverity { set; get; }
public BeeFaceFailureHandler()
{
ErrorMessage = "";
ErrorSeverity = "";
}
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
{
IList<FailureMessageAccessor> failureMessages = failuresAccessor.GetFailureMessages();
foreach (FailureMessageAccessor failureMessageAccessor in failureMessages)
{
FailureDefinitionId id = failureMessageAccessor.GetFailureDefinitionId();
try
{
ErrorMessage = failureMessageAccessor.GetDescriptionText();
}
catch
自动弹窗代码{
ErrorMessage = "Unknown Error";
}
try
{
FailureSeverity failureSeverity = failureMessageAccessor.GetSeverity();
ErrorSeverity = failureSeverity.ToString();
if (failureSeverity == FailureSeverity.Warning)
{
//if (failureMessageAccessor.GetDescriptionText() == "同⼀位置处具有相同实例。这将导致在明细表中重复计算。.")
//{
//    List<ElementId> c = failureMessageAccessor.GetFailingElementIds().ToList();
//    if (c.Count > 1)
//    {
//        failuresAccessor.DeleteElements(new List<ElementId>() { c[1] });
//    }
//}
//else
//{
// 如果是警告,则禁⽌消息框
failureMessageAccessor.GetDefaultResolutionCaption();
//}
failuresAccessor.DeleteWarning(failureMessageAccessor);
}
else
{
// 如果是错误:则取消导致错误的操作,但是仍然继续整个事务
if (ErrorMessage.Contains("线太短"))
{
failureMessageAccessor.SetCurrentResolutionType(FailureResolutionType.DeleteElements);
failuresAccessor.ResolveFailure(failureMessageAccessor);
return FailureProcessingResult.ProceedWithCommit;
}
//else
//{
/
/    failuresAccessor.DeleteWarning(failureMessageAccessor);
//    return FailureProcessingResult.ProceedWithCommit;
//}
}
}
catch (Exception ex)
{
}
}
return FailureProcessingResult.Continue;
}
[Description("这个⽅法⽤在事务开始前,在FailureHandler初始化后调⽤")]
///<summary>
///这个⽅法⽤在事务开始前,在FailureHandler初始化后调⽤
///</summary>
public static void SetFailedHandlerBeforeTransaction(IFailuresPreprocessor failureHandler, Transaction transaction)
{
FailureHandlingOptions failureHandlingOptions = transaction.GetFailureHandlingOptions();
failureHandlingOptions.SetFailuresPreprocessor(failureHandler);
// 这句话是关键
//failureHandlingOptions.SetClearAfterRollback(true);
transaction.SetFailureHandlingOptions(failureHandlingOptions);
}
}
调⽤⽅法:
Transaction tran = new Transaction(doc, "测试");
var failure = new BeeFaceFailureHandler();
BeeFaceFailureHandler.SetFailedHandlerBeforeTransaction(failure, tran);
tran.Start();
//-------
tran.Commit();
下⾯讲⼀下之前碰到的创建楼板的⼀个错误:边界边缘线彼此相交.边界等⾼线不可扭曲解决⽅案:
1. 板的”结构“属性不要勾选,或者
2. 板的”启⽤分析模型“不要勾选
对应的,我们可以再创建floor之后,马上调⽤下⾯的任何⼀段代码:
_Parameter(BuiltInParameter.STRUCTURAL_ANALYTICAL_MODEL).Set(0);
_Parameter(BuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL).Set(0);
如果不需要分析模型,请使⽤⽅法2,如果既不需要分析模型⼜不需要钢筋,请使⽤⽅法1.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。