BIMFACE二次开发系列目录     【已更新最新开发文章,点击查看详细】

  本篇主要介绍如何获取单文件/模型下单个构建的属性信息。

请求地址:GET https://api.bimface.com/data/v2/files/{fileId}/elements/{elementId}

说明:支持查询模型属性重写后构件的属性,需要设置请求参数includeOverrides的值为true

参数:

请求 path(示例):https://api.bimface.com/data/v2/files/1211223382064960/elements/1109329

                            若需查询重写后的构件属性,请求示例为

                            https://api.bimface.com/data/v2/files/1211223382064960/elements/1109329?includeOverrides=true

请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"

HTTP响应示例(200):

{
  "code" : "success",
  "data" : {
    "boundingBox" : {
      "max" : {
        "x" : -4938.068482562385,
        "y" : -3201.59397858169,
        "z" : 0.0
      },
      "min" : {
        "x" : -4938.068482562385,
        "y" : -3201.59397858169,
        "z" : 0.0
      }
    },
    "elementId" : "313052",
    "familyGuid" : "000222",
    "guid" : "79d547c1-5dbf-4e6a-811d-951cf37b29da-0004c6dc",
    "name" : "norm - 150mm",
    "properties" : [ {
      "group" : "dimension",
      "items" : [ {
        "code" : "perimeter",
        "extension" : "object",
        "key" : "perimeter",
        "orderNumber" : 0,
        "unit" : "mm",
        "value" : 17200,
        "valueType" : 2
      } ]
    } ]
  },
  "message" : ""
}

C#实现方法:

 1 /// <summary>
 2 ///  获取构件属性
 3 /// </summary>
 4 /// <param name="accessToken">令牌</param>
 5 /// <param name="fileId">【必填】代表该单模型的文件ID</param>
 6 /// <param name="elementId">【必填】代表该单模型的构件ID</param>
 7 /// <param name="includeOverrides">【非必填】是否查询修改的属性</param>
 8 /// <returns></returns>
 9 public virtual SingleModelSingleElementProperty GetSingleModelSingleElementProperty(string accessToken, long fileId, string elementId, bool? includeOverrides = null)
10 {
11     // GET https://api.bimface.com/data/v2/files/{fileId}/elements/{elementId}
12     string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/elements/{1}", fileId, elementId);
13     if (includeOverrides != null)
14     {
15         url = url + "?includeOverrides=" + includeOverrides;
16     }
17 
18     BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
19     headers.AddOAuth2Header(accessToken);
20 
21     try
22     {
23         SingleModelSingleElementProperty response;
24 
25         HttpManager httpManager = new HttpManager(headers);
26         HttpResult httpResult = httpManager.Get(url);
27         if (httpResult.Status == HttpResult.STATUS_SUCCESS)
28         {
29             response = httpResult.Text.DeserializeJsonToObject<SingleModelSingleElementProperty>();
30         }
31         else
32         {
33             response = new SingleModelSingleElementProperty
34             {
35                 Message = httpResult.RefText
36             };
37         }
38 
39         return response;
40     }
41     catch (Exception ex)
42     {
43         throw new Exception("[获取构件属性]发生异常!", ex);
44     }
45 }

其中调用到的 httpManager.Get() 方法,请参考《C# HTTP系列》

 响应结果对应的实体类 SingleModelSingleElementProperty ,封装如下:

/// <summary>
/// 获取单个模型单个构件的属性返回的结果类
/// </summary>
[Serializable]
public class SingleModelSingleElementProperty : GeneralResponse<SingleModelSingleElementEntity>
{

}
 1 [Serializable]
 2 public class SingleModelSingleElementEntity
 3 {
 4     [JsonProperty("boundingBox")]
 5     public BoundingBox BoundingBox { get; set; }
 6 
 7     [JsonProperty("elementId")]
 8     public string ElementId { get; set; }
 9 
10     [JsonProperty("familyGuid")]
11     public string FamilyGuid { get; set; }
12 
13     [JsonProperty("guid")]
14     public string Guid { get; set; }
15 
16     [JsonProperty("name")]
17     public string Name { get; set; }
18 
19     [JsonProperty("properties")]
20     public PropertyGroup[] Properties { get; set; }
21 
22     /// <summary>返回表示当前对象的字符串。</summary>
23     /// <returns>表示当前对象的字符串。</returns>
24     public override string ToString()
25     {
26         StringBuilder sb = new StringBuilder();
27         if (Properties != null && Properties.Length > 0)
28         {
29             foreach (var pro in Properties)
30             {
31                 sb.AppendLine(pro.ToString());
32             }
33         }
34 
35         return string.Format("SingleModelSingleElementEntity: [boundingBox={0}, elementId={1}, familyGuid={2}, Guid={3}, name={4}, Properties={5}]",
36                              BoundingBox, ElementId, FamilyGuid, Guid,Name, sb);
37     }
38 }
 1 [Serializable]
 2 public class BoundingBox
 3 {
 4     [JsonProperty("max")]
 5     public Max Max { get; set; }
 6 
 7     [JsonProperty("min")]
 8     public Min Min { get; set; }
 9 
10     /// <summary>返回表示当前对象的字符串。</summary>
11     /// <returns>表示当前对象的字符串。</returns>
12     public override string ToString()
13     {
14         return string.Format("[max={0}, min={1}]", Max.ToString(), Min.ToString());
15     }
16 }
1 [Serializable]
2 public class Max : ThreeDimensionalCoordinates
3 {
4 }
[Serializable]
public class Min : ThreeDimensionalCoordinates
{
}
/// <summary>
///  三维坐标系
/// </summary>
public class ThreeDimensionalCoordinates
{
    [JsonProperty("x")]
    public double X { get; set; }

    [JsonProperty("y")]
    public double Y { get; set; }

    [JsonProperty("z")]
    public double Z { get; set; }

    /// <summary>返回表示当前对象的字符串。</summary>
    /// <returns>表示当前对象的字符串。</returns>
    public override string ToString()
    {
        return string.Format("[x={0}, y={1}, z={2}]", X, Y, Z);
    }
}

其中 PropertyGroup 类,请参考《C#开发BIMFACE系列17 服务端API之获取模型数据2:获取构件材质列表》中的 响应结果类中的 PropertyGroup 类。

测试

在BIMFACE的控制台中可以看到我们上传的文件列表,共计2个文件。模型状态均为转换成功。

以“01_BIMFACE示例文件-Revit模型.rvt”为例来测试。

 
完整的属性为:
success
elementId:300067

SingleModelSingleElementEntity: 
[boundingBox=[max=[x=5838.783, y=4387.716, z=6000], 
              min=[x=5788.783, y=4237.716, z=5475]
             ], 
 elementId=300067, 
 familyGuid=2d99307a-66cd-4439-b173-5c88d252416e-00002122, 
 Guid=89c90034-40ae-423a-8935-8f5624db86c1-00049423, 
 name=50 x 150 mm, 
 Properties=
    [group=基本属性, 
     items= [code=, extension=, key=specialty, orderNumber=,unit=,value=,valueType=]
            [code=, extension=, key=floor, orderNumber=,unit=,value=F2,valueType=]
            [code=, extension=, key=categoryId, orderNumber=,unit=,value=-2000171,valueType=]
            [code=, extension=, key=categoryName, orderNumber=,unit=,value=幕墙竖梃,valueType=]
            [code=, extension=, key=family, orderNumber=,unit=,value=矩形竖梃,valueType=]
            [code=, extension=, key=familyId, orderNumber=,unit=,value=,valueType=]
            [code=, extension=, key=familyType, orderNumber=,unit=,value=50 x 150 mm,valueType=]
            [code=, extension=, key=familyTypeId, orderNumber=,unit=,value=8486,valueType=]
            [code=, extension=, key=systemType, orderNumber=,unit=,value=,valueType=]
            [code=, extension=, key=building, orderNumber=,unit=,value=,valueType=]
    ]
    [group=尺寸标注, 
     items=[code=, extension=, key=边 1 上的宽度, orderNumber=,unit=mm,value=25,valueType=2]
           [code=, extension=, key=边 2 上的宽度, orderNumber=,unit=mm,value=25,valueType=2]
           [code=, extension=, key=长度, orderNumber=,unit=mm,value=525,valueType=2]
    ]
    [group=材质和装饰, 
     items=[code=, extension=, key=材质, orderNumber=,unit=,value=金属 - 铝,valueType=4]
    ]
    [group=构造, 
     items=[code=, extension=, key=位置, orderNumber=,unit=,value=垂直于面,valueType=4]
           [code=, extension=, key=厚度, orderNumber=,unit=mm,value=150,valueType=2]
           [code=, extension=, key=角竖梃, orderNumber=,unit=,value=False,valueType=1]
           [code=, extension=, key=轮廓, orderNumber=,unit=,value=默认,valueType=4]
    ]
    [group=标识数据, 
     items=[code=, extension=, key=OmniClass 标题, orderNumber=,unit=,value=,valueType=3]
           [code=, extension=, key=OmniClass 编号, orderNumber=,unit=,value=,valueType=3]
           [code=, extension=, key=URL, orderNumber=,unit=,value=,valueType=3]
           [code=, extension=, key=代码名称, orderNumber=,unit=,value=,valueType=3]
           [code=, extension=, key=制造商, orderNumber=,unit=,value=,valueType=3]
           [code=, extension=, key=图像, orderNumber=,unit=,value=,valueType=4]
           [code=, extension=, key=型号, orderNumber=,unit=,value=,valueType=3]
           [code=, extension=, key=成本, orderNumber=,unit=,value=,valueType=2]
           [code=, extension=, key=标记, orderNumber=,unit=,value=,valueType=3]
           [code=, extension=, key=注释, orderNumber=,unit=,value=,valueType=3]
           [code=, extension=, key=注释记号, orderNumber=,unit=,value=,valueType=3]
           [code=, extension=, key=类型图像, orderNumber=,unit=,value=,valueType=4]
           [code=, extension=, key=类型标记, orderNumber=,unit=,value=,valueType=3]
           [code=, extension=, key=类型注释, orderNumber=,unit=,value=,valueType=3]
           [code=, extension=, key=说明, orderNumber=,unit=,value=,valueType=3]
           [code=, extension=, key=部件代码, orderNumber=,unit=,value=,valueType=3]
           [code=, extension=, key=部件说明, orderNumber=,unit=,value=,valueType=3]
    ]
    [group=阶段化, 
     items=[code=, extension=, key=创建的阶段, orderNumber=,unit=,value=新构造,valueType=4]
           [code=, extension=, key=拆除的阶段, orderNumber=,unit=,value=无,valueType=4]
    ]
    [group=限制条件, 
     items=[code=, extension=, key=偏移量, orderNumber=,unit=mm,value=0,valueType=2]
           [code=, extension=, key=角度, orderNumber=,unit=°,value=0.00,valueType=2]
    ]
]

测试代码如下:

 1 // 获取构件属性
 2 protected void btnGetSingleModelSingleElementProperty_Click(object sender, EventArgs e)
 3 {
 4     FileConvertApi api = new FileConvertApi();
 5 
 6     string elementId = ddlSingleModelElements.SelectedValue;
 7 
 8     SingleModelSingleElementProperty response = api.GetSingleModelSingleElementProperty(txtAccessToken.Text, txtFileID.Text.ToLong(), elementId, chkIncludeOverrides.Checked);
 9 
10     txtResult.Text = response.Code.ToString2()
11                    + Environment.NewLine
12                    + "elementId:" + elementId
13                    + Environment.NewLine
14                    + response.Message.ToString2()
15                    + Environment.NewLine
16                    + response.Data.ToString();
17 }
BIMFACE二次开发系列目录     【已更新最新开发文章,点击查看详细】
内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/SavionZhang/p/11465063.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!