public static void DrawForm(RenderDescription description, object obj) { Autodesk.Revit.DB.Form form = obj as Autodesk.Revit.DB.Form; if (form == null) { return; } DrawGeometryElement(description, form.get_Geometry(new Options())); }
private void CreateHeightLabel(Document fdoc, Autodesk.Revit.DB.Form extruedForm) { try { Options opt = m_app.Create.NewGeometryOptions(); opt.ComputeReferences = true; opt.IncludeNonVisibleObjects = true; PlanarFace topFace = null; GeometryElement geometryElement = extruedForm.get_Geometry(opt); foreach (GeometryObject obj in geometryElement) { Solid solid = obj as Solid; if (solid != null) { UV uv = new UV(0, 0); foreach (Face face in solid.Faces) { XYZ normal = face.ComputeNormal(uv); if (normal.IsAlmostEqualTo(new XYZ(0, 0, 1)))//top face { topFace = face as PlanarFace; } } } } if (null != topFace) { #if RELEASE2016 Dimension dimension = fdoc.FamilyCreate.NewAlignment(FindView(fdoc, "South"), FindLevel(fdoc, "Level 2").GetPlaneReference(), topFace.Reference); #else Dimension dimension = fdoc.FamilyCreate.NewAlignment(FindView(fdoc, "South"), FindLevel(fdoc, "Level 2").PlaneReference, topFace.Reference); #endif dimension.IsLocked = true; } } catch (Exception ex) { MessageBox.Show("Failed to create a dimension for Height.\n" + ex.Message, "MassCreator : CreateHeightLabel", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
//Create family for each building //http://thebuildingcoder.typepad.com/blog/2011/06/creating-and-inserting-an-extrusion-family.html private bool CreateFamilyFile(ProcessPolygon polygon, double height, string familyFileName, XYZ translation) { bool success = true; Document FamDoc = null; Autodesk.Revit.DB.Form form = null; using (Transaction CreateFamily = new Transaction(_doc)) { CreateFamily.Start("Create a new Family"); FamDoc = _doc.Application.NewFamilyDocument(this.FamilyTemplateAddress); CreateFamily.Commit(); } ReferenceArray refAr = polygon.Get_ReferenceArray(FamDoc, translation); using (Transaction CreateExtrusion = new Transaction(FamDoc)) { FailureHandlingOptions failOpt = CreateExtrusion.GetFailureHandlingOptions(); failOpt.SetFailuresPreprocessor(new WarningSwallower()); CreateExtrusion.SetFailureHandlingOptions(failOpt); CreateExtrusion.Start("Create Extrusion"); /*Mohammad took this out of try */ try { form = FamDoc.FamilyCreate.NewExtrusionForm(true, refAr, height * XYZ.BasisZ); } catch (Exception) { this.FailedAttemptsToCreateBuildings++; success = false; } CreateExtrusion.Commit(); } //Added by Mohammad using (Transaction AddParamTrans = new Transaction(FamDoc)) { AddParamTrans.Start("Add Parameter"); Autodesk.Revit.ApplicationServices.Application app = FamDoc.Application; View3D view3d = createView3d(); Dimension windowInsetDimension = null; FaceArray faces = new FaceArray(); if (form.IsSolid) { Options options = new Options(); options.ComputeReferences = true; //options.View = new Autodesk.Revit.DB.View(); //GeometryObjectArray geoArr = extrusion.get_Geometry(options).Objects; IEnumerator <GeometryObject> Objects = form.get_Geometry(options).GetEnumerator(); //foreach (GeometryObject geoObj in geoArr) while (Objects.MoveNext()) { GeometryObject geoObj = Objects.Current; if (geoObj is Solid) { Solid s = geoObj as Solid; foreach (Face fc in s.Faces) { //MessageBox.Show(fc.ComputeNormal(new UV(0, 0)).X.ToString() + "/n" + fc.ComputeNormal(new UV(0, 0)).Y.ToString() + "/n" + fc.ComputeNormal(new UV(0, 0)).Z.ToString()); if (Math.Round((fc.ComputeNormal(new UV(0, 0))).Z) == 1 || Math.Round((fc.ComputeNormal(new UV(0, 0))).Z) == -1) { faces.Append(fc); } } //************************************************************************************************************** //****************************Here is the Error ********************************************************************** //************************************************************************************************************************ //windowInsetDimension = AddDimension( FamDoc, view3d, faces.get_Item( 0 ), faces.get_Item( 1 ) ); View viewElevation = new FilteredElementCollector(FamDoc).OfClass(typeof(View)).Cast <View>().Where <View>(v => ViewType.Elevation == v.ViewType).FirstOrDefault <View>(); windowInsetDimension = AddDimension(FamDoc, viewElevation, faces.get_Item(0), faces.get_Item(1)); } } } //Test for creating dimension #region two lines creating dimenstion //// first create two lines //XYZ pt1 = new XYZ(5, 0, 5); //XYZ pt2 = new XYZ(5, 0, 10); //Line line = Line.CreateBound(pt1, pt2); //Plane plane = app.Create.NewPlane(pt1.CrossProduct(pt2), pt2); //SketchPlane skplane = SketchPlane.Create(FamDoc, plane); //ModelCurve modelcurve1 = FamDoc.FamilyCreate.NewModelCurve(line, skplane); //pt1 = new XYZ(10, 0, 5); //pt2 = new XYZ(10, 0, 10); //line = Line.CreateBound(pt1, pt2); //plane = app.Create.NewPlane(pt1.CrossProduct(pt2), pt2); //skplane = SketchPlane.Create(FamDoc, plane); //ModelCurve modelcurve2 = FamDoc.FamilyCreate.NewModelCurve(line, skplane); //// now create a linear dimension between them //ReferenceArray ra = new ReferenceArray(); //ra.Append(modelcurve1.GeometryCurve.Reference); //ra.Append(modelcurve2.GeometryCurve.Reference); //pt1 = new XYZ(5, 0, 10); //pt2 = new XYZ(10, 0, 10); //line = Line.CreateBound(pt1, pt2); //Dimension dim = FamDoc.FamilyCreate.NewLinearDimension(view3d, line, ra); #endregion //creates a prameter named index for each family. BuiltInParameterGroup paramGroup = (BuiltInParameterGroup)Enum.Parse(typeof(BuiltInParameterGroup), "PG_GENERAL"); ParameterType paramType = (ParameterType)Enum.Parse(typeof(ParameterType), "Length"); FamilyManager m_manager = FamDoc.FamilyManager; FamilyParameter famParam = m_manager.AddParameter("Height", paramGroup, paramType, true); //Set the value for the parameter if (m_manager.Types.Size == 0) { m_manager.NewType("Type 1"); } m_manager.Set(famParam, height); //connects dimension to lable called with //windowInsetDimension.FamilyLabel = famParam; AddParamTrans.Commit(); } SaveAsOptions opt = new SaveAsOptions(); opt.OverwriteExistingFile = true; FamDoc.SaveAs(familyFileName, opt); FamDoc.Close(false); return(success); }