1、更新全局参数
//modelSetValue 要修改的全局参数的 键值对
GlobalParameter globalParameter;
//获取所有的全局参数
ISet<ElementId> elementIds = GlobalParametersManager.GetAllGlobalParameters(doc);
for (int i = 0; i < elementIds.Count; i++)
{
globalParameter = doc.GetElement(elementIds.ElementAt(i)) as GlobalParameter;
//名字相同是更新
if (modelSetValue.data_name == globalParameter.Name)
{
globalParameter.GetParameters(globalParameter.Name);
if (!globalParameter.IsDrivenByFormula)
{
ParameterValue gpvalue = globalParameter.GetValue();
ParameterValue pv = null;
if (gpvalue.GetType() == typeof(DoubleParameterValue))
{
//处理角度不应转化的问题 弧度值
double value = double.Parse(modelSetValue.data_value);
if (globalParameter.GetDefinition().GetDataType() == new ForgeTypeId("autodesk.spec.aec:angle-2.0.0"))
{
pv = new DoubleParameterValue(value / 180 * Math.PI);
}
else
{
pv = new DoubleParameterValue(UnitUtils.Convert(value, UnitTypeId.Millimeters, UnitTypeId.Feet));
}
}
else if (gpvalue.GetType() == typeof(IntegerParameterValue))
{
int value = int.Parse(modelSetValue.data_value);
pv = new IntegerParameterValue(value);
}
else if (gpvalue.GetType() == typeof(StringParameterValue))
{
pv = new StringParameterValue(modelSetValue.data_value);
}
globalParameter.SetValue(pv);
}
break;
}
}
2、修改管道直径 管道有接头 三通 法兰
/// <summary>
/// 修改管道直径
/// </summary>
/// <param name="id">管道id</param>
/// <param name="value">待修改的直径值</param>
public void updataPipeDiameter(Document doc, string id, string strValue)
{
ElementId elementId = new ElementId(int.Parse(id));
Element element = doc.GetElement(elementId);
double value = double.Parse(strValue);
double feetValue = UnitUtils.Convert(value, UnitTypeId.Millimeters, UnitTypeId.Feet);
if (element != null && element is Pipe)
{//管道
Pipe pipe = (Pipe)element;
pipe.LookupParameter("直径").Set(feetValue);
}
if (element != null && element is FamilyInstance)
{//管道接头
FamilyInstance instance = (FamilyInstance)element;
ConnectorSet connectorSet = instance.MEPModel.ConnectorManager.Connectors;
if (connectorSet.Size > 2)
{//三通
List<Connector> conList = new List<Connector>();
foreach (Connector connector in connectorSet)
{
conList.Add(connector);
}
XYZ xyz1 = conList[0].Origin;
XYZ xyz2 = conList[1].Origin;
XYZ xyz3 = conList[2].Origin;
XYZ o = (instance.Location as LocationPoint).Point;
XYZ vector1 = o.Subtract(xyz1);
XYZ vector2 = o.Subtract(xyz2);
XYZ vector3 = o.Subtract(xyz3);
if (vector1.IsAlmostEqualTo(vector2) || vector1.IsAlmostEqualTo(-vector2))
{//1和2同尺寸
conList[0].Radius = (feetValue / 2.0);
conList[1].Radius = (feetValue / 2.0);
}
else if (vector1.IsAlmostEqualTo(vector3) || xyz1.IsAlmostEqualTo(-vector3))
{//1和3同尺寸
conList[0].Radius = (feetValue / 2.0);
conList[2].Radius = (feetValue / 2.0);
}
else
{//2和3同尺寸
conList[1].Radius = (feetValue / 2.0);
conList[2].Radius = (feetValue / 2.0);
}
}
else
{//弯头 法兰
foreach (Connector connector in connectorSet)
{
connector.Radius = feetValue / 2.0;
}
}
}
}
3、修改墙体厚度
/// <summary>
/// 修改墙体厚度
/// </summary>
/// <param name="id">墙id</param>
/// <param name="value"></param>
public void updataWallthick(Document doc, string id, string strValue)
{
ElementId elementId = new ElementId(int.Parse(id));
Wall wall = doc.GetElement(elementId) as Wall;
WallType selWallType = wall.WallType;
//墙结构的编辑部件界面
CompoundStructure wallTypeStructure = selWallType.GetCompoundStructure();
//拿到墙的整体厚度
double wallThickness = wallTypeStructure.GetWidth();
//拿到核心边界里面的第一个图层再所有图层里面的开始编号和结束编号。如果两个不一样的时候,需要考虑改变的是哪一个图层的厚度
int startIndex = wallTypeStructure.GetFirstCoreLayerIndex();
int eneIndex = wallTypeStructure.GetLastCoreLayerIndex();
//修改厚度
double value = double.Parse(strValue);
double feetValue = UnitUtils.Convert(value, UnitTypeId.Millimeters, UnitTypeId.Feet);
wallTypeStructure.SetLayerWidth(startIndex, feetValue);
//墙类型重新赋值
selWallType.SetCompoundStructure(wallTypeStructure);
}
4、修改楼板厚度
/// <summary>
/// 修改楼板厚度
/// </summary>
/// <param name="id">楼板id</param>
/// <param name="value"></param>
public void updataFloorthick(Document doc, string id, string strValue)
{
ElementId elementId = new ElementId(int.Parse(id));
Floor floor = doc.GetElement(elementId) as Floor;
FloorType selFloorType = floor.FloorType;
//楼板结构的编辑部件界面
CompoundStructure floorTypeStructure = selFloorType.GetCompoundStructure();
//拿到楼板的整体厚度
double floorThickness = floorTypeStructure.GetWidth();
//拿到核心边界里面的第一个图层再所有图层里面的开始编号和结束编号。如果两个不一样的时候,需要考虑改变的是哪一个图层的厚度
int startIndex = floorTypeStructure.GetFirstCoreLayerIndex();
int eneIndex = floorTypeStructure.GetLastCoreLayerIndex();
//修改厚度
double value = double.Parse(strValue);
double feetValue = UnitUtils.Convert(value, UnitTypeId.Millimeters, UnitTypeId.Feet);
floorTypeStructure.SetLayerWidth(startIndex, feetValue);
//楼板类型重新赋值
selFloorType.SetCompoundStructure(floorTypeStructure);
}
5、删除指定对象
/// <summary>
/// 根据id删除对象
/// </summary>
/// <param name="elementId"></param>
private void deleteEntityById(string elementId)
{
Element element = doc.GetElement(ElementId.Parse(elementId));
if (element != null)
{
if (element is FamilyInstance)
{
//删除的是三通需要处理
FamilyInstance instance = (FamilyInstance)element;
if (instance.MEPModel != null && instance.MEPModel.ConnectorManager != null)
{
ConnectorSet connectorSet = instance.MEPModel.ConnectorManager.Connectors;
if (connectorSet.Size > 2)
{//三通
List<Connector> conList = new List<Connector>();
foreach (Connector connector in connectorSet)
{
conList.Add(connector);
}
XYZ xyz1 = conList[0].Origin;
XYZ xyz2 = conList[1].Origin;
XYZ xyz3 = conList[2].Origin;
XYZ o = (instance.Location as LocationPoint).Point;
XYZ vector1 = o.Subtract(xyz1);
XYZ vector2 = o.Subtract(xyz2);
XYZ vector3 = o.Subtract(xyz3);
if (vector1.IsAlmostEqualTo(vector2) || vector1.IsAlmostEqualTo(-vector2))
{//1和2在一条直线
DeleteElementByIdTools.ConnectPipe(doc, conList[0], conList[1]);
}
else if (vector1.IsAlmostEqualTo(vector3.Normalize()) || vector1.IsAlmostEqualTo(-vector3))
{//1和3在一条直线
DeleteElementByIdTools.ConnectPipe(doc, conList[0], conList[2]);
}
else
{//2和3在一条直线
DeleteElementByIdTools.ConnectPipe(doc, conList[1], conList[2]);
}
}
}
}
doc.Delete(ElementId.Parse(elementId));
}
}
有问题可评论区留言或私信。