EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 718|回复: 6
打印 上一主题 下一主题

Revit编程修改板的边界(含完整源代码)

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12404

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-15 14:01:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

我在ADN AEC英文博客中发表了一篇文章用于修改板的边界。Revit没有直接提供API来修改板的边界。

发现了这个解决方案,先写了英文版的。这里就不翻译,直接贴过来。

原帖地址:点击打开链接

http://adndevblog.typepad.com/aec/2013/10/change-the-boundary-of-floorsslabs.html



Change the boundary of floors/slabs
Revit didn’t expose the API to edit floors/slabs boundary by now. Here introduce a trick to edit the boundary.
For a Revit slab or floor, there are mapping model lines to representing the boundary of tha slab. If a floor boundary has 6 segments, there are 6 corresponding model lines for this floor. When we change those model line's position or shape, the slab or floor's shape will be updated accordingly.
There probably are many model lines in a document. How can we find the model lines that representing the slab is the key point.
Here is the solution: You need to create a tempt transaction. During this temp transaction, delete the target slab by Document.Delete() method. This method will return all the deleted elements' ids after the slab is deleted. So the slab's boundary model line can be find by iterating all the return id (get the element from those ids and compare the object type if they are ModelLine class). Finally abort this temp transaction.
After get the boundary's boundary model lines, you can change the model line's shape by changing those ModelLine object ( use this method
LocationCurve lCurve = modelLine.Location as LocationCurve;
lCurve.Curve = newcurve.
I just did a very quick test, this works.
  
Here is the complete command code.
For simplicity, it just moves the floor by creating new boundary lines by moving the old segment.  Here suppose the segment lines are all straight lines.
[Autodesk.Revit.Attributes.Transaction(
          Autodesk.Revit.Attributes.TransactionMode.Manual)]
        public class ChangeFloor : IExternalCommand
        {
          public Autodesk.Revit.UI.Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
          {
            Document doc = commandData.Application.ActiveUIDocument.Document;
            Autodesk.Revit.UI.Selection.Selection sel =
              commandData.Application.ActiveUIDocument.Selection;

            Reference ref1 = sel.PickObject (Autodesk.Revit.UI.Selection.ObjectType.Element,
              "Please pick a floor to edit");
            Floor f = doc.GetElement(ref1) as Floor;

            Transaction transTemp = new Transaction(doc);
            transTemp.Start ("tempDelete");
            ICollection<ElementId> ids = doc.Delete(f);
            transTemp.RollBack ();

            List<ModelLine> mLines = new List<ModelLine>();
            foreach (ElementId id in ids)
            {
              Element ele = doc.GetElement (id);
              if (ele is ModelLine)
              {
                mLines.Add(ele as ModelLine);
              }
            }

            Transaction trans = new Transaction(doc);
            trans.Start("ChangeFloor");

            //
            foreach (ModelLine mline in mLines)
            {
              LocationCurve lCurve = mline.Location as LocationCurve;
              Line c = lCurve.Curve as Line;
              XYZ pt1 = c.GetEndPoint(0);
              XYZ pt2 = c.GetEndPoint(1);

              Transform transform = Transform.CreateTranslation(
                new XYZ(1, 1, 0)); //move the line.
              XYZ pt1New = transform.OfPoint (pt1);
              XYZ pt2New = transform.OfPoint (pt2);
              Line newLine = Line.CreateBound(pt1New, pt2New);
              lCurve.Curve = newLine;

            }
            trans.Commit ();
            return Result.Succeeded;
          }
        }

    }



转载请复制以下信息:
原文链接: http://blog.csdn.net/joexiongjin/article/details/12583387
作者:  叶雄进 , Autodesk ADN

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对
工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言

11

主题

815

帖子

1367

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1367
3F
发表于 2014-2-15 14:28:24 | 只看该作者
路过!!! 不发表意见……

23

主题

793

帖子

1941

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1941
4F
发表于 2014-2-15 14:33:07 | 只看该作者
路过!!! 不发表意见……

5

主题

726

帖子

1692

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1692
6F
发表于 2014-2-18 12:03:22 | 只看该作者
路过!!! 不发表意见……
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-16 20:07

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表