/// <summary> /// The construct of the RoofItem class. /// </summary> /// <param name="roof"></param> public RoofItem(Autodesk.Revit.DB.RoofBase roof) : base(roof.Id.IntegerValue.ToString()) { m_roof = roof; this.SubItems.Add(roof.Name); if (m_roof is Autodesk.Revit.DB.FootPrintRoof) { Parameter para = roof.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOF_BASE_LEVEL_PARAM); this.SubItems.Add(LevelConverter.GetLevelByID(para.AsElementId().IntegerValue).Name); } else if (m_roof is Autodesk.Revit.DB.ExtrusionRoof) { Parameter para = roof.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM); this.SubItems.Add(LevelConverter.GetLevelByID(para.AsElementId().IntegerValue).Name); } this.SubItems.Add(roof.RoofType.Name); }
/// <summary> /// get a datatable contains parameters'information of SpotDimension /// here, almost only get Type Parameters of SpotDimension /// </summary> /// <param name="spotDimension">the SpotDimension need to be dealt with</param> /// <returns>a DataTable store Parameter information</returns> public DataTable GetParameterTable(Autodesk.Revit.DB.SpotDimension spotDimension) { try { //check whether is null if (null == spotDimension) { return null; } //create an empty datatable DataTable parameterTable = CreateTable(); //get DimensionType Autodesk.Revit.DB.DimensionType dimensionType = spotDimension.DimensionType; //begin to get Parameters and add them to a DataTable Parameter temporaryParam = null; string temporaryValue = ""; #region Get all SpotDimension element parameters //string formatter string formatter = "#0.000"; //Property Category of SpotDimension AddDataRow("Category", spotDimension.Category.Name, parameterTable); //Leader Arrowhead temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_ELEV_LEADER_ARROWHEAD); Autodesk.Revit.DB.ElementId elementId = temporaryParam.AsElementId(); //if not found that element, add string "None" to DataTable if (-1 == elementId.IntegerValue) { temporaryValue = "None"; } else { temporaryValue = m_document.get_Element(elementId).Name; } AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //Leader Line Weight temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_ELEV_LINE_PEN); temporaryValue = temporaryParam.AsInteger().ToString(); AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //Leader Arrowhead Line Weight temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_ELEV_TICK_MARK_PEN); temporaryValue = temporaryParam.AsInteger().ToString(); AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //Symbol temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_ELEV_SYMBOL); elementId = temporaryParam.AsElementId(); //if not found that element, add string "None" to DataTable if (-1 == elementId.IntegerValue) { temporaryValue = "None"; } else { temporaryValue = m_document.get_Element(elementId).Name; } AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //Text Size temporaryParam = dimensionType.get_Parameter(BuiltInParameter.TEXT_SIZE); temporaryValue = (temporaryParam.AsDouble() / ToFractionalInches).ToString(formatter) + "''"; AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //Text Offset from Leader temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_TEXT_FROM_LEADER); temporaryValue = (temporaryParam.AsDouble() / ToFractionalInches).ToString(formatter) + "''"; AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //Text Offset from Symbol temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_ELEV_TEXT_HORIZ_OFFSET); temporaryValue = (temporaryParam.AsDouble() / ToFractionalInches).ToString(formatter) + "''"; AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //for Spot Coordinates, add some other Parameters if ("Spot Coordinates" == spotDimension.Category.Name) { //Coordinate Origin temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_COORDINATE_BASE); temporaryValue = temporaryParam.AsInteger().ToString(); AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //Top Value temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_ELEV_TOP_VALUE); temporaryValue = s_topBottomValue[temporaryParam.AsInteger()]; AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //Bottom Value temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_ELEV_BOT_VALUE); temporaryValue = s_topBottomValue[temporaryParam.AsInteger()]; AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //North / South s_indicator temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_ELEV_IND_NS); temporaryValue = temporaryParam.AsString(); AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //East / West s_indicator temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_ELEV_IND_EW); temporaryValue = temporaryParam.AsString(); AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); } //for Spot Elevation, add some other Parameters else { //Instance Parameter----Value temporaryParam = spotDimension.get_Parameter(BuiltInParameter.DIM_VALUE_LENGTH); temporaryValue = temporaryParam.AsDouble().ToString(formatter) + "'"; AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //Elevation Origin temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_ELEV_BASE); temporaryValue = s_elevationOrigin[temporaryParam.AsInteger()]; AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //Elevation s_indicator temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_ELEV_IND_ELEVATION); temporaryValue = temporaryParam.AsString(); AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); } //Text Orientation temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_ELEV_TEXT_ORIENTATION); temporaryValue = s_textOrientation[temporaryParam.AsInteger()]; AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //s_indicator as Prefix / Suffix temporaryParam = dimensionType.get_Parameter(BuiltInParameter.SPOT_ELEV_IND_TYPE); temporaryValue = s_indicator[temporaryParam.AsInteger()]; AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //Text Font temporaryParam = dimensionType.get_Parameter(BuiltInParameter.TEXT_FONT); temporaryValue = temporaryParam.AsString(); AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); //Text Background temporaryParam = dimensionType.get_Parameter(BuiltInParameter.DIM_TEXT_BACKGROUND); temporaryValue = s_textBackground[temporaryParam.AsInteger()]; AddDataRow(temporaryParam.Definition.Name, temporaryValue, parameterTable); #endregion return parameterTable; } catch (Exception ex) { Trace.WriteLine(ex.Message, "A error in Function 'GetParameterTable':"); return null; } }
FrameWall( Autodesk.Revit.ApplicationServices.Application rvtApp, Autodesk.Revit.DB.Wall wall, double spacing, FamilySymbol columnType ) { Document rvtDoc = wall.Document; LocationCurve loc = (LocationCurve) wall.Location; XYZ startPt = loc.Curve.GetEndPoint( 0 ); XYZ endPt = loc.Curve.GetEndPoint( 1 ); UV wallVec = new UV( endPt.X - startPt.X, endPt.Y - startPt.Y ); UV axis = new UV( 1.0, 0.0 ); ElementId baseLevelId = wall.get_Parameter( BuiltInParameter.WALL_BASE_CONSTRAINT ).AsElementId(); ElementId topLevelId = wall.get_Parameter( BuiltInParameter.WALL_HEIGHT_TYPE ).AsElementId(); double wallLength = VecLength( wallVec ); wallVec = VecNormalise( wallVec ); int nmax = (int) ( wallLength / spacing ); MessageBox.Show( "Wall Length = " + wallLength + "\nSpacing = " + spacing + "\nMax Number = " + nmax, "Structural Sample", MessageBoxButtons.OK, MessageBoxIcon.Information ); double angle = VecAngle( wallVec, axis ); XYZ loc2 = startPt; double dx = wallVec.U * spacing; double dy = wallVec.V * spacing; for( int i = 0; i < nmax; i++ ) { PlaceColumn( rvtApp, rvtDoc, loc2, angle, columnType, baseLevelId, topLevelId ); loc2 = new XYZ( startPt.X + dx, startPt.Y + dy, startPt.Z ); } PlaceColumn( rvtApp, rvtDoc, endPt, angle, columnType, baseLevelId, topLevelId ); }
/// <summary> /// Make a single element appear in a particular view /// </summary> /// <param name="view"></param> /// <param name="element"></param> protected static void IsolateInView(Autodesk.Revit.DB.View3D view, Autodesk.Revit.DB.Element element) { var fec = GetVisibleElementFilter(); view.CropBoxActive = true; var all = fec.ToElements(); var toHide = fec.ToElements().Where(x => !x.IsHidden(view) && x.CanBeHidden(view) && x.Id != element.Id).Select(x => x.Id).ToList(); if (toHide.Count > 0) view.HideElements(toHide); DocumentManager.Regenerate(); if (view.IsPerspective) { var farClip = view.get_Parameter("Far Clip Active"); farClip.Set(0); } else { var pts = new List<XYZ>(); GetPointCloud(element, pts); var bounding = view.CropBox; var transInverse = bounding.Transform.Inverse; var transPts = pts.Select(transInverse.OfPoint); //ingore the Z coordindates and find //the max X ,Y and Min X, Y in 3d view. double dMaxX = 0, dMaxY = 0, dMinX = 0, dMinY = 0; bool bFirstPt = true; foreach (var pt1 in transPts) { if (true == bFirstPt) { dMaxX = pt1.X; dMaxY = pt1.Y; dMinX = pt1.X; dMinY = pt1.Y; bFirstPt = false; } else { if (dMaxX < pt1.X) dMaxX = pt1.X; if (dMaxY < pt1.Y) dMaxY = pt1.Y; if (dMinX > pt1.X) dMinX = pt1.X; if (dMinY > pt1.Y) dMinY = pt1.Y; } } bounding.Max = new XYZ(dMaxX, dMaxY, bounding.Max.Z); bounding.Min = new XYZ(dMinX, dMinY, bounding.Min.Z); view.CropBox = bounding; } view.CropBoxVisible = false; }
/// <summary> /// Frame a Wall /// </summary> /// <param name="rvtApp">Revit application></param> /// <param name="wall">Wall as host to place column objects</param> /// <param name="spacing">spacing between two columns</param> /// <param name="columnType">column type</param> private void FrameWall(Autodesk.Revit.ApplicationServices.Application rvtApp, Autodesk.Revit.DB.Wall wall, double spacing, Autodesk.Revit.DB.FamilySymbol columnType) { Autodesk.Revit.DB.Document rvtDoc = wall.Document; // get wall location Autodesk.Revit.DB.LocationCurve loc = (Autodesk.Revit.DB.LocationCurve)wall.Location; Autodesk.Revit.DB.XYZ startPt = loc.Curve.get_EndPoint(0); Autodesk.Revit.DB.XYZ endPt = loc.Curve.get_EndPoint(1); // get wall's vector Autodesk.Revit.DB.UV wallVec = new Autodesk.Revit.DB.UV( endPt.X - startPt.X, endPt.Y - startPt.Y); // get the axis vector Autodesk.Revit.DB.UV axis = new Autodesk.Revit.DB.UV(1.0, 0.0); Autodesk.Revit.DB.ElementId baseLevelId = wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId(); Autodesk.Revit.DB.ElementId topLevelId = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId(); // get wall length and vector double wallLength = wallVec.GetLength(); wallVec = wallVec.Normalize(); // get # of column int nmax = (int)(wallLength / spacing); MessageBox.Show("wallLength = " + wallLength + "\r\nspacing = " + spacing.ToString() + "\r\nnmax = " + nmax.ToString()); // get angle of wall and axis double angle = wallVec.AngleTo(axis); // place all column Autodesk.Revit.DB.XYZ loc2 = startPt; double dx = wallVec.U * spacing; double dy = wallVec.V * spacing; for (int i = 0; i < nmax; i++) { PlaceColumn(rvtApp, rvtDoc, loc2, angle, columnType, baseLevelId, topLevelId); loc2 = new XYZ(loc2.X + dx, loc2.Y + dy, loc2.Z); } // place column at end point of wall PlaceColumn(rvtApp, rvtDoc, endPt, angle, columnType, baseLevelId, topLevelId); }