美文网首页
Revit数据读取与修改

Revit数据读取与修改

作者: Karel_ | 来源:发表于2017-09-04 12:21 被阅读87次

    1.数据读取

    1.1属性读取

    属性分为类型属性和实例属性,可以通过Parametes或者ParametersMap查看 ,后者属性较少。

    Parametes ParametersMap

    GetOrderedParameters对族里面的所有可见属性进行排序,按照属性顺序,忽略族里的分组顺序进行排序。
    GetParameterFormatOptions获取数据格式。
    LookupParameter查找自定义族中的自定义参数。
    Parameter(Guid)通过共享参数的Guid属性在指定的element中查找。
    Parameter(BuiltInParameter)通过自带参数的特定built in param属性来查找。

    BuiltInParameter

    实例属性在实例里面,类型属性在类型里面,可载入族的类型属性在symbol里面。

    测试代码:
     public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
            {
                UIDocument uidoc = commandData.Application.ActiveUIDocument;
                Document doc = uidoc.Document;
    
                Reference refer = uidoc.Selection.PickObject(ObjectType.Element, "请选择墙");
                Wall awall = doc.GetElement(refer) as Wall;
                //Parameter para = awall.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH);//方式一
                Parameter para = awall.LookupParameter("长度");//方式二
                double lenght1 = para.AsDouble();   
                string length2 = para.AsValueString();
                TaskDialog.Show("长度", lenght1.ToString() + "\r\n" + length2);
    
                return Result.Succeeded;
    
            }
    
    测试结果

    1.2其它数据读取

    Lookup不能修改的数据,查看api。

    2.数据的修改

    大部分数据不能直接修改,比如面积/体积(计算得到的),墙的长度(通过墙的位置确定长度的)。

    测试代码:
     public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
            {
                UIDocument uidoc = commandData.Application.ActiveUIDocument;
                Document doc = uidoc.Document;
    
                Reference refer = uidoc.Selection.PickObject(ObjectType.Element, "请选择墙");
                Wall awall = doc.GetElement(refer) as Wall;
                Parameter para = awall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
    
                using (Transaction trans = new Transaction(doc, "修改墙的底部偏移"))//给名称或者在star里面给,两个都没给会报错
                {
                    trans.Start();
                    para.Set(1000 / 304.8);
                    trans.Commit();
                }
    
                return Result.Succeeded;
    
            }
    
    测试结果

    相关文章

      网友评论

          本文标题:Revit数据读取与修改

          本文链接:https://www.haomeiwen.com/subject/nuosjxtx.html