编程设置房间以及墙的上部楼层


转载请复制以下信息:
原文链接: 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



  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值