Esempio n. 1
0
 /// <summary>
 /// 根据节点名称获取节点
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public ParamTree GetChildNodesByName(string name)
 {
     ParamTree paramTree = null;
      List<ParamTree> listpt = this.GetChildNodes();
     foreach (ParamTree pt in listpt)
     {
         if (pt.Name == name)
         {
             paramTree = pt;
             break;
         }
         else
         {
             paramTree = null;
         }
     }
     return paramTree;
 }
Esempio n. 2
0
        /// <summary>
        /// 向属性树的第三层插放数据
        /// </summary>
        /// <param name="parameterset"></param>
        private void InsertThrParam(Element elem, ParamTree Tree, ParameterSet parameter)
        {
            foreach (Parameter param in parameter)
            {
                if (param == null)
                {
                    continue;                //如果参数没有,继续下一个
                }
                //定位第二层
                ParamTree tmptree = Tree.GetChildNodesByName(LabelUtils.GetLabelFor(param.Definition.ParameterGroup));

                string sb = "";

                switch (param.StorageType)
                {
                case Autodesk.Revit.DB.StorageType.Double:
                    sb += param.AsValueString();
                    break;

                case Autodesk.Revit.DB.StorageType.Integer:
                    sb += param.AsInteger().ToString();
                    break;

                case Autodesk.Revit.DB.StorageType.ElementId:
                    sb += (elem != null ? param.AsValueString() : "Not set");
                    break;

                case Autodesk.Revit.DB.StorageType.String:
                    sb += param.AsString();
                    break;

                case Autodesk.Revit.DB.StorageType.None:
                    sb += param.AsValueString();
                    break;

                default:
                    break;
                }
                //循环添加第三层数据
                tmptree.AddChildNodes(new ParamTree("3", param.Definition.Name, sb));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 制作单个构件的属性树
        /// </summary>
        /// <param name="parametergroup"></param>
        private ParamTree MakeParamTree(Element elem, List <string> parametergroup)
        {
            //第一层根节点的名字构件的Id
            ParamTree Tree = new ParamTree("1", elem.UniqueId.ToString());

            //第二层
            foreach (string str in parametergroup)
            {
                Tree.AddChildNodes(new ParamTree("2", str));
            }
            //得到每个属性的属性类别,然后查找到第二层的节点
            ParameterSet parameters = elem.Parameters;//获取单个元素的全部属性;

            //获取类型属性:
            ParameterSet parameters2 = GetParamSet(elem);


            InsertThrParam(elem, Tree, parameters);
            InsertThrParam(elem, Tree, parameters2);

            return(Tree);
        }
Esempio n. 4
0
        /// <summary>
        /// 创建一个对象
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private string CreateElement(ParamTree item)
        {
            StringBuilder strBuild = new StringBuilder("");

            if (item.GetChildNodesCount() != 0)
            {
                strBuild.AppendLine("\n\t{");
                strBuild.AppendLine("\t\t\"Name\":" + "\"" + item.Name + "\",");
                //strBuild.AppendLine("\t\t\"Value\":" + "\"" + item.Value + "\",");
                strBuild.AppendLine("\t\t\"children\":[");
                bool isFirst = true;

                foreach (ParamTree element in item.GetChildNodes())
                {
                    if (isFirst)
                    {
                        strBuild.Append(this.CreateElement(element));
                        isFirst = false;
                    }
                    else
                    {
                        strBuild.AppendLine("," + this.CreateElement(element));
                    }
                }
                strBuild.AppendLine("]}");
            }
            else
            {
                strBuild.AppendLine("\n\t{");
                strBuild.AppendLine("\t\t\"Name\":" + "\"" + item.Name + "\",");
                strBuild.AppendLine("\t\t\"Value\":" + "\"" + item.Value + "\"");
                strBuild.AppendLine("\n\t}");
                return(strBuild.ToString());
            }

            return(strBuild.ToString());
        }
Esempio n. 5
0
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message,
                                                ElementSet elements)
        {
            // set out default result to failure.
            Autodesk.Revit.UI.Result        retRes = Autodesk.Revit.UI.Result.Succeeded;
            Autodesk.Revit.UI.UIApplication app    = commandData.Application;

            // get the elements selected
            // The current selection can be retrieved from the active
            // document via the selection object
            ElementSet seletion = new ElementSet();

            foreach (ElementId elementId in app.ActiveUIDocument.Selection.GetElementIds())
            {
                seletion.Insert(app.ActiveUIDocument.Document.GetElement(elementId));
            }

            List <string>    parametergroup = new List <string>();
            List <ParamTree> All_Elem       = new List <ParamTree>();
            int n = seletion.Size;

            //迭代器
            ElementSetIterator it = seletion.ForwardIterator();

            //遍历所有选中的元素;
            for (int i = 0; i < n; i++)
            {
                //每次迭代下一个元素;
                it.MoveNext();
                Element element = it.Current as Element;

                ParameterSet parameters  = element.Parameters;//获取单个元素的全部属性;
                ParameterSet parameters2 = GetParamSet(element);



                foreach (Parameter param in parameters)
                {
                    if (param == null)
                    {
                        continue;                //如果参数没有,继续下一个
                    }
                    parametergroup = GetParameterGroup(parametergroup, param);
                }

                foreach (Parameter param in parameters2)
                {
                    if (param == null)
                    {
                        continue;                //如果参数没有,继续下一个
                    }
                    parametergroup = GetParameterGroup(parametergroup, param);
                }
                ParamTree tree = MakeParamTree(element, parametergroup);
                All_Elem.Add(tree);
            }


            CreateJsonFile(CreateJson(All_Elem));
            retRes = Autodesk.Revit.UI.Result.Succeeded;
            return(retRes);
        }
Esempio n. 6
0
 /// <summary>
 /// 添加子节点
 /// </summary>
 /// <param name="child"></param>
 public void AddChildNodes(ParamTree child)
 {
     this.lstChildren.Add(child);
 }