获取墙的长宽高

在一个Revit项目里面,如何读取这堵墙的详细信息(名字,长、宽、高等),并且修改它的信息

 

获取对象信息是Revit开发中最基本的步骤。从Revit获取对象信息有三种方式,一个从类的属性读取,另一个是读取对象的参数值,最后一种是读取墙的几何信息。

 

墙的名字可以通过Wall.Name 属性获取,

墙的长度可以从墙的Location 属性间接获取,或者读取wall的 ”长度“ 参数的值。

高度可以从墙的四个参数读取,

公式:(墙的上部连接到的楼层高度+ 上部偏移参数) -  (墙的上部连接到的楼层高度- 上部偏移参数)

若墙上部没有连接到楼层,可以直接用 未连接高度来计算墙的高度。

宽度可以从wall.Width 属性获得。

 

请看下面代码

 

 

 using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using Autodesk.Revit .DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using Autodesk.Revit .ApplicationServices; using Autodesk.Revit.Attributes ; [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)] [RegenerationAttribute(Autodesk.Revit.Attributes.RegenerationOption.Manual)] public class ReadWallData : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; Transaction trans = new Transaction(doc, "ExComm"); trans.Start(); //选择墙 Selection sel = app.ActiveUIDocument.Selection; Reference ref1 = sel.PickObject(ObjectType.Element, "Please select a wall"); Wall wall = ref1.Element as Wall; if(wall == null) { messages = "No wall was selected"; return Result.Failed; } Utility util = new Utility() ; XYZ wallDimension = util.GetWallDimensions(doc, wall); TaskDialog.Show("Wall dimensions", "Length = " + wallDimension.X.ToString() + "/r/n" + "Width=" + wallDimension.Y.ToString() + "/r/n" + "Height" + wallDimension.Z.ToString()); trans.Commit(); return Result.Succeeded; } } class Utility { public XYZ GetWallDimensions(Document doc, Wall wall) { //read the wall's name string wallName = wall.Name; //read the wall's length by reading parameter. LocationCurve lc = wall.Location as LocationCurve; double dWallLength = lc.Curve.Length; //get wall base absoutely height Parameter paramBottomLevel = wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT); //base level. //get the bottom level id ElementId idbottom = paramBottomLevel.AsElementId(); Level levelBottom = doc.get_Element(idbottom) as Level; Parameter paramBotomOffset = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET); //base offset. double dBottomHeight = levelBottom.Elevation + paramBotomOffset.AsDouble(); //get wall top absoutely height double dHeight = 0; Parameter paramTopLevel = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE); //top level. if(paramTopLevel != null) { //get the bottom level id ElementId idTop = paramTopLevel.AsElementId(); Level levelTop = doc.get_Element(idTop) as Level; if (levelTop != null) { Parameter paramTopOffset = wall.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET); //upper offset. double dHeightTop = levelTop.Elevation + paramTopOffset.AsDouble(); //wall height dHeight = dHeightTop - dBottomHeight; } else dHeight = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble(); } //get wall width double dWidth = wall.Width; return new XYZ(dWallLength, dWidth, dHeight); } }

 

 

修改墙的长宽高方法:

修改墙的长度,只能通过修改墙的基线也就是修改LocationCurve中包含的线。

修改墙的高度:可以通过修改墙上下所在的楼层,偏移量等参数来修改。

墙的厚度在Revit2011中只能通过更换一种墙的方式来修改。

在Revit2012中可以直接修改墙类型的各层厚度,实现修改墙的厚度。

 

请大家好好看看我做过的讲座,领会如果获取和修改参数。其它逻辑一眼就可以知道。

 

 

你可能感兴趣的:(Revit,二次开发中级技术)