当前位置: 首页>>代码示例>>C#>>正文


C# ElementSet.Clear方法代码示例

本文整理汇总了C#中ElementSet.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# ElementSet.Clear方法的具体用法?C# ElementSet.Clear怎么用?C# ElementSet.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ElementSet的用法示例。


在下文中一共展示了ElementSet.Clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            #region 1.2.a. Examine command data input argument:
              //
              // access application, document, and current view:
              //
              UIApplication uiapp = commandData.Application;
              Application app = uiapp.Application;
              UIDocument uidoc = uiapp.ActiveUIDocument;
              Document doc = uidoc.Document;
              View view = commandData.View;
              LanguageType lt = app.Language;
              ProductType pt = app.Product;
              string s = "Application = " + app.VersionName
            + "\r\nLanguage = " + lt.ToString()
            + "\r\nProduct = " + pt.ToString()
            + "\r\nVersion = " + app.VersionNumber
            + "\r\nDocument path = " + doc.PathName // empty if not yet saved
            + "\r\nDocument title = " + doc.Title
            + "\r\nView name = " + view.Name;
              LabUtils.InfoMsg( s );
              #endregion // 1.2.a. Examine command data input argument

              #region 1.2.b. List selection set content:
              //
              // list the current selection set:
              //
              Selection sel = uidoc.Selection;
              List<string> a = new List<string>();
              foreach( ElementId id in sel.GetElementIds() )
              {
            Element e = doc.GetElement( id );

            string name = ( null == e.Category )
              ? e.GetType().Name
              : e.Category.Name;

            a.Add( name + " Id="
              + e.Id.IntegerValue.ToString() );
              }
              LabUtils.InfoMsg(
            "There are {0} element{1} in the selection set{2}",
            a );

              #endregion // 1.2.b. List selection set content

              #region 1.2.c. Populate return arguments:

              // We pretend that something is wrong with the
              // first element in the selection. Pass an error
              // message back to the user and indicate the
              // error result:

              ICollection<ElementId> ids = sel.GetElementIds();

              if( 0 < ids.Count )
              {
            //ElementSetIterator iter = sel.Elements.ForwardIterator();
            //iter.MoveNext();
            //Element errElem = iter.Current as Element;

            Element errElem = doc.GetElement( ids.First()  );
            elements.Clear();
            elements.Insert( errElem );
            message = "We pretend something is wrong with this "
              + " element and pass back this message to user";

            return Result.Failed;
              }
              else
              {
            // We return failed here as well.
            // As long as the message string and element set are empty,
            // it makes no difference to the user.
            // If they are not empty, the message is displayed to the
            // user and/or the elements in the set are highlighted.
            // If an automatic transaction is open, it is aborted,
            // avoiding marking the database as dirty.

            return Result.Failed;
              }
              #endregion // 1.2.c. Populate return arguments
        }
开发者ID:jeremytammik,项目名称:AdnRevitApiLabsXtra,代码行数:86,代码来源:Labs1.cs


注:本文中的ElementSet.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。