MR_HJ
2016-07-22 04:31
采纳率: 50%
浏览 3.2k
已采纳

大神们求帮助,在revit二次开发中,如何获取三维视图数据

新手求教,在线等,急!!
在revit二次开发,如何获取三维视图数据

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • MR_HJ 2016-07-27 08:15
    已采纳

    //遍历元素的普通参数
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    [Journaling(JournalingMode.NoCommandData)]
    public class OneParameter : IExternalCommand
    {
    public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
    {
    UIApplication app = commandData.Application;
    Document doc = app.ActiveUIDocument.Document;
    FilteredElementCollector collector = new FilteredElementCollector(doc);

            //遍历选中元素的普通参数
            Selection sel = app.ActiveUIDocument.Selection;
            ElementSet es = sel.Elements;
            Element elemPick = null;
            if (es.Size > 0)
            {
                int count_1 = 0;
                int count_2 = 0;
                StringBuilder sb = new StringBuilder();
                foreach (Element elem in es)
                {
                    elemPick = elem;
                    foreach (Parameter p in elemPick.Parameters)
                    {
                        sb.Append(p.Definition.ParameterGroup + "," + p.Definition.Name + "," + p.AsValueString() + "\n");
                        count_2 += 1;
                    }
                    count_1 += 1;
                }
                TaskDialog.Show("数据", "模型数量:" + count_1 + ",总数:" + count_2 + "\n" + sb.ToString());
    
            }
            return Result.Succeeded;
        }
    }
    #endregion
    
    打赏 评论
  • MR_HJ 2016-07-27 08:13

    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    [Journaling(JournalingMode.NoCommandData)]
    public class reivtnums : IExternalCommand
    {
    public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
    {
    UIApplication app = commandData.Application;
    Document doc = app.ActiveUIDocument.Document;

            ElementClassFilter instanceFitler = new ElementClassFilter(typeof(FamilyInstance));
            ElementClassFilter hostFilter = new ElementClassFilter(typeof(HostObject));
    
            LogicalOrFilter andFilter = new LogicalOrFilter(instanceFitler, hostFilter);
    
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            collector.WherePasses(andFilter);
    
            #region 遍历选中实例对象
            //遍历选中实例对象
            //Selection sel = app.ActiveUIDocument.Selection;
            //ElementSet es = sel.Elements;
            //if (es.Size > 0)
            //{
            //    //StringBuilder sb = new StringBuilder();
            //    //foreach (Element el in es)
            //    //{
            //    //    sb.Append("数据:" + el.Id + "," + el.Name + "\n");
            //    //}
            //    //TaskDialog.Show("数据", sb.ToString()); 
            //}
            #endregion
    
            #region 遍历所有实例对象
            //所有实例对象
            List<string> list = new List<string>();
            foreach (Element el in collector)
            {
                list.Add("数据:" + el.Id + "," + el.Name + "\n");
            }
            StringBuilder sb = new StringBuilder();
            foreach (string str in list)
            {
                sb.Append(str);
            }
            TaskDialog.Show("数据", sb.ToString());
            #endregion
            ViewType vt = commandData.View.ViewType;
    
            //collector.ToElementIds().Count.ToString() 所有实例对象数量
            //TaskDialog.Show("numbers", collector.ToElementIds().Count.ToString());
            return Result.Succeeded;
        }
    }
    #endregion
    
    打赏 评论

相关推荐 更多相似问题