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

本文介绍了一个在Revit中修改板边界的方法,通过创建临时事务、删除目标板并找到代表该板边界的模型线,最后回滚事务并更新模型线形状。


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

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

原帖地址:点击打开链接

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


Change the boundary of floors/slabs

ByJoe Ye

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)]

publicclassChangeFloor:IExternalCommand

{

publicAutodesk.Revit.UI.ResultExecute(

ExternalCommandDatacommandData,

refstringmessage,

ElementSetelements)

{

Documentdoc = commandData.Application.ActiveUIDocument.Document;

Autodesk.Revit.UI.Selection.Selectionsel =

commandData.Application.ActiveUIDocument.Selection;

Referenceref1 = sel.PickObject (Autodesk.Revit.UI.Selection.ObjectType.Element,

"Please pick a floor to edit");

Floorf = doc.GetElement(ref1)asFloor;

TransactiontransTemp =newTransaction(doc);

transTemp.Start ("tempDelete");

ICollection<ElementId> ids = doc.Delete(f);

transTemp.RollBack ();

List<ModelLine> mLines =newList<ModelLine>();

foreach(ElementIdidinids)

{

Elementele = doc.GetElement (id);

if(eleisModelLine)

{

mLines.Add(eleasModelLine);

}

}

Transactiontrans =newTransaction(doc);

trans.Start("ChangeFloor");

//

foreach(ModelLinemlineinmLines)

{

LocationCurvelCurve = mline.LocationasLocationCurve;

Linec = lCurve.CurveasLine;

XYZpt1 = c.GetEndPoint(0);

XYZpt2 = c.GetEndPoint(1);

Transformtransform =Transform.CreateTranslation(

newXYZ(1, 1, 0));//move the line.

XYZpt1New = transform.OfPoint (pt1);

XYZpt2New = transform.OfPoint (pt2);

LinenewLine =Line.CreateBound(pt1New, pt2New);

lCurve.Curve = newLine;

}

trans.Commit ();

returnResult.Succeeded;

}

}

}

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

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值