/// <summary> /// Initialize a Grid element /// </summary> /// <param name="line"></param> private void InitGrid(Autodesk.Revit.DB.Line line) { // Changing the underlying curve requires destroying the Grid TransactionManager.Instance.EnsureInTransaction(Document); Autodesk.Revit.DB.Grid g = Document.Create.NewGrid(line); InternalSetGrid(g); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.CleanupAndSetElementForTrace(Document, this.InternalElement); }
public static Line FromRevit(Autodesk.Revit.DB.Line revitLine) { if (revitLine == null) { throw new ArgumentNullException(); } var line = new Line { StartPoint = PointInterop.FromRevit(revitLine.GetEndPoint(0)), EndPoint = PointInterop.FromRevit(revitLine.GetEndPoint(1)) }; return(line); }
private void InitDimension(Autodesk.Revit.DB.View view, Autodesk.Revit.DB.Line line, Autodesk.Revit.DB.ReferenceArray arr, Autodesk.Revit.DB.DimensionType type) { //Phase 1 - Check to see if the object exists and should be rebound var oldEle = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Dimension>(DocumentManager.Instance.CurrentDBDocument); // Rebind to Element if (oldEle != null) { InternalSetDimension(oldEle); return; } //Phase 2 - There was no existing Element, create new one TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var ii = DocumentManager.Instance.CurrentDBDocument.Create.NewDimension(view, line, arr, type); InternalSetDimension(ii); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
internal FamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.Line pos) { SafeInit(() => InitFamilyInstance(fs, reference, pos)); }
private void InitFamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.Line pos) { //Phase 1 - Check to see if the object exists and should be rebound var oldFam = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document); //There was an existing family instance, rebind to that, and adjust its position if (oldFam != null && oldFam.HostFace.ElementId == reference.ElementId) { InternalSetFamilyInstance(oldFam); InternalSetFamilySymbol(fs); InternalSetPosition(pos); return; } //Phase 2- There was no existing point, create one TransactionManager.Instance.EnsureInTransaction(Document); //If the symbol is not active, then activate it if (!fs.IsActive) { fs.Activate(); } var fi = Document.IsFamilyDocument ? Document.FamilyCreate.NewFamilyInstance(reference, pos, fs) : Document.Create.NewFamilyInstance(reference, pos, fs); InternalSetFamilyInstance(fi); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
/// protected Dimensions(Autodesk.Revit.DB.View view, Autodesk.Revit.DB.Line line, Autodesk.Revit.DB.ReferenceArray arr, Autodesk.Revit.DB.DimensionType type) { SafeInit(() => InitDimension(view, line, arr, type)); }
/// <summary> /// /// </summary> /// <param name="grid"></param> /// <param name="view"></param> /// <returns></returns> public static Element SetToViewCropBox(Element grid, View view) { if (grid == null || !(grid.InternalElement is Grid g)) { throw new ArgumentNullException(nameof(grid)); } if (view == null || !(view.InternalElement is Autodesk.Revit.DB.View v)) { throw new ArgumentNullException(nameof(view)); } var boundingLines = GetOutline(v.CropBox.ToProtoType()); var dsCurve = g.Curve.ToProtoType(); var midPt = dsCurve.PointAtParameter(0.5); var dir = ((Autodesk.Revit.DB.Line)g.Curve).Direction.ToVector(true); var resultList = new List <Autodesk.Revit.DB.XYZ>(); foreach (var bl in boundingLines) { midPt = Point.ByCoordinates(midPt.X, midPt.Y, bl.StartPoint.Z); // flatten var iResult1 = midPt.Project(bl, dir); var iResult2 = midPt.Project(bl, dir.Reverse()); if (iResult1.Length > 0) { resultList.Add(((Point)iResult1[0]).ToXyz()); } if (iResult2.Length > 0) { resultList.Add(((Point)iResult2[0]).ToXyz()); } } Autodesk.Revit.DB.Line updatedLine = null; if (resultList.Count == 2) { updatedLine = Autodesk.Revit.DB.Line.CreateBound(resultList[0], resultList[1]); } else { throw new ArgumentNullException(nameof(grid)); } //// (Konrad) If Grid Curve is a line, Revit wants it to be a Bound Curve. //// Otherwise it will throw an exception. //var startPt = curve.StartPoint.ToRevitType(); //var endPt = curve.EndPoint.ToRevitType(); //var line = Autodesk.Revit.DB.Line.CreateBound(startPt, endPt); //var distance = startPt.DistanceTo(endPt); //var length = line.Length; //var c = (length - distance) <= 0.001 // ? line // : curve.ToRevitType(); //var et = (Autodesk.Revit.DB.DatumExtentType)Enum.Parse(typeof(Autodesk.Revit.DB.DatumExtentType), extentType); var doc = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(doc); g.SetCurveInView(Autodesk.Revit.DB.DatumExtentType.ViewSpecific, v, updatedLine); TransactionManager.Instance.TransactionTaskDone(); return(grid); }
/// <summary> /// Private constructor that creates a new Element every time /// </summary> /// <param name="line"></param> private Grid(Autodesk.Revit.DB.Line line) { SafeInit(() => InitGrid(line)); }