本文主要是介绍Revit二次开发之“墙体开洞NewOpening”,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
墙体开洞的函数是Document.Create.NewOpening(Wall,XYZ,XYX);但是这里有个技巧就是如何选取墙上的两点。添加一个墙的过滤条件。using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinForm = System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using RevitApp = Autodesk.Revit.ApplicationServices;
using System.Xml;
namespace RevitCodes
{
class WallSelectionFilter : ISelectionFilter
{
public bool AllowElement(Element e)
{
return e is Wall;
}
public bool AllowReference(Reference r, XYZ p)
{
return true ;
}
}
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmdCreateOpening : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIApplication uiApp = cmdData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
Selection sel = uiApp.ActiveUIDocument.Selection;
Transaction ts = new Transaction(doc, " opening " );
ts.Start();
Wall wall = doc.GetElement(sel.PickObject(ObjectType.Element, " 请选择一面墙。 " )) as Wall;
WallSelectionFilter f = new WallSelectionFilter();
XYZ pt1 = sel.PickObject(ObjectType.Element, f, " 请选择墙上第一点。 " ).GlobalPoint;
XYZ pt2 = sel.PickObject(ObjectType.Element, f, " 请选择墙上第二点。 " ).GlobalPoint;
doc.Create.NewOpening(wall, pt1, pt2);
ts.Commit();
return Result.Succeeded;
}
}
}
这篇关于Revit二次开发之“墙体开洞NewOpening”的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!