/// <summary> /// Generate a volume of a given width /// </summary> /// <param name="model">The input model.</param> /// <param name="input">The arguments to the execution.</param> /// <returns>A EnvolopeByPolylineOutputs instance containing computed results and the model with any new elements.</returns> public static EnvolopeByPolylineOutputs Execute(Dictionary <string, Model> inputModels, EnvolopeByPolylineInputs input) { Polyline polyline = input.BuildingAxis; if (polyline == null) { throw new ArgumentException("Please draw the axe of the building."); } Polygon perimeter = input.BuildingAxis.Offset(input.BuildingWidth / 2, EndType.Butt).First(); var envMatl = new Material("envelope", new Color(0.3, 0.7, 0.7, 0.6), 0.0f, 0.0f); var envelopes = new List <Envelope>(); // Create the Envelope at the location's zero plane. var output = new EnvolopeByPolylineOutputs(perimeter.ToPolyline().Length() * input.BuildingHeight, perimeter.Area()); var extrude = new Elements.Geometry.Solids.Extrude(perimeter, input.BuildingHeight, Vector3.ZAxis, false); var geomRep = new Representation(new List <Elements.Geometry.Solids.SolidOperation>() { extrude }); envelopes.Add(new Envelope(perimeter, 0.0, input.BuildingHeight, Vector3.ZAxis, 0.0, new Transform(), envMatl, geomRep, false, Guid.NewGuid(), "")); output.Model.AddElements(envelopes); var sketch = new ModelCurve(polyline, name: "Centerline Sketch"); output.Model.AddElement(sketch); return(output); }
public static void DrawCircle(UIDocument ui_doc, XYZ CenterPoint, double radius, XYZ Normal) { Plane plane = Plane.CreateByNormalAndOrigin(Normal, CenterPoint); SketchPlane skplane = SketchPlane.Create(ui_doc.Document, plane); Arc arc = Arc.Create(plane, radius, 0.0F, 2 * 22 / 7.0); ModelCurve mc = ui_doc.Document.Create.NewModelCurve(arc, skplane); }
/// <summary> /// Get all selected lines and arcs /// </summary> /// <param name="document">Revit's document</param> /// <returns>CurveArray contains all selected lines and arcs</returns> private CurveArray GetSelectedCurves(ThisDocument document) { CurveArray selectedCurves = m_doc.Document.Application.Create.NewCurveArray(); ElementSet elements = new ElementSet(); foreach (var elementid in document.Selection.GetElementIds()) { elements.Insert(m_doc.Document.GetElement(elementid)); } foreach (Autodesk.Revit.DB.Element element in elements) { if ((element is ModelLine) || (element is ModelArc)) { ModelCurve modelCurve = element as ModelCurve; Curve curve = modelCurve.GeometryCurve; if (curve != null) { selectedCurves.Append(curve); } } else if ((element is DetailLine) || (element is DetailArc)) { DetailCurve detailCurve = element as DetailCurve; Curve curve = detailCurve.GeometryCurve; if (curve != null) { selectedCurves.Append(curve); } } } return(selectedCurves); }
/// <summary> /// Tessellate the curves of path reinforcement. /// </summary> private void Tessellate() { Options option = new Options(); option.DetailLevel = ViewDetailLevel.Fine; Autodesk.Revit.DB.GeometryElement geoElem = m_pathRein.get_Geometry(option); //GeometryObjectArray geoArray = geoElem.Objects; IEnumerator <GeometryObject> Objects = geoElem.GetEnumerator(); //foreach (GeometryObject geo in geoArray) while (Objects.MoveNext()) { GeometryObject geo = Objects.Current; if (geo is Curve) { Curve curve = geo as Curve; m_curves.Add(curve.Tessellate() as List <XYZ>); } } IList <ElementId> curveIds = m_pathRein.GetCurveElementIds(); foreach (ElementId id in curveIds) { ModelCurve modelCurve = m_commandData.Application.ActiveUIDocument.Document.GetElement(id) as ModelCurve; m_path.Add(modelCurve.GeometryCurve.Tessellate() as List <XYZ>); } }
public Dimension CreateLinearDimension( Document doc) { Application app = doc.Application; // first create two lines XYZ pt1 = new XYZ(5, 5, 0); XYZ pt2 = new XYZ(5, 10, 0); Line line = Line.CreateBound(pt1, pt2); //Plane plane = app.Create.NewPlane( pt1.CrossProduct( pt2 ), pt2 ); // 2016 Plane plane = Plane.CreateByNormalAndOrigin(pt1.CrossProduct(pt2), pt2); // 2017 //SketchPlane skplane = doc.FamilyCreate.NewSketchPlane( plane ); // 2013 SketchPlane skplane = SketchPlane.Create(doc, plane); // 2014 ModelCurve modelcurve1 = doc.FamilyCreate .NewModelCurve(line, skplane); pt1 = new XYZ(10, 5, 0); pt2 = new XYZ(10, 10, 0); line = Line.CreateBound(pt1, pt2); //plane = app.Create.NewPlane( pt1.CrossProduct( pt2 ), pt2 ); // 2016 plane = Plane.CreateByNormalAndOrigin(pt1.CrossProduct(pt2), pt2); // 2017 //skplane = doc.FamilyCreate.NewSketchPlane( plane ); // 2013 skplane = SketchPlane.Create(doc, plane); // 2014 ModelCurve modelcurve2 = doc.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, 10, 0); pt2 = new XYZ(10, 10, 0); line = Line.CreateBound(pt1, pt2); Dimension dim = doc.FamilyCreate .NewLinearDimension(doc.ActiveView, line, ra); // create a label for the dimension called "width" FamilyParameter param = doc.FamilyManager .AddParameter("width", BuiltInParameterGroup.PG_CONSTRAINTS, ParameterType.Length, false); //dim.Label = param; // 2013 dim.FamilyLabel = param; // 2014 return(dim); }
/// <summary> /// Make a line from start point to end point with the direction and style /// </summary> /// <param name="startpt">start point</param> /// <param name="endpt">end point</param> /// <param name="direction">the direction which decide the plane</param> /// <param name="style">line style name</param> public void MakeLine(Autodesk.Revit.DB.XYZ startpt, Autodesk.Revit.DB.XYZ endpt, Autodesk.Revit.DB.XYZ direction, string style) { try { m_LineCount = m_LineCount + 1; Line line = m_app.Application.Create.NewLineBound(startpt, endpt); // Line must lie in the sketch plane. Use the direction of the line to construct a plane that hosts the target line. XYZ rotatedDirection = XYZ.BasisX; // If the direction is not vertical, cross the direction vector with Z to get a vector rotated ninety degrees. That vector, // plus the original vector, form the axes of the sketch plane. if (!direction.IsAlmostEqualTo(XYZ.BasisZ) && !direction.IsAlmostEqualTo(-XYZ.BasisZ)) { rotatedDirection = direction.Normalize().CrossProduct(XYZ.BasisZ); } Plane geometryPlane = m_app.Application.Create.NewPlane(direction, rotatedDirection, startpt); SketchPlane skplane = m_app.ActiveUIDocument.Document.Create.NewSketchPlane(geometryPlane); ModelCurve mcurve = m_app.ActiveUIDocument.Document.Create.NewModelCurve(line, skplane); m_app.ActiveUIDocument.Document.Regenerate(); ElementArray lsArr = mcurve.LineStyles; foreach (Autodesk.Revit.DB.Element e in lsArr) { if (e.Name == style) { mcurve.LineStyle = e; break; } } m_app.ActiveUIDocument.Document.Regenerate(); } catch (System.Exception ex) { m_outputInfo.Add("Failed to create lines: " + ex.ToString()); } }
private void lineCiz(List <XYZ> vertexList) { try { if (vertexList.Count > 1) { for (int i = 0; i < vertexList.Count - 1; i++) { XYZ v1 = vertexList[i]; XYZ v2 = vertexList[i + 1]; XYZ normal = new XYZ(0, 0, 1); using (Transaction tr = new Transaction(doc, "Yüzey Çiz")) { tr.Start(); Plane plane = Plane.CreateByNormalAndOrigin(normal, v1); SketchPlane sketchPlane = SketchPlane.Create(doc, plane); Line line = Line.CreateBound(vertexList[i], vertexList[i + 1]); ModelCurve ml = doc.Create.NewModelCurve(line, sketchPlane); GraphicsStyle gs = ml.LineStyle as GraphicsStyle; gs.GraphicsStyleCategory.LineColor = new Autodesk.Revit.DB.Color(255, 10, 10); tr.Commit(); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void UpdateGeometry(List <object> geomObjs) { if (geomObjs.Count != _previousIds.Count || geomObjs.Count != _previousRefs.Count) { throw new InvalidOperationException("Cannot update geometry, counts dont match"); } Transaction trans = new Transaction(_document); trans.Start("pipe_pull_update"); for (int i = 0; i < geomObjs.Count; i++) { Element elem = _document.GetElement(_previousIds[i]); GeometryObject oldGeom = elem.GetGeometryObjectFromReference(_previousRefs[i]); if (oldGeom.GetType() != geomObjs[i].GetType()) { continue; } if (typeof(ModelCurve).IsAssignableFrom(elem.GetType()) && typeof(Curve).IsAssignableFrom(geomObjs[i].GetType())) { ModelCurve curveElem = (ModelCurve)elem; curveElem.SetGeometryCurve((Curve)geomObjs[i], true); } } trans.Commit(); }
public void ByPointsOnCurve_ValidInput() { // create spline var pts = new Autodesk.DesignScript.Geometry.Point[] { Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(1, 0, 0), Point.ByCoordinates(3, 0, 0), Point.ByCoordinates(10, 0, 0), Point.ByCoordinates(12, 0, 0), }; var spline = NurbsCurve.ByControlPoints(pts, 3); Assert.NotNull(spline); // build model curve from spline var modCurve = ModelCurve.ByCurve(spline); Assert.NotNull(modCurve); // obtain the family from the document var fs = FamilySymbol.ByName("3PointAC"); // build the AC var parms = new double[] { 0, 0.5, 1 }; var ac = AdaptiveComponent.ByParametersOnCurveReference(parms, modCurve.ElementCurveReference, fs); Assert.NotNull(ac); }
private Form CreateExtrusionForm(Autodesk.Revit.DB.Document massFamilyDocument) { Form extrusionForm = null; // Create one profile ReferenceArray ref_ar = new ReferenceArray(); XYZ ptA = new XYZ(10, 10, 0); XYZ ptB = new XYZ(90, 10, 0); ModelCurve modelcurve = MakeLine(massFamilyDocument, ptA, ptB); ref_ar.Append(modelcurve.GeometryCurve.Reference); ptA = new XYZ(90, 10, 0); ptB = new XYZ(10, 90, 0); modelcurve = MakeLine(massFamilyDocument, ptA, ptB); ref_ar.Append(modelcurve.GeometryCurve.Reference); ptA = new XYZ(10, 90, 0); ptB = new XYZ(10, 10, 0); modelcurve = MakeLine(massFamilyDocument, ptA, ptB); ref_ar.Append(modelcurve.GeometryCurve.Reference); // The extrusion form direction XYZ direction = new XYZ(0, 0, 50); extrusionForm = massFamilyDocument.FamilyCreate.NewExtrusionForm(true, ref_ar, direction); int profileCount = extrusionForm.ProfileCount; return(extrusionForm); }
public void ModelCurve() { this.Name = "Elements_ModelCurve"; // <example> // A line var line = new Line(Vector3.Origin, new Vector3(5, 5, 5)); // An arc var arc = new Arc(Vector3.Origin, 2.0, 45.0, 135.0); // A polygon var pline = Polygon.L(2, 2, 0.5); // A Bezier var a = Vector3.Origin; var b = new Vector3(5, 0, 1); var c = new Vector3(5, 5, 2); var d = new Vector3(0, 5, 3); var e = new Vector3(0, 0, 4); var f = new Vector3(5, 0, 5); var ctrlPts = new List <Vector3> { a, b, c, d, e, f }; var bezier = new Bezier(ctrlPts); var lineModelCurve = new ModelCurve(line, new Material("Red", Colors.Red)); var arcModelCurve = new ModelCurve(arc, new Material("Orange", Colors.Orange), new Transform(5, 0, 0)); var plineModelCurve = new ModelCurve(pline, new Material("Purple", Colors.Purple), new Transform(10, 0, 0)); var bezierModelCurve = new ModelCurve(bezier, new Material("Green", Colors.Green), new Transform(15, 0, 0)); // </example> this.Model.AddElements(new[] { lineModelCurve, arcModelCurve, plineModelCurve, bezierModelCurve }); }
/// <summary> /// Get all selected lines and arcs /// </summary> /// <param name="document">Revit's document</param> /// <returns>CurveArray contains all selected lines and arcs</returns> private static CurveArray GetSelectedCurves(Document document) { CurveArray selectedCurves = new CurveArray(); UIDocument newUIdocument = new UIDocument(document); ElementSet elements = new ElementSet(); foreach (ElementId elementId in newUIdocument.Selection.GetElementIds()) { elements.Insert(newUIdocument.Document.GetElement(elementId)); } foreach (Autodesk.Revit.DB.Element element in elements) { if ((element is ModelLine) || (element is ModelArc)) { ModelCurve modelCurve = element as ModelCurve; Curve curve = modelCurve.GeometryCurve; if (curve != null) { selectedCurves.Append(curve); } } else if ((element is DetailLine) || (element is DetailArc)) { DetailCurve detailCurve = element as DetailCurve; Curve curve = detailCurve.GeometryCurve; if (curve != null) { selectedCurves.Append(curve); } } } return(selectedCurves); }
/// <summary> /// /// </summary> /// <param name="app"></param> /// <param name="modelCurve"></param> /// <returns></returns> private static Revit.Element CloneElement(Autodesk.Revit.UI.UIApplication app, ModelCurve modelCurve) { ModelCurve modelCurveClone = app.ActiveUIDocument.Document.Create.NewModelCurve(modelCurve.GeometryCurve, modelCurve.SketchPlane); Utils.ParamUtil.SetParameters(modelCurveClone.Parameters, modelCurve.Parameters); return(modelCurveClone); }
/// <summary> /// Create a rectangle profile with provided length, width and height /// </summary> /// <param name="length">Length of the rectangle</param> /// <param name="width">Width of the rectangle</param> /// <param name="height">Height of the profile</param> /// <returns>The created profile</returns> private ReferenceArray CreateProfile(double length, double width, double height) { ReferenceArray profile = new ReferenceArray(); // Prepare points to create lines List <XYZ> points = new List <XYZ>(); points.Add(new Autodesk.Revit.DB.XYZ(-1 * length / 2, -1 * width / 2, height)); points.Add(new Autodesk.Revit.DB.XYZ(length / 2, -1 * width / 2, height)); points.Add(new Autodesk.Revit.DB.XYZ(length / 2, width / 2, height)); points.Add(new Autodesk.Revit.DB.XYZ(-1 * length / 2, width / 2, height)); // Prepare sketch plane to create model line Autodesk.Revit.DB.XYZ normal = new Autodesk.Revit.DB.XYZ(0, 0, 1); Autodesk.Revit.DB.XYZ origin = new Autodesk.Revit.DB.XYZ(0, 0, height); Plane geometryPlane = m_revitApp.Create.NewPlane(normal, origin); SketchPlane sketchPlane = SketchPlane.Create(m_revitDoc, geometryPlane); // Create model lines and get their references as the profile for (int i = 0; i < 4; i++) { Autodesk.Revit.DB.XYZ startPoint = points[i]; Autodesk.Revit.DB.XYZ endPoint = (i == 3 ? points[0] : points[i + 1]); Line line = Line.CreateBound(startPoint, endPoint); ModelCurve modelLine = m_revitDoc.FamilyCreate.NewModelCurve(line, sketchPlane); profile.Append(modelLine.GeometryCurve.Reference); } return(profile); }
public ModelCurveArray MakeModelCurve(BoundingBoxXYZ bb) { ModelCurveArray array = new ModelCurveArray(); XYZ p1 = bb.Min; XYZ p2 = bb.Max; XYZ[][] pairs = { new XYZ[] { new XYZ(p1.X, p1.Y, p1.Z), new XYZ(p2.X, p1.Y, p1.Z) }, new XYZ[] { new XYZ(p2.X, p2.Y, p1.Z), new XYZ(p2.X, p1.Y, p1.Z) }, new XYZ[] { new XYZ(p2.X, p2.Y, p1.Z), new XYZ(p1.X, p2.Y, p1.Z) }, new XYZ[] { new XYZ(p1.X, p1.Y, p1.Z), new XYZ(p1.X, p2.Y, p1.Z) }, new XYZ[] { new XYZ(p1.X, p1.Y, p2.Z), new XYZ(p2.X, p1.Y, p2.Z) }, new XYZ[] { new XYZ(p2.X, p2.Y, p2.Z), new XYZ(p2.X, p1.Y, p2.Z) }, new XYZ[] { new XYZ(p2.X, p2.Y, p2.Z), new XYZ(p1.X, p2.Y, p2.Z) }, new XYZ[] { new XYZ(p1.X, p1.Y, p2.Z), new XYZ(p1.X, p2.Y, p2.Z) }, new XYZ[] { new XYZ(p1.X, p1.Y, p1.Z), new XYZ(p1.X, p1.Y, p2.Z) }, new XYZ[] { new XYZ(p2.X, p1.Y, p1.Z), new XYZ(p2.X, p1.Y, p2.Z) }, new XYZ[] { new XYZ(p2.X, p2.Y, p1.Z), new XYZ(p2.X, p2.Y, p2.Z) }, new XYZ[] { new XYZ(p1.X, p2.Y, p1.Z), new XYZ(p1.X, p2.Y, p2.Z) } }; foreach (var pair in pairs) { ModelCurve modelCurve = MakeModelCurve(pair[0], pair[1]); array.Append(modelCurve); } return(array); }
//public Result OnStartup(Autodesk.Revit.UI.UIControlledApplication application) //{ // ElementUpdater updater = new ElementUpdater(application.ActiveAddInId); // UpdaterRegistry.RegisterUpdater(updater); // ElementClassFilter elementFilter = new ElementClassFilter(typeof(Element)); // UpdaterRegistry.AddTrigger(updater.getUpdaterId(), elementFilter, Element.GetChangeTypeParameter()); // return Result.Succeeded; //} //public Result OnShutdown(Autodesk.Revit.UI.UIControlledApplication application) //{ // return Result.Succeeded; //} void GetStyles(ref Element dynVolatileStyle, ref Element dynPersistentStyle, ref Element dynXStyle, ref Element dynYStyle, ref Element dynZStyle) { Curve tick = m_revit.Application.Create.NewLineBound(new XYZ(), new XYZ(0, 1, 0)); Plane p = new Plane(new XYZ(0, 0, 1), new XYZ()); SketchPlane sp = m_doc.Document.Create.NewSketchPlane(p); ModelCurve ml = m_doc.Document.Create.NewModelCurve(tick, sp); ElementArray styles = ml.LineStyles; ElementArrayIterator styleIter = styles.ForwardIterator(); while (styleIter.MoveNext()) { Element style = styleIter.Current as Element; if (style.Name == "dynVolatile") { dynVolatileStyle = style; } else if (style.Name == "dynPersistent") { dynPersistentStyle = style; } else if (style.Name == "dynX") { dynXStyle = style; } else if (style.Name == "dynY") { dynYStyle = style; } else if (style.Name == "dynZ") { dynZStyle = style; } } }
/// <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 Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application; Document doc = commandData.Application.ActiveUIDocument.Document; Transaction transaction = new Transaction(doc, "PointsOnCurve"); transaction.Start(); XYZ start = new XYZ(0, 0, 0); XYZ end = new XYZ(50, 50, 0); Autodesk.Revit.DB.Line line = Autodesk.Revit.DB.Line.CreateBound(start, end); Plane geometryPlane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, start); SketchPlane skplane = SketchPlane.Create(doc, geometryPlane); ModelCurve modelcurve = doc.FamilyCreate.NewModelCurve(line, skplane); for (double i = 0.1; i <= 1; i = i + 0.1) { PointLocationOnCurve locationOnCurve = new PointLocationOnCurve(PointOnCurveMeasurementType.NormalizedCurveParameter, i, PointOnCurveMeasureFrom.Beginning); PointOnEdge poe = app.Create.NewPointOnEdge(modelcurve.GeometryCurve.Reference, locationOnCurve); ReferencePoint rp2 = doc.FamilyCreate.NewReferencePoint(poe); } transaction.Commit(); return(Result.Succeeded); }
public void Setbacks() { this.Name = "BeamSetbacks"; var line = new Line(Vector3.Origin, new Vector3(3, 3, 0)); var mc = new ModelCurve(line, BuiltInMaterials.XAxis); this.Model.AddElement(mc); // Normal setbacks var beam = new Beam(line, this._testProfile, BuiltInMaterials.Steel, 2.0, 2.0); this.Model.AddElement(beam); var line1 = new Line(new Vector3(2, 0, 0), new Vector3(5, 3, 0)); var mc1 = new ModelCurve(line1, BuiltInMaterials.XAxis); this.Model.AddElement(mc1); var sb = line1.Length() / 2; // Setbacks longer in total than the beam. // We are testing to ensure that the beam gets created // without throwing. It will not have setbacks. var beam1 = new Beam(line1, this._testProfile, BuiltInMaterials.Steel, sb, sb); this.Model.AddElement(beam1); }
/// <summary> /// Delete all unnecessary lines /// </summary> public void DeleteLines() { int delLineNum = 0; try { SubTransaction transaction = new SubTransaction(m_app.ActiveUIDocument.Document); transaction.Start(); List <Autodesk.Revit.DB.Element> list = new List <Autodesk.Revit.DB.Element>(); ElementClassFilter filter = new ElementClassFilter(typeof(Autodesk.Revit.DB.CurveElement)); FilteredElementCollector collector = new FilteredElementCollector(m_app.ActiveUIDocument.Document); list.AddRange(collector.WherePasses(filter).ToElements()); foreach (Autodesk.Revit.DB.Element e in list) { ModelCurve mc = e as ModelCurve; if (mc != null) { if (mc.LineStyle.Name == "bounce" || mc.LineStyle.Name == "normal") { m_app.ActiveUIDocument.Document.Delete(e.Id); delLineNum++; } } } transaction.Commit(); } catch (System.Exception) { } }
public void ByCurveAndEqualDivisions_ValidArgs() { // create spline var pts = new[] { Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(1, 0, 0), Point.ByCoordinates(3, 0, 0), Point.ByCoordinates(10, 0, 0), Point.ByCoordinates(12, 0, 0) }; var spline = NurbsCurve.ByControlPoints(pts, 3); Assert.NotNull(spline); // build model curve from spline var modCurve = ModelCurve.ByCurve(spline); Assert.NotNull(modCurve); // build dividedPath var divPath = DividedPath.ByCurveAndDivisions(modCurve.ElementCurveReference, 5); Assert.NotNull(divPath); }
private ModelCurve DrawLine(Document doc, XYZ point1, XYZ point2) { Line ln = Line.CreateBound(point1, point2); XYZ p3; if (ln.Direction.Z != 1) { p3 = new XYZ(point1.X, point1.Y, point1.Z + 1); } else { p3 = new XYZ(point1.X + 2, point1.Y, point1.Z); } Plane pl = Plane.CreateByThreePoints(point1, point2, p3); SketchPlane sk = SketchPlane.Create(doc, pl); if (doc.IsFamilyDocument) { ModelCurve ml = doc.FamilyCreate.NewModelCurve(ln, sk); return(ml); } else { ModelCurve ml = doc.Create.NewModelCurve(ln, sk); return(ml); } }
public void Points() { // create spline var pts = new[] { Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(1, 0, 0), Point.ByCoordinates(3, 0, 0), Point.ByCoordinates(10, 0, 0), Point.ByCoordinates(12, 0, 0) }; var spline = NurbsCurve.ByControlPoints(pts, 3); Assert.NotNull(spline); // build model curve from spline var modCurve = ModelCurve.ByCurve(spline); Assert.NotNull(modCurve); // build dividedPath var divPath = DividedPath.ByCurveAndDivisions(modCurve.ElementCurveReference, 5); Assert.NotNull(divPath); foreach (var pt in divPath.Points) { Assert.IsTrue(pts.Any(x => x.ShouldBeApproximately(pt))); } }
public Dimension CreateLinearDimension(Document doc) { Autodesk.Revit.ApplicationServices.Application app = doc.Application; XYZ pt1 = new XYZ(5, 5, 0); XYZ pt2 = new XYZ(5, 10, 0); Line line = Line.CreateUnbound(pt1, pt2); Plane plane = Plane.CreateByNormalAndOrigin(pt1.CrossProduct(pt2), pt2); SketchPlane skPlane = SketchPlane.Create(doc, plane); ModelCurve modelCurveA = doc.FamilyCreate.NewModelCurve(line, skPlane); pt1 = new XYZ(10, 5, 0); pt2 = new XYZ(10, 10, 0); line = Line.CreateUnbound(pt1, pt2); plane = Plane.CreateByNormalAndOrigin(pt1.CrossProduct(pt2), pt2); skPlane = SketchPlane.Create(doc, plane); ModelCurve modelCurveB = doc.FamilyCreate.NewModelCurve(line, skPlane); ReferenceArray refArr = new ReferenceArray(); refArr.Append(modelCurveA.GeometryCurve.Reference); refArr.Append(modelCurveB.GeometryCurve.Reference); pt1 = new XYZ(5, 10, 0); pt2 = new XYZ(10, 10, 0); line = Line.CreateUnbound(pt1, pt2); Dimension dim = doc.FamilyCreate.NewLinearDimension(doc.ActiveView, line, refArr); FamilyParameter param = doc.FamilyManager.AddParameter("width", BuiltInParameterGroup.PG_CONSTRAINTS, ParameterType.Length, false); dim.FamilyLabel = param; return(dim); }
/// <summary> /// Gets a ReferenceArray representing the polygon /// </summary> /// <param name="document">The document in which the ReferenceArray is going to be generated</param> /// <param name="height">A desired plane that is determined by a Z value</param> /// <returns>Returns a ReferenceArray that might be null especifically the polygon is not closed</returns> public ReferenceArray Get_ReferenceArray(Document document, XYZ translation) { ReferenceArray refAr = null; using (Transaction createReferenceArray = new Transaction(document)) { FailureHandlingOptions failOpt = createReferenceArray.GetFailureHandlingOptions(); failOpt.SetFailuresPreprocessor(new WarningSwallower()); createReferenceArray.SetFailureHandlingOptions(failOpt); createReferenceArray.Start("Create ReferenceArray"); refAr = new ReferenceArray(); Plane p = new Plane(XYZ.BasisZ, new XYZ(this.processedPolygon[0].X, this.processedPolygon[0].Y, 0)); SketchPlane skp = SketchPlane.Create(document, p); try { for (int i = 0; i < this.processedPolygon.Count; i++) { int j = (i == this.processedPolygon.Count - 1) ? 0 : i + 1; XYZ ptA = this.processedPolygon[i] - translation; XYZ PtB = this.processedPolygon[j] - translation; Line l = Line.CreateBound(ptA, PtB); ModelCurve mCrv = document.FamilyCreate.NewModelCurve(l, skp); refAr.Append(mCrv.GeometryCurve.Reference); } } catch (Exception) { createReferenceArray.Commit(); return(null); } createReferenceArray.Commit(); } return(refAr); }
public static Curve RequestModelCurveSelection(UIDocument doc, string message, dynElementSettings settings) { try { ModelCurve c = null; Curve cv = null; Selection choices = doc.Selection; choices.Elements.Clear(); //MessageBox.Show(message); dynElementSettings.SharedInstance.Bench.Log(message); Reference curveRef = doc.Selection.PickObject(ObjectType.Element); //c = curveRef.Element as ModelCurve; c = dynElementSettings.SharedInstance.Revit.ActiveUIDocument.Document.GetElement(curveRef) as ModelCurve; if (c != null) { cv = c.GeometryCurve; } return(cv); } catch (Exception ex) { settings.Bench.Log(ex.Message); return(null); } }
public void OffsetModelCurves() { this.Name = "OffsetModelCurves"; var pline = new Polygon(new[] { new Vector3(0, 0), new Vector3(20, -10), new Vector3(25, 5), new Vector3(15, 3), new Vector3(20, 20), new Vector3(5, 19), new Vector3(0, 15) }); var mcs = new List <ModelCurve>(); var m = new Material("Purple", Colors.Blue); var plineModelCurve = new ModelCurve(pline, m); mcs.Add(plineModelCurve); var distance = -0.2; for (var i = 0; i < 100; i++) { mcs.AddRange(OffsetPolygon(distance, pline, m)); } this.Model.AddElements(mcs); }
public void createALinearDimensionFamilyEditor() { UIDocument uiDoc = this.ActiveUIDocument; Document doc = uiDoc.Document; using (Transaction trans = new Transaction(doc, "Create linear Dimension")) { trans.Start(); XYZ pt1 = new XYZ(5, 5, 0); XYZ pt2 = new XYZ(5, 10, 0); Line line = Line.CreateBound(pt1, pt2); Plane plane = Plane.CreateByNormalAndOrigin(pt1.CrossProduct(pt2), pt2); SketchPlane skPlane = SketchPlane.Create(doc, plane); ModelCurve modelCurve1 = doc.FamilyCreate.NewModelCurve(line, skPlane); pt1 = new XYZ(10, 5, 0); pt2 = new XYZ(10, 10, 0); line = Line.CreateBound(pt1, pt2); plane = Plane.CreateByNormalAndOrigin(pt1.CrossProduct(pt2), pt2); skPlane = SketchPlane.Create(doc, plane); ModelCurve modelCurve2 = doc.FamilyCreate.NewModelCurve(line, skPlane); // Create a linear dimension between them ReferenceArray ra = new ReferenceArray(); ra.Append(modelCurve1.GeometryCurve.Reference); ra.Append(modelCurve2.GeometryCurve.Reference); pt1 = new XYZ(5, 10, 0); pt2 = new XYZ(10, 10, 0); line = Line.CreateBound(pt1, pt2); Dimension dim = doc.FamilyCreate.NewLinearDimension(doc.ActiveView, line, ra); // Create a lable for the dimension called "width" FamilyParameter param = doc.FamilyManager.AddParameter("width", BuiltInParameterGroup.PG_CONSTRAINTS, ParameterType.Length, false); dim.FamilyLabel = param; trans.Commit(); } }
/// <summary> /// The top level command. /// </summary> /// <param name="revit">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 Result Execute(ExternalCommandData revit, ref string message, ElementSet elements) { m_app = revit.Application.Application; m_doc = revit.Application.ActiveUIDocument.Document; // Find a 3D view to use for the ray tracing operation FilteredElementCollector collector = new FilteredElementCollector(m_doc); Func <View3D, bool> isNotTemplate = v3 => !(v3.IsTemplate); m_view3D = collector.OfClass(typeof(View3D)).Cast <View3D>().First <View3D>(isNotTemplate); Autodesk.Revit.UI.Selection.Selection selection = revit.Application.ActiveUIDocument.Selection; // If skylight is selected, process it. m_skylight = null; if (selection.GetElementIds().Count == 1) { foreach (ElementId eId in selection.GetElementIds()) { Element e = revit.Application.ActiveUIDocument.Document.GetElement(eId); if (e is FamilyInstance) { FamilyInstance instance = e as FamilyInstance; bool isWindow = (instance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows); bool isHostedByRoof = (instance.Host.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Roofs); if (isWindow && isHostedByRoof) { m_skylight = instance; } } } } if (m_skylight == null) { message = "This tool requires exactly one skylight to be selected."; return(Result.Cancelled); } // Find the floor to use for the measurement (hardcoded) ElementId id = new ElementId(150314); m_floor = m_doc.GetElement(id) as Floor; // Calculate the height Line line = CalculateLineAboveFloor(); // Create a model curve to show the distance Plane plane = m_app.Create.NewPlane(new XYZ(1, 0, 0), line.GetEndPoint(0)); SketchPlane sketchPlane = SketchPlane.Create(m_doc, plane); ModelCurve curve = m_doc.Create.NewModelCurve(line, sketchPlane); // Show a message with the length value TaskDialog.Show("Distance", "Distance to floor: " + String.Format("{0:f2}", line.Length)); return(Result.Succeeded); }
internal static ElementId AddCurveToDocument(ref Document doc, Curve curve, out Reference geomRef) { SketchPlane plane = SketchPlane.Create(doc, SketchPlaneUtil.GetPlaneForCurve(curve)); ModelCurve addedCurve = doc.Create.NewModelCurve(curve, plane); geomRef = addedCurve.GeometryCurve.Reference; return(addedCurve.Id); }
public static void HighlightPoint(this Vector3 pt, double howBig, Model model) { Material highlight = new Material("Highlight", Colors.Red); ModelCurve m1 = new ModelCurve(new Line(pt + new Vector3(-1 * howBig, -1 * howBig, 0), pt + new Vector3(howBig, howBig, 0)), highlight); ModelCurve m2 = new ModelCurve(new Line(pt + new Vector3(-1 * howBig, 1 * howBig, 0), pt + new Vector3(howBig, -1 * howBig, 0)), highlight); model.AddElement(m1); model.AddElement(m2); }
public override void Destroy() { if (modelCurve != null) { Settings.Doc.Document.Delete(modelCurve); Settings.Doc.Document.Delete(sp); modelCurve = null; curve = null; } }
/// <summary> /// The construct of the FootPrintRoofLine class. /// </summary> /// <param name="roof">The footprint roof which the foot print data belong to.</param> /// <param name="curve">The model curve data which the foot print data stand for.</param> public FootPrintRoofLine(FootPrintRoof roof, ModelCurve curve) { m_roof = roof; m_curve = curve; m_boundingbox = m_roof.get_BoundingBox(Revit.SDK.Samples.NewRoof.CS.Command.ActiveView); }
/// <summary> /// Creates one model curve on a plane with an origin at 0,0,0 /// </summary> /// <param name="mc1"></param> protected void CreateOneModelCurve(out ModelCurve mc1) { //create two model curves using (var trans = new Transaction(DocumentManager.Instance.CurrentUIDocument.Document, "CreateTwoModelCurves")) { trans.Start(); var p1 = new Plane(XYZ.BasisZ, XYZ.Zero); SketchPlane sp1 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewSketchPlane(p1); Curve c1 = DocumentManager.Instance.CurrentUIApplication.Application.Create.NewLineBound(XYZ.Zero, new XYZ(1, 0, 0)); mc1 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewModelCurve(c1, sp1); trans.Commit(); } }
public override void Draw() { //sp = Settings.Doc.Document.Create.NewSketchPlane(plane_in.P); if (sp != null) { modelCurve = Settings.Doc.Document.Create.NewModelCurve(this.curve, sp); } }
/// <summary> /// /// </summary> /// <param name="app"></param> /// <param name="modelCurve"></param> /// <returns></returns> private static Revit.Element CloneElement( Autodesk.Revit.UI.UIApplication app, ModelCurve modelCurve ) { ModelCurve modelCurveClone = app.ActiveUIDocument.Document.Create.NewModelCurve( modelCurve.GeometryCurve, modelCurve.SketchPlane ); Utils.ParamUtil.SetParameters( modelCurveClone.Parameters, modelCurve.Parameters ); return modelCurveClone; }
private void Stream( ArrayList data, ModelCurve modelCurve ) { data.Add( new Snoop.Data.ClassSeparator( typeof( ModelCurve ) ) ); data.Add( new Snoop.Data.Object( "Geometry curve", modelCurve.GeometryCurve ) ); data.Add( new Snoop.Data.Object( "Sketch plane", modelCurve.SketchPlane ) ); data.Add( new Snoop.Data.ElementId( "Line style", modelCurve.LineStyle.Id, m_app.ActiveUIDocument.Document ) ); data.Add( new Snoop.Data.Enumerable( "Line styles", modelCurve.GetLineStyleIds(), m_app.ActiveUIDocument.Document ) ); ModelArc modelArc = modelCurve as ModelArc; if( modelArc != null ) { Stream( data, modelArc ); return; } ModelEllipse modelEllipse = modelCurve as ModelEllipse; if( modelEllipse != null ) { Stream( data, modelEllipse ); return; } ModelHermiteSpline modelHSpline = modelCurve as ModelHermiteSpline; if( modelHSpline != null ) { Stream( data, modelHSpline ); return; } ModelNurbSpline modelNSpline = modelCurve as ModelNurbSpline; if( modelNSpline != null ) { Stream( data, modelNSpline ); return; } ModelLine modelLine = modelCurve as ModelLine; if( modelLine != null ) { Stream( data, modelLine ); return; } }