根据参考说明文档(https://communities.bentley.com/communities/other_communities/chinafirst/w/chinawiki/42976/page)中获取模板库中的模块对象,有以下二个问题:
1、文章中已说明,获取模板库中的模块对象,需要用到TemplateLibrary 类,但是在ORD U4中SDK中不存在该类,是否需要在UE7或者7以上版本才有该类?
2、获取模板库中的模块对象,是否只能用C#实现,C++是否有同样的接口实现?
TemplateLibrary 目前需要更新U7 SDK后才能使用该类,该类主要是创建与编辑模板库接口包含以下功能:
命名空间: Bentley.CifNET. GeometryModel.SDK.Edit
Assembly: Bentley.CifNET. GeometryModel.SDK.Edit.dll
目前仅支持C#实现。
Answer Verified By: Yongan.Fu
class TemplateCmd { public void GetTemplate() { string strLib = TemplateLibrary.GetDefaultTemplateLibraryPath(); TemplateLibrary templateLibrary = TemplateLibrary.Load(strLib); //从模板库的根目录开始遍历。 GetCategoryAllTemplate(templateLibrary.RootCategory); //以Xml Xpath形式获取指定的模板 string strXmlXPath = @"/InRoads/TemplateLibrary/Category/Category[@name='Templates']/Category[@name='Rail']/Template[@name='Double Track - Wooden Sleepers']"; //TemplateDefinition tempDef = templateLibrary.FindTemplateByPath(strXmlXPath); //以xml xpath路径对应的模板库路径形式的路径 string strTemplatePath = @"Templates/Rail/Double Track - Wooden Sleepers"; TemplateDefinition tempDef2 = templateLibrary.FindTemplateByPath(strTemplatePath); } private void GetCategoryAllTemplate(Category category) { //遍历目录下的子目录 foreach(Category subCategory in category.Categories) { GetCategoryAllTemplate(subCategory); } //表面目录下的所有模板 foreach(TemplateDefinition tempDef in category.Templates) { string strName = tempDef.Name; string strPath = tempDef.GetPath(); } } }
另外给您提供一个示例,上面的代码示例通过TemplateLibrary对象遍历模板库中所有的模板对象;以及获取模板库中指定路径的模板对象.