|
下面这段代码用来判断柱子的形状。提取柱子的几何形状,看看所有的面,如果有一个面是CylindricalFace,那么其就是圆形柱子。(本命令只适用与判断是矩形柱还是圆形柱)。可以看看如何访问对象的几何信息
[c-sharp] view plaincopyusing System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using Autodesk.Revit .DB; using Autodesk.Revit.UI; using Autodesk.Revit .ApplicationServices; using Autodesk.Revit.Attributes ; using Autodesk.Revit.UI.Selection; [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)] public class RevitCommand : 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 pick a column to get its shape"); Element elem = doc.GetElement(ref1); FamilyInstance column = elem as FamilyInstance; //read its geometry Options options = app.Application.Create.NewGeometryOptions(); GeometryElement geoElement = column.get_Geometry(options); bool bRound = false; Solid solid; foreach (GeometryObject geoObj in geoElement.Objects) { if (geoObj is Solid) { solid = geoObj as Solid; if (solid.Faces.Size > 1) { bRound = IsAnyCylinderFace(ref solid); } if (true == bRound) break; } else if (geoObj is GeometryInstance) { GeometryInstance geoInstance = geoObj as GeometryInstance; GeometryElement geoElem1 = geoInstance.GetSymbolGeometry(); if (geoElem1.Objects.Size > 1) { foreach (GeometryObject geoObj1 in geoElem1.Objects) { if (geoObj1 is Solid && geoObj1 != null) { solid = geoObj1 as Solid; if (solid.Faces.Size > 1) { bRound = IsAnyCylinderFace(ref solid); } if (true == bRound) break; } } } } } TaskDialog.Show("column section shape", bRound.ToString()); trans.Commit(); return Result.Succeeded ; } bool IsAnyCylinderFace(ref Solid solid) { bool bRound = false; foreach (Face face in solid.Faces) { if (face is CylindricalFace) { bRound = true; break; } } return bRound; } } 作者:叶雄进文章来源:http://blog.csdn.net/joexiongjin/article/category/782739
|
|