转载请复制以下信息:
原文链接: http://blog.csdn.net/joexiongjin/article/details/8000754
作者: 叶雄进 , Autodesk ADN
文章背景:
在创建墙的时候,可能用户没有设置墙的上部楼层。是否可以通过编程的方式一次性的全部设置墙的上部楼层?
同样的是否可以编程设置房间的上部楼层?
这是可以通过编程实现。
你需要获取所有需要修改上部楼层的墙。然后修改墙的上部楼层参数值为目标楼层即可。 你需要获取目标楼层的ElementId,把这个ElementId值赋值给墙的参数即可。
墙的上部楼层对应的内部枚举变量是
BuiltInParameter.WALL_HEIGHT_TYPE
请看下面的代码。
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Autodesk.Revit .DB;
using Autodesk.Revit.UI;
using Autodesk.Revit .ApplicationServices;
using Autodesk.Revit.Attributes ;
using Autodesk.Revit.UI.Selection;
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class RevitCommand : IExternalCommand
{
//把选中的墙的上部楼层设置为第二层。
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(Level));
var levels = from Element elem in collector
where elem.Name.Equals("Level 2")
select elem;
Level level2 = null;
if (levels.Count() > 0)
level2 = levels.First() as Level;
Selection sel = app.ActiveUIDocument.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element, "please pick wall only");
Wall wall = doc.GetElement(ref1) as Wall;
if (wall == null)
{
return Result.Failed;
}
Transaction trans = new Transaction(doc, "ExComm");
trans.Start();
//设置上部楼层。通过修改参数值来实现,这是唯一的办法。上部楼层的内置枚举值是 BuiltInParameter.WALL_HEIGHT_TYPE
Parameter paraTopConstraint = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE);
paraTopConstraint.Set(level2.Id);
trans.Commit();
return Result.Succeeded ;
}
}
可以用同样的办法来修改房间的上部楼层。房间的上部楼层内置枚举成员是:BuiltInParameter.ROOM_UPPER_LEVEL