本篇主要介绍如何获取单文件/模型下单个构建的属性信息。
请求地址: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" : "",
"familyGuid" : "",
"guid" : "79d547c1-5dbf-4e6a-811d-951cf37b29da-0004c6dc",
"name" : "norm - 150mm",
"properties" : [ {
"group" : "dimension",
"items" : [ {
"code" : "perimeter",
"extension" : "object",
"key" : "perimeter",
"orderNumber" : ,
"unit" : "mm",
"value" : ,
"valueType" :
} ]
} ]
},
"message" : ""
}
C#实现方法:
/// <summary>
/// 获取构件属性
/// </summary>
/// <param name="accessToken">令牌</param>
/// <param name="fileId">【必填】代表该单模型的文件ID</param>
/// <param name="elementId">【必填】代表该单模型的构件ID</param>
/// <param name="includeOverrides">【非必填】是否查询修改的属性</param>
/// <returns></returns>
public virtual SingleModelSingleElementProperty GetSingleModelSingleElementProperty(string accessToken, long fileId, string elementId, bool? includeOverrides = null)
{
// GET https://api.bimface.com/data/v2/files/{fileId}/elements/{elementId}
string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/elements/{1}", fileId, elementId);
if (includeOverrides != null)
{
url = url + "?includeOverrides=" + includeOverrides;
} BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
headers.AddOAuth2Header(accessToken); try
{
SingleModelSingleElementProperty response; HttpManager httpManager = new HttpManager(headers);
HttpResult httpResult = httpManager.Get(url);
if (httpResult.Status == HttpResult.STATUS_SUCCESS)
{
response = httpResult.Text.DeserializeJsonToObject<SingleModelSingleElementProperty>();
}
else
{
response = new SingleModelSingleElementProperty
{
Message = httpResult.RefText
};
} return response;
}
catch (Exception ex)
{
throw new Exception("[获取构件属性]发生异常!", ex);
}
}
其中调用到的 httpManager.Get() 方法,请参考《C# HTTP系列》
响应结果对应的实体类 SingleModelSingleElementProperty ,封装如下:
/// <summary>
/// 获取单个模型单个构件的属性返回的结果类
/// </summary>
[Serializable]
public class SingleModelSingleElementProperty : GeneralResponse<SingleModelSingleElementEntity>
{ }
[Serializable]
public class SingleModelSingleElementEntity
{
[JsonProperty("boundingBox")]
public BoundingBox BoundingBox { get; set; } [JsonProperty("elementId")]
public string ElementId { get; set; } [JsonProperty("familyGuid")]
public string FamilyGuid { get; set; } [JsonProperty("guid")]
public string Guid { get; set; } [JsonProperty("name")]
public string Name { get; set; } [JsonProperty("properties")]
public PropertyGroup[] Properties { get; set; } /// <summary>返回表示当前对象的字符串。</summary>
/// <returns>表示当前对象的字符串。</returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
if (Properties != null && Properties.Length > )
{
foreach (var pro in Properties)
{
sb.AppendLine(pro.ToString());
}
} return string.Format("SingleModelSingleElementEntity: [boundingBox={0}, elementId={1}, familyGuid={2}, Guid={3}, name={4}, Properties={5}]",
BoundingBox, ElementId, FamilyGuid, Guid,Name, sb);
}
}
[Serializable]
public class BoundingBox
{
[JsonProperty("max")]
public Max Max { get; set; } [JsonProperty("min")]
public Min Min { get; set; } /// <summary>返回表示当前对象的字符串。</summary>
/// <returns>表示当前对象的字符串。</returns>
public override string ToString()
{
return string.Format("[max={0}, min={1}]", Max.ToString(), Min.ToString());
}
}
[Serializable]
public class Max : ThreeDimensionalCoordinates
{
}
[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: SingleModelSingleElementEntity:
[boundingBox=[max=[x=5838.783, y=4387.716, z=],
min=[x=5788.783, y=4237.716, z=]
],
elementId=,
familyGuid=2d99307a-66cd--b173-5c88d252416e-,
Guid=89c90034-40ae-423a--8f5624db86c1-,
name= x 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=-,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= x mm,valueType=]
[code=, extension=, key=familyTypeId, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=systemType, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=building, orderNumber=,unit=,value=,valueType=]
]
[group=尺寸标注,
items=[code=, extension=, key=边 上的宽度, orderNumber=,unit=mm,value=,valueType=]
[code=, extension=, key=边 上的宽度, orderNumber=,unit=mm,value=,valueType=]
[code=, extension=, key=长度, orderNumber=,unit=mm,value=,valueType=]
]
[group=材质和装饰,
items=[code=, extension=, key=材质, orderNumber=,unit=,value=金属 - 铝,valueType=]
]
[group=构造,
items=[code=, extension=, key=位置, orderNumber=,unit=,value=垂直于面,valueType=]
[code=, extension=, key=厚度, orderNumber=,unit=mm,value=,valueType=]
[code=, extension=, key=角竖梃, orderNumber=,unit=,value=False,valueType=]
[code=, extension=, key=轮廓, orderNumber=,unit=,value=默认,valueType=]
]
[group=标识数据,
items=[code=, extension=, key=OmniClass 标题, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=OmniClass 编号, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=URL, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=代码名称, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=制造商, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=图像, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=型号, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=成本, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=标记, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=注释, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=注释记号, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=类型图像, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=类型标记, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=类型注释, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=说明, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=部件代码, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=部件说明, orderNumber=,unit=,value=,valueType=]
]
[group=阶段化,
items=[code=, extension=, key=创建的阶段, orderNumber=,unit=,value=新构造,valueType=]
[code=, extension=, key=拆除的阶段, orderNumber=,unit=,value=无,valueType=]
]
[group=限制条件,
items=[code=, extension=, key=偏移量, orderNumber=,unit=mm,value=,valueType=]
[code=, extension=, key=角度, orderNumber=,unit=°,value=0.00,valueType=]
]
]
测试代码如下:
// 获取构件属性
protected void btnGetSingleModelSingleElementProperty_Click(object sender, EventArgs e)
{
FileConvertApi api = new FileConvertApi(); string elementId = ddlSingleModelElements.SelectedValue; SingleModelSingleElementProperty response = api.GetSingleModelSingleElementProperty(txtAccessToken.Text, txtFileID.Text.ToLong(), elementId, chkIncludeOverrides.Checked); txtResult.Text = response.Code.ToString2()
+ Environment.NewLine
+ "elementId:" + elementId
+ Environment.NewLine
+ response.Message.ToString2()
+ Environment.NewLine
+ response.Data.ToString();
}