ABD CONNECT 版本已经支持 .NET API。 开发时需要参考的dll文件是: $(ABD_INSTALL_DIR)\Assemblies\Bentley.Building.Api.dll 。主要的API接口都定义在 Bentley.Building.Api 这个名字空间中。
API接口所定义的类是C语言接口的封装。以FormRecipe为例, interface ITFFormRecipe 定义了mdlTFFormRecipe_xxx函数所提供的功能。
这里有一个简单的例子,包含在SDK 的example 中。examples\buildingelement\Test.cs
public sealed class Test { public static void Run(string unparsed) { DPoint3d start = new DPoint3d(0,0,0); DPoint3d opposite = new DPoint3d(5000, 0, 0); //建立FormRecipe对象 TFFormRecipeLinearList form = new TFFormRecipeLinearList(); //初始化FormRecipe对象 Bentley.DgnPlatformNET.DgnModelRef modelRef = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModelRef(); form.Init(""); form.SetModelRef(modelRef, 0); //得到ITFFormRecipeLinear接口 ITFFormRecipeLinear wallForm = form.AsTFFormRecipeLinear; //设置属性 wallForm.SetEndPoints(ref start, ref opposite, 0); wallForm.SetThickness(200, 0); wallForm.SetTopFixedHeight(1000, 0); string DGType = "Wall"; string DGItem = "Brick"; string FamilyName = "WallComponent"; string PartName = "Brick"; ITFFormRecipe f = form.AsTFFormRecipe; f.SetPartName(PartName, 0); f.SetPartFamilyName(FamilyName, 0); //同步内存中的数据定义 f.Synchronize(0); //生成Element Element elm; f.GetElement(0, out elm); //得到系统用的DataGroup对象 TFCatalogList datagroup = new TFCatalogList(); ITFCatalog catalog = datagroup.AsTFCatalog; //得到具体的CatalogItem定义 ITFCatalogItemList itemList; catalog.GetCatalogItemByNames(DGType, DGItem, 0, out itemList); //得到CatalogItem接口 ITFCatalogItem item = itemList.AsTFCatalogItem; //设置Family Part属性 item.SetFamilyAndPartValueChar(FamilyName, PartName, 0); //在Element上增加DataGroup属性 item.AttachLinkagesOnElement(ref elm, 0); //把element保存到文件中 elm.AddToModel(); } }
上面这段代码,演示的是创建一段墙。还有另外的一种方式创建墙,具体的代码是:
public static Element CreateElement(DPoint3d start, DPoint3d opposite, int height, bool isDynamic = false) { //得到系统DataGroup对象 TFCatalogList datagroup = new TFCatalogList(); datagroup.Init(""); ITFCatalog catalog = datagroup as ITFCatalog; //得到CatalogItem定义 ITFCatalogItemList itemList; catalog.GetCatalogItemByNames("Wall", "Brick", 0, out itemList); //创建LoadableWall对象。 TFLoadableWallList form = new TFLoadableWallList(); form.InitFromCatalogItem(itemList, 0); form.SetWallType(TFdLoadableWallType.TFdLoadableWallType_Line, 0); //设置属性 start.ScaleInPlace(1.0 / 304800.0); opposite.ScaleInPlace(1.0 / 304800.0); form.SetEndPoints(ref start, ref opposite, 0); form.SetHeight(height, 0); form.SetThickness(height / 10.0, 0); //构造Element Element elm; if ( isDynamic ) { Element baseLine; form.GetPreviewDescr(out baseLine, 0, out elm); // setting the modelref on the element is needed later for transient draw code to work var itfe = elm as Bentley.Building.Api.ITFElement; if ( itfe != null ) itfe.SetModelRef(Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModelRef(), 0); } else { form.GetElementWritten(out elm, Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModelRef(), 0); } return elm; }