C#开发BIMFACE系列16 服务端API之获取模型数据1:查询满足条件的构件ID列表

2023-02-20,,

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

源文件/模型转换完成之后,可以获取模型的具体数据。本篇介绍根据文件ID查询满足条件的构件ID列表。

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

说明:根据六个维度(专业,系统类型,楼层,构件类型,族,族类型)获取对应的构件ID列表,任何维度都是可选的。

构件ID分页查询相关请参考这里

同时,也支持根据空间关系从房间计算出房间内的构件ID列表

构件与房间空间关系计算相关请参考这里

参数:

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

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

HTTP响应示例(200):

{
"code": "success",
"message": null,
"data": [
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
]
}

C#实现方法:

 /// <summary>
/// 查询满足条件的构件ID列表
/// </summary>
/// <param name="accessToken">令牌</param>
/// <param name="fileId">文件ID</param>
/// <param name="request">请求参数对象</param>
/// <returns></returns>
public virtual FileElementsGetResponse GetFileElements(string accessToken, string fileId, FileElementsGetRequest request = null)
{
// GET https://api.bimface.com/data/v2/files/{fileId}/elementIds
string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/elementIds", fileId); BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
headers.AddOAuth2Header(accessToken); string data = string.Empty;
if (request != null)
{
data = request.SerializeToJson();
} try
{
FileElementsGetResponse response; HttpManager httpManager = new HttpManager(headers);
HttpResult httpResult = httpManager.Get(url, data);
if (httpResult.Status == HttpResult.STATUS_SUCCESS)
{
response = httpResult.Text.DeserializeJsonToObject<FileElementsGetResponse>();
}
else
{
response = new FileElementsGetResponse
{
Message = httpResult.RefText
};
} return response;
}
catch (Exception ex)
{
throw new Exception("[查询满足条件的构件ID列表]发生异常!", ex);
}
}

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

封装的其他请求参数类 FileElementsGetRequest

 /// <summary>
/// 查询满足条件的构件ID列表请求参数类
/// </summary>
[Serializable]
public class FileElementsGetRequest
{
public FileElementsGetRequest()
{
CategoryId = null;
Family = null;
FamilyType = null;
Floor = null;
PaginationContextId = null;
PaginationNo = null;
PaginationSize = null;
RoomId = null;
RoomToleranceXY = null;
RoomToleranceZ = null;
Specialty = null;
SystemType = null;
} ///// <summary>
///// 【必填】代表该单模型的文件ID
///// </summary>
//[JsonProperty("fileId")]
//public long FileId { get; set; } /// <summary>
/// 【非必填】筛选条件构件类型id
/// </summary>
[JsonProperty("categoryId",NullValueHandling = NullValueHandling.Ignore)]
public string CategoryId { get; set; } /// <summary>
/// 【非必填】筛选条件族
/// </summary>
[JsonProperty("family", NullValueHandling = NullValueHandling.Ignore)]
public string Family { get; set; } /// <summary>
/// 【非必填】筛选条件族类型
/// </summary>
[JsonProperty("familyType", NullValueHandling = NullValueHandling.Ignore)]
public string FamilyType { get; set; } /// <summary>
/// 【非必填】筛选条件楼层
/// </summary>
[JsonProperty("floor", NullValueHandling = NullValueHandling.Ignore)]
public string Floor { get; set; } /// <summary>
/// 【非必填】根据paginationContextId返回构件ID列表
/// </summary>
[JsonProperty("paginationContextId", NullValueHandling = NullValueHandling.Ignore)]
public string PaginationContextId { get; set; } /// <summary>
/// 【非必填】返回结果中paginationNo对应的页码构件ID项
/// </summary>
[JsonProperty("paginationNo", NullValueHandling = NullValueHandling.Ignore)]
public int? PaginationNo { get; set; } /// <summary>
/// 【非必填】返回结果按照paginationSize分页
/// </summary>
[JsonProperty("paginationSize", NullValueHandling = NullValueHandling.Ignore)]
public int? PaginationSize { get; set; } /// <summary>
/// 【非必填】筛选条件房间id
/// </summary>
[JsonProperty("roomId", NullValueHandling = NullValueHandling.Ignore)]
public string RoomId { get; set; } /// <summary>
/// 【非必填】XY坐标轴方向对构件的筛选容忍度
/// </summary>
[JsonProperty("roomToleranceXY", NullValueHandling = NullValueHandling.Ignore)]
public RoomTolerance? RoomToleranceXY { get; set; } /// <summary>
/// 【非必填】Z坐标轴方向对构件的筛选容忍度
/// </summary>
[JsonProperty("roomToleranceZ", NullValueHandling = NullValueHandling.Ignore)]
public RoomTolerance? RoomToleranceZ { get; set; } /// <summary>
/// 【非必填】筛选条件专业
/// </summary>
[JsonProperty("specialty", NullValueHandling = NullValueHandling.Ignore)]
public string Specialty { get; set; } /// <summary>
/// 【非必填】筛选条件系统类型
/// </summary>
[JsonProperty("systemType", NullValueHandling = NullValueHandling.Ignore)]
public string SystemType { get; set; }
}
 /// <summary>
/// 坐标轴方向对构件的筛选容忍度
/// </summary>
public enum RoomTolerance
{
STRICT, ORDINARY, LENIENT
}

参数都是可选的,如果不设置,则默认不添加到请求中。

测试

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

以“01_BIMFACE示例文件-Revit模型.rvt”为例查询其构建ID列表

查看结果中返回了构建ID列表。

如果使用 .dwg 二维文件进行测试则返回一下信息:unsupported operation:[please upgrade this databag to support specialty tree]

查询满足条件的构件ID列表 ,只对三维模型适用。二维图纸没有目录树。

测试代码如下:

// 查询满足条件的构件ID列表
protected void btnGetFileElements_Click(object sender, EventArgs e)
{
FileConvertApi api = new FileConvertApi();
FileElementsGetResponse response = api.GetFileElements(txtAccessToken.Text, txtFileID.Text); txtResult.Text = response.Code.ToString2()
+ Environment.NewLine
+ response.Message.ToString2()
+ Environment.NewLine
+ response.Data.ToStringWith(",");
}

查询构建ID列表返回类 FileElementsGetResponse

/// <summary>
/// 查询满足条件的构件ID列表返回的结果类
/// </summary>
public class FileElementsGetResponse : GeneralResponse<List<string>>
{
}

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

C#开发BIMFACE系列16 服务端API之获取模型数据1:查询满足条件的构件ID列表的相关教程结束。

《C#开发BIMFACE系列16 服务端API之获取模型数据1:查询满足条件的构件ID列表.doc》

下载本文的Word格式文档,以方便收藏与打印。