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;
}
}
}
相关推荐
Revit Develop TV 中演示的工程源代码
REVIT 下材质材质工具的源代码,有autodesk 上海研发中心的开发人员提供。多谢他们的无私奉献。
Revit 2018最新二次开发官方案例,147例,含源代码,含说明文档,Revit二次开发学习以及开发必备资源。很多代码都能直接复制使用,代码复用性大,逻辑严谨,值得学习
Revit 2019.2 二次开发官方案例,147例,含源代码,Revit二次开发必备资源。
revit导出json数据源代码,请需要这下载使用
revit导出json数据源代码,请需要这下载使用亲测好用,挺不错的资源,大家快来下载吧!挺有用的!需要的话可以来下载哦!
bool CDlgDwgImage::CDwgPaint::ChargeLine(const RMatrix &xForm, RLine *pLine) { RPoint pt1, pt2; pLine->GetPoint(0, pt1); pLine->GetPoint(1, pt2); xForm.TransPoint3D(RPoint(pt1), (pt1));...
Revit lookup2016-2022源代码
【亲测可用】Revit 2020 Lookup Tables是Revit表格查找工具,是revit开发必不可少的一个组件,需要的朋友可以下载! 用法:将RevitLookup.addin和RevitLookup.dll放到C:\ProgramData\Autodesk\Revit\Addins\2019下...
Revit 2018.2 二次开发官方案例+源代码,总共144例;二次开发必备资源。
Revit导出JSON数据源代码源码.zip
revit教程代码 revit教程代码 revit教程代码 revit教程代码 revit教程代码
Revit中几何编程的深入探究.pptx
Revit插件将rvt转换为obj
Autodesk Revit族详解-源代码(配套光盘文件).rar
Revit 2014 SDK 免安装版本,直接解压即可。内含revit2014 lookup。
修改代码后如何立即使用新修改的代码 如果调试修改后的代码 最后发布时,需要附带Addin文件 深入探究Revit内部世界 RevitLookup 0. 编译和加载RevitLookup 1. 了解Revit内部对象的组织方式 2. 了解Revit内对象的...
编译的基于revit2017的lookup工具,帮助更好的开发revit插件。 RevitLookUp工具可以帮助我们调试Revit数据库,并能够辅助我们理解和查找元素以及它们的参数。但是网站上只有源码需要自己编译。
Revit 2018 SDK 免安装解压可用 含addin manager,revit二次开发学习必备
revit2018 rvt导出obj文件亲测可用,目前仅支持2018版本的revit 将dll,pdb格式文件放到C:\ProgramData\Autodesk\Revit\Addins\2018,通过revit外部工具添加,然后生成local下addin文件即可完成添加;添加后在外部...