/// <summary> /// Construct a Revit Form from an existing form. /// </summary> /// <param name="form"></param> private Form(Autodesk.Revit.DB.Form form) { InternalSetForm(form); }
private void InternalSetForm(Autodesk.Revit.DB.Form form) { this.InternalForm = form; this.InternalElementId = form.Id; this.InternalUniqueId = form.UniqueId; }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { ExternalCommandData cdata = commandData; Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application; app = commandData.Application.Application; Document doc = commandData.Application.ActiveUIDocument.Document; Transaction transaction = new Transaction(doc, "MakeSweptBlendForm"); transaction.Start(); // Create first profile ReferenceArray ref_ar = new ReferenceArray(); Autodesk.Revit.DB.XYZ ptA = new Autodesk.Revit.DB.XYZ(10, 10, 0); Autodesk.Revit.DB.XYZ ptB = new Autodesk.Revit.DB.XYZ(50, 10, 0); ModelCurve modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB); ref_ar.Append(modelcurve.GeometryCurve.Reference); ptA = new Autodesk.Revit.DB.XYZ(50, 10, 0); ptB = new Autodesk.Revit.DB.XYZ(10, 50, 0); modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB); ref_ar.Append(modelcurve.GeometryCurve.Reference); ptA = new Autodesk.Revit.DB.XYZ(10, 50, 0); ptB = new Autodesk.Revit.DB.XYZ(10, 10, 0); modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB); ref_ar.Append(modelcurve.GeometryCurve.Reference); // Create second profile ReferenceArray ref_ar2 = new ReferenceArray(); ptA = new Autodesk.Revit.DB.XYZ(10, 10, 90); ptB = new Autodesk.Revit.DB.XYZ(80, 10, 90); modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB); ref_ar2.Append(modelcurve.GeometryCurve.Reference); ptA = new Autodesk.Revit.DB.XYZ(80, 10, 90); ptB = new Autodesk.Revit.DB.XYZ(10, 50, 90); modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB); ref_ar2.Append(modelcurve.GeometryCurve.Reference); ptA = new Autodesk.Revit.DB.XYZ(10, 50, 90); ptB = new Autodesk.Revit.DB.XYZ(10, 10, 90); modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB); ref_ar2.Append(modelcurve.GeometryCurve.Reference); // Add profiles ReferenceArrayArray profiles = new ReferenceArrayArray(); profiles.Append(ref_ar); profiles.Append(ref_ar2); // Create path for swept blend form ReferenceArray path = new ReferenceArray(); ptA = new Autodesk.Revit.DB.XYZ(10, 10, 0); ptB = new Autodesk.Revit.DB.XYZ(10, 10, 90); modelcurve = FormUtils.MakeLine(commandData.Application, ptA, ptB); path.Append(modelcurve.GeometryCurve.Reference); Autodesk.Revit.DB.Form form = doc.FamilyCreate.NewSweptBlendForm(true, path, profiles); transaction.Commit(); return(Autodesk.Revit.UI.Result.Succeeded); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { ExternalCommandData cdata = commandData; Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application; app = commandData.Application.Application; Document doc = commandData.Application.ActiveUIDocument.Document; Transaction transaction = new Transaction(doc, "MakeLoftForm"); transaction.Start(); // Create profiles array ReferenceArrayArray ref_ar_ar = new ReferenceArrayArray(); // Create first profile ReferenceArray ref_ar = new ReferenceArray(); int y = 100; int x = 50; Autodesk.Revit.DB.XYZ ptA = new Autodesk.Revit.DB.XYZ(-x, y, 0); Autodesk.Revit.DB.XYZ ptB = new Autodesk.Revit.DB.XYZ(x, y, 0); Autodesk.Revit.DB.XYZ ptC = new Autodesk.Revit.DB.XYZ(0, y + 10, 10); ModelCurve modelcurve = FormUtils.MakeArc(commandData.Application, ptA, ptB, ptC); ref_ar.Append(modelcurve.GeometryCurve.Reference); ref_ar_ar.Append(ref_ar); // Create second profile ref_ar = new ReferenceArray(); y = 40; ptA = new Autodesk.Revit.DB.XYZ(-x, y, 5); ptB = new Autodesk.Revit.DB.XYZ(x, y, 5); ptC = new Autodesk.Revit.DB.XYZ(0, y, 25); modelcurve = FormUtils.MakeArc(commandData.Application, ptA, ptB, ptC); ref_ar.Append(modelcurve.GeometryCurve.Reference); ref_ar_ar.Append(ref_ar); // Create third profile ref_ar = new ReferenceArray(); y = -20; ptA = new Autodesk.Revit.DB.XYZ(-x, y, 0); ptB = new Autodesk.Revit.DB.XYZ(x, y, 0); ptC = new Autodesk.Revit.DB.XYZ(0, y, 15); modelcurve = FormUtils.MakeArc(commandData.Application, ptA, ptB, ptC); ref_ar.Append(modelcurve.GeometryCurve.Reference); ref_ar_ar.Append(ref_ar); // Create fourth profile ref_ar = new ReferenceArray(); y = -60; ptA = new Autodesk.Revit.DB.XYZ(-x, y, 0); ptB = new Autodesk.Revit.DB.XYZ(x, y, 0); ptC = new Autodesk.Revit.DB.XYZ(0, y + 10, 20); modelcurve = FormUtils.MakeArc(commandData.Application, ptA, ptB, ptC); ref_ar.Append(modelcurve.GeometryCurve.Reference); ref_ar_ar.Append(ref_ar); ref_ar = new ReferenceArray(); ref_ar_ar.Append(ref_ar); Autodesk.Revit.DB.Form form = doc.FamilyCreate.NewLoftForm(true, ref_ar_ar); transaction.Commit(); return(Autodesk.Revit.UI.Result.Succeeded); }
//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); }
public static Form Wrap(Autodesk.Revit.DB.Form ele, bool isRevitOwned) { return(Form.FromExisting(ele, isRevitOwned)); }
/// <summary> /// Construct a Revit Form from an existing form. /// </summary> /// <param name="form"></param> private Form(Autodesk.Revit.DB.Form form) { SafeInit(() => InitForm(form)); }
private bool CreateExtrusion(Document fdoc, FloorProperties fp) { bool result = false; try { if (true == fdoc.IsFamilyDocument) { double maxCircum = 0;//to find out the largest outer loop. List <ReferenceArray> profiles = new List <ReferenceArray>(); foreach (EdgeArray edgeArray in fp.EdgeArrayArray) { Curve curve = null; List <XYZ> pointList = new List <XYZ>(); ReferenceArray refArray = new ReferenceArray(); bool first = true; double circumference = 0; foreach (Edge edge in edgeArray) { circumference += edge.ApproximateLength; int pointCount = edge.Tessellate().Count; if (pointCount > 2)//edge from a circular face { IList <XYZ> tPoints = edge.Tessellate(); tPoints.RemoveAt(tPoints.Count - 1); foreach (XYZ point in tPoints) { XYZ tempPoint = new XYZ(point.X, point.Y, 0); pointList.Add(tempPoint); } } else if (pointCount == 2) { curve = edge.AsCurve(); #if RELEASE2013 XYZ point = curve.get_EndPoint(0); #elif RELEASE2014 || RELEASE2015 || RELEASE2016 XYZ point = curve.GetEndPoint(0); #endif XYZ tempPoint = new XYZ(point.X, point.Y, 0); if (first) { pointList.Add(tempPoint); first = false; } else if (pointList[pointList.Count - 1].DistanceTo(tempPoint) > 0.0026) { pointList.Add(tempPoint); } } } if (maxCircum == 0) { maxCircum = circumference; } else if (maxCircum < circumference) { maxCircum = circumference; } int num = pointList.Count; if (num > 0) { Plane plane = fdoc.Application.Create.NewPlane(XYZ.BasisZ, new XYZ(0, 0, 0)); #if RELEASE2013 SketchPlane skPlane = fdoc.FamilyCreate.NewSketchPlane(plane); #elif RELEASE2014 || RELEASE2015 || RELEASE2016 SketchPlane skPlane = SketchPlane.Create(fdoc, plane); #endif for (int i = 0; i < num; i++) { if (i == num - 1) { #if RELEASE2013 curve = fdoc.Application.Create.NewLineBound(pointList[i], pointList[0]); #elif RELEASE2014 || RELEASE2015 || RELEASE2016 curve = Autodesk.Revit.DB.Line.CreateBound(pointList[i], pointList[0]); #endif } else { #if RELEASE2013 curve = fdoc.Application.Create.NewLineBound(pointList[i], pointList[i + 1]); #elif RELEASE2014 || RELEASE2015 || RELEASE2016 curve = Autodesk.Revit.DB.Line.CreateBound(pointList[i], pointList[i + 1]); #endif } ModelCurve modelCurve = fdoc.FamilyCreate.NewModelCurve(curve, skPlane); refArray.Append(modelCurve.GeometryCurve.Reference); } //first index of profile list will be the outer loop if (maxCircum == circumference) { profiles.Insert(0, refArray); } else { profiles.Add(refArray); } } } if (profiles.Count > 0) { XYZ direction = new XYZ(0, 0, fp.Height); FamilyParameter fparam = fdoc.FamilyManager.get_Parameter("Height"); fdoc.FamilyManager.Set(fparam, fp.Height); for (int i = 0; i < profiles.Count; i++) { Autodesk.Revit.DB.Form solidForm = fdoc.FamilyCreate.NewExtrusionForm(true, profiles[i], direction); CreateHeightLabel(fdoc, solidForm); if (i > 0) { Parameter param = solidForm.get_Parameter(BuiltInParameter.ELEMENT_IS_CUTTING); param.Set(1); //void form } } } result = true; } else { result = false; throw new Exception("Please open a Family document before invoking this command."); } return(result); } catch (Exception ex) { result = false; MessageBox.Show("Failed to create an extruded form.\n\nFloorName: " + fp.TypeName + " FloorLevel: " + fp.Level + "\nBoundary lines of floor cannot create a profile..\n\n" + ex.Message, "MassCreator: CreateExtrusion", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(result); } }