コード例 #1
0
        /// <summary> 执行外部命令,并且在执行命令之前,自动将 事务打开</summary>
        /// <param name="cmd">要执行的命令</param>
        public static void ExecuteCommand(ExternalCommand cmd)
        {
            using (DocumentModifier docMdf = new DocumentModifier(openDebugerText: true))
            {
                try
                {
                    // 刷新所有的全局选项到内存中
                    DbXdata.LoadAllOptionsFromDbToMemory(docMdf);
                    //
                    var impliedSelection = docMdf.acEditor.SelectImplied().Value;
                    var res = cmd(docMdf, impliedSelection);
                    //
                    switch (res)
                    {
                    case ExternalCmdResult.Commit:
                        docMdf.acTransaction.Commit();
                        break;

                    case ExternalCmdResult.Cancel:
                        docMdf.acTransaction.Abort();
                        break;

                    default:
                        docMdf.acTransaction.Abort();
                        break;
                    }
                }
                catch (System.Exception ex)
                {
                    docMdf.acTransaction.Abort(); // Abort the transaction and rollback to the previous state
                    MessageBox.Show(ex.AppendMessage(), @"出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #2
0
        internal static ExternalCommandResult DebugInAddinManager(ExternalCommand cmd,
                                                                  SelectionSet impliedSelection, ref string errorMessage, ref IList <ObjectId> elementSet)
        {
            var dat = new DllActivator_RESD();

            dat.ActivateReferences();

            using (var docMdf = new DocumentModifier(true))
            {
                try
                {
                    // 先换个行,显示效果更清爽
                    docMdf.WriteNow("\n");
                    // 刷新所有的全局选项到内存中
                    DbXdata.LoadAllOptionsFromDbToMemory(docMdf);
                    // 运行具体的命令
                    var canCommit = cmd(docMdf, impliedSelection);
                    //
                    switch (canCommit)
                    {
                    case ExternalCmdResult.Commit:
                        docMdf.acTransaction.Commit();
                        return(ExternalCommandResult.Succeeded);

                        break;

                    case ExternalCmdResult.Cancel:
                        docMdf.acTransaction.Abort();
                        return(ExternalCommandResult.Cancelled);

                        break;

                    default:
                        docMdf.acTransaction.Abort();
                        return(ExternalCommandResult.Cancelled);

                        break;
                    }
                }
                catch (Exception ex)
                {
                    docMdf.acTransaction.Abort(); // Abort the transaction and rollback to the previous state
                    errorMessage = ex.AppendMessage();
                    return(ExternalCommandResult.Failed);
                }
            }
        }