BIMBase SDK中对象的编辑主要包括属性、夹点、移动复制等通用编辑操作。本节中主要介绍洞口的属性编辑和立方体的移动操作。
9.3.1 洞口对象属性编辑
在3.2.6节中已详细介绍立方体的属性,洞口属性获取与立方体属性获取相似,但洞口属性修改后需要刷新关联立方体,实现重新开洞,详见示例代码9-4。
[BPExternalToolAttribute(className = "OpenningDemo")]
public class 0penningPropertyDemo : BPToolProperty
{
enum enOpenningProperty
{
Length,
Height,
OpenningPropertyCunt
}
public override bool onPropertySet(List<BPObject> elementlist, int index, BPBimUIPropertyItem item)
{
BPDocument doc = BPApplication.singleton().activeDocument;
BPModel model = doc.modelManager.activeModel;
for (int i = 0; i < elementlist.Count(); i++)
{
OpenningDemo Openning = (OpenningDemo)elementlist.ElementAt(i);
switch (index)
{
case (int)enOpenningProperty.Length:
{
int _value = 0;
if (!item.getValue(ref _value))
return false;
Openning.length = _value;
break;
}
case (int)enOpenningProperty.Height:
{
int _value = 0;
if (!item.getValue(ref _value))
return false;
Openning.height = _value;
break;
}
default:
break;
}
Openning.replaceInDocument(doc);
List<BPDataKey> keyList = new List<BPDataKey>();
BPDataKey keyOpenning = Openning.dataKey;
BPRelatedDataUtil.getRelatedElements(keyList,doc,
keyOpenning);
if (keyList.Count == 0) return false;
BPGraphics graphicBoolResult = new BPGraphics();
foreach (BPDataKey key in keyList)
{
BPObject _object = BPObjectUtil.getObjFromData(doc,
key);
if (_object != null)
{
CubeDemo cube = _object as CubeDemo;
if (cube == null)
continue;
cube.replaceInDocument(doc);
}
}
}
return true;
}
}
代码9-4 洞口属性编辑(源文件部分代码)
示例代码9-4为洞口属性类中OnPropertySet接口的实现,可以看到在设置了洞口的长或高,并刷新洞口后,需要通过BPRelatedDataUtil.getRelatedElements获取洞口关联的立方体对象,并刷新立方体的图素修改开洞大小。洞口属性效果实现如图9-2所示。

图9-2 洞口属性实现效果
9.3.2 立方体对象编辑时联动洞口
示例代码9-5主要展示在立方体对象移动时相应的修改关联的洞口,读者需要关注对关联对象的操作,通过继承BPToolMove
类重写move
方法实现。在刷新立方体前,需要通过关联关系找到立方体关联的洞口,对洞口进行移动并刷新洞口。此时,移动立方体时,洞口会跟随移动。
[BPExternalToolAttribute(className = "CubeDemo")]
public class CubeMove : BPToolMove
{
public override void move(List<BPObject> elementlist, GeTransform lst)
{
BPDocument doc = BPApplication.singleton().activeDocument;
BPModel model = doc.modelManager.activeModel;
foreach (var obj in elementlist)
{
CubeDemo cube = obj as CubeDemo;
cube.replaceInDocument(doc);
List<BPDataKey> keyList = new List<BPDataKey>();
BPDataKey keyCube = cube.dataKey;
BPRelatedDataUtil.getRelatedElements(keyList, doc, keyCube);
foreach (BPDataKey key in keyList)
{
BPObject _object = BPObjectUtil.getObjFromData(doc, key);
if (_object != null)
{
OpenningDemo Openning = _object as OpenningDemo;
if (Openning == null) continue;
Openning.onTransform(lst);
Openning.replaceInDocument(doc);
}
}
}
}
}
代码9-5 立方体移动