public static void CenterTextOnLine(global::Revit.Elements.Dimension dimension) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; Autodesk.Revit.DB.Dimension internalDimension = (Autodesk.Revit.DB.Dimension)dimension.InternalElement; Autodesk.Revit.DB.View ownerView = (Autodesk.Revit.DB.View)doc.GetElement(internalDimension.OwnerViewId); //calculate offset distance from the view scale and the text size. int viewScaleFactor = ownerView.Scale; double textHeight = (double)internalDimension.DimensionType.get_Parameter(BuiltInParameter.TEXT_SIZE).AsDouble(); double offsetAmount = ((textHeight + 0.002604) / 2) * viewScaleFactor; List <Line> dimCurve = GetCurve(dimension); if (internalDimension.NumberOfSegments > 1) { for (int i = 0; i < internalDimension.NumberOfSegments; i++) { Autodesk.Revit.DB.Line dimLine = dimCurve[i].ToRevitType() as Autodesk.Revit.DB.Line; var currentSegment = internalDimension.Segments.get_Item(i); XYZ point = dimLine.Evaluate(0.5, true); XYZ normal = dimLine.Direction.Normalize(); XYZ dir = new XYZ(0, 0, 1); XYZ cross = normal.CrossProduct(dir); if (cross.Y > 0) { offsetAmount = -offsetAmount; } XYZ pointEnd = point + (offsetAmount) * cross; TransactionManager.Instance.EnsureInTransaction(doc); currentSegment.TextPosition = pointEnd; TransactionManager.Instance.TransactionTaskDone(); } } else { Autodesk.Revit.DB.Line singleLine = dimCurve.First().ToRevitType() as Autodesk.Revit.DB.Line; XYZ point = singleLine.Evaluate(0.5, true); XYZ normal = singleLine.Direction.Normalize(); XYZ dir = new XYZ(0, 0, 1); XYZ cross = normal.CrossProduct(dir); if (cross.Y > 0) { offsetAmount = -offsetAmount; } XYZ pointEnd = point + (offsetAmount) * cross; TransactionManager.Instance.EnsureInTransaction(doc); internalDimension.TextPosition = pointEnd; TransactionManager.Instance.TransactionTaskDone(); } }
public static List <string> DisplayValueString(global::Revit.Elements.Dimension dimension) { //the current document Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; //list to append values to List <string> values = new List <string>(); //convert the dimension to the Revit DB Version Autodesk.Revit.DB.Dimension internalDimension = dimension.InternalElement as Autodesk.Revit.DB.Dimension; if (internalDimension.DimensionType.GetUnitsFormatOptions().UseDefault) { if (internalDimension.NumberOfSegments == 0) { values.Add(internalDimension.ValueString); } else { foreach (DimensionSegment segment in internalDimension.Segments) { values.Add(segment.ValueString); } } } else { TransactionManager.Instance.EnsureInTransaction(doc); Units ogUnits = doc.GetUnits(); Units newUnits = new Units(UnitSystem.Imperial); newUnits.SetFormatOptions(internalDimension.DimensionType.UnitType, internalDimension.DimensionType.GetUnitsFormatOptions()); //set the document units and commit the change doc.SetUnits(newUnits); //if else statement to work for both single segment or multi segment dimensions. if (internalDimension.NumberOfSegments == 0) { values.Add(internalDimension.ValueString); } else { foreach (DimensionSegment segment in internalDimension.Segments) { values.Add(segment.ValueString); } } doc.SetUnits(ogUnits); TransactionManager.Instance.TransactionTaskDone(); } //return the values you retrieved. return(values); }
public static List <Autodesk.DesignScript.Geometry.Line> GetCurve(global::Revit.Elements.Dimension dimension) { //convert to internal dimension Autodesk.Revit.DB.Dimension internalDimension = (Autodesk.Revit.DB.Dimension)dimension.InternalElement; Document doc = internalDimension.Document; List <Autodesk.DesignScript.Geometry.Line> dimensionLine = new List <Line>(); if (internalDimension.NumberOfSegments > 1) { Autodesk.Revit.DB.DimensionSegmentArray dimSegArray = internalDimension.Segments; List <Autodesk.Revit.DB.DimensionSegment> dimSegments = new List <DimensionSegment>(); foreach (Autodesk.Revit.DB.DimensionSegment seg in internalDimension.Segments) { dimSegments.Add(seg); } foreach (Autodesk.Revit.DB.DimensionSegment s in dimSegments) { var originPoint = s.Origin.ToPoint(); Autodesk.Revit.DB.Line dimCurve = (Autodesk.Revit.DB.Line)internalDimension.Curve; var vector = dimCurve.Direction.ToVector(); var dimValue = s.Value.Value; if (doc.DisplayUnitSystem.ToString() != "IMPERIAL") { dimValue = s.Value.Value * 304.8; } var startPoint = (Autodesk.DesignScript.Geometry.Point)originPoint.Translate(vector.Reverse(), dimValue / 2); var endPoint = (Autodesk.DesignScript.Geometry.Point)originPoint.Translate(vector, dimValue / 2); dimensionLine.Add(Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(startPoint, endPoint)); } } else { var originPoint = internalDimension.Origin.ToPoint(); Autodesk.Revit.DB.Line dimCurve = (Autodesk.Revit.DB.Line)internalDimension.Curve; var vector = dimCurve.Direction.ToVector(); var dimValue = internalDimension.Value.Value; if (doc.DisplayUnitSystem.ToString() != "IMPERIAL") { dimValue = internalDimension.Value.Value * 304.8; } var startPoint = (Autodesk.DesignScript.Geometry.Point)originPoint.Translate(vector.Reverse(), dimValue / 2); var endPoint = (Autodesk.DesignScript.Geometry.Point)originPoint.Translate(vector, dimValue / 2); dimensionLine.Add(Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(startPoint, endPoint)); } return(dimensionLine); }
public static List <string> BelowValue(global::Revit.Elements.Dimension dimension) { Autodesk.Revit.DB.Dimension internalDimension = dimension.InternalElement as Autodesk.Revit.DB.Dimension; List <string> values = new List <string>(); if (internalDimension.NumberOfSegments == 0) { values.Add(internalDimension.Below); } else { foreach (DimensionSegment segment in internalDimension.Segments) { values.Add(segment.Below); } } return(values); }
public static List <Point> TextPosition(global::Revit.Elements.Dimension dimension) { //List<Point> textPosition = new List<Point>(dimension.Select(d => ((Autodesk.Revit.DB.Dimension)d.InternalElement).TextPosition.ToPoint()).ToArray()); Autodesk.Revit.DB.Dimension internalDimension = dimension.InternalElement as Autodesk.Revit.DB.Dimension; List <Point> values = new List <Point>(); if (internalDimension.NumberOfSegments == 0) { values.Add(internalDimension.TextPosition.ToPoint(true)); } else { foreach (DimensionSegment segment in internalDimension.Segments) { values.Add(segment.TextPosition.ToPoint(true)); } } return(values); }
public static List <string> ValueString(global::Revit.Elements.Dimension dimension) { Autodesk.Revit.DB.Dimension internalDimension = dimension.InternalElement as Autodesk.Revit.DB.Dimension; List <string> values = new List <string>(); //List<string> valueString = new List<string>(dimension.Select(d => ((Autodesk.Revit.DB.Dimension)d.InternalElement).ValueString).ToArray()); if (internalDimension.NumberOfSegments == 0) { values.Add(internalDimension.ValueString); } else { foreach (DimensionSegment segment in internalDimension.Segments) { values.Add(segment.ValueString); } } return(values); }
public static List <global::Revit.Elements.Element> GetReferenceElements(global::Revit.Elements.Dimension dimension) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; //convert to internal dimension Autodesk.Revit.DB.Dimension internalDimension = (Autodesk.Revit.DB.Dimension)dimension.InternalElement; //lists to output success or not success List <global::Revit.Elements.Element> referenceElements = new List <global::Revit.Elements.Element>(); try { ReferenceArray refs = new ReferenceArray(); refs = internalDimension.References; foreach (Reference r in refs) { referenceElements.Add(doc.GetElement(r.ElementId).ToDSType(true)); } } catch (Exception) { referenceElements.Add(null); } return(referenceElements); }
public static void SetTextLocation(global::Revit.Elements.Dimension dimension, List <Autodesk.DesignScript.Geometry.Point> locationPoint) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; //convert to internal dimension Autodesk.Revit.DB.Dimension internalDimension = (Autodesk.Revit.DB.Dimension)dimension.InternalElement; List <Autodesk.Revit.DB.Dimension> internalDimensionList = new List <Autodesk.Revit.DB.Dimension> { internalDimension }; if (internalDimension.NumberOfSegments > 1) //set the multi segment ones { List <DimensionSegment> dimSegments = new List <DimensionSegment>(); foreach (DimensionSegment seg in internalDimension.Segments) { dimSegments.Add(seg); } //check if lists are even bool cond = locationPoint.Count < 2 && dimSegments.Count > 1; IEnumerable <Autodesk.DesignScript.Geometry.Point> repeatedSequence = Enumerable.Repeat(locationPoint.First(), dimSegments.Count); if (cond) { int count = 0; TransactionManager.Instance.EnsureInTransaction(doc); while (count < dimSegments.Count) { dimSegments[count].TextPosition = repeatedSequence.ElementAt(count).ToXyz(); count++; } TransactionManager.Instance.TransactionTaskDone(); } else { int count = 0; TransactionManager.Instance.EnsureInTransaction(doc); while (count < dimSegments.Count) { dimSegments[count].TextPosition = locationPoint[count].ToXyz(); count++; } TransactionManager.Instance.TransactionTaskDone(); } } else // set the single ones { //check if lists are even bool cond = locationPoint.Count < 2 && internalDimensionList.Count > 1; IEnumerable <Autodesk.DesignScript.Geometry.Point> repeatedSequence = Enumerable.Repeat(locationPoint.First(), internalDimensionList.Count); if (cond) { int count = 0; TransactionManager.Instance.EnsureInTransaction(doc); while (count < internalDimensionList.Count) { internalDimensionList[count].TextPosition = repeatedSequence.ElementAt(count).ToXyz(); count++; } TransactionManager.Instance.TransactionTaskDone(); } else { int count = 0; TransactionManager.Instance.EnsureInTransaction(doc); while (count < internalDimensionList.Count) { internalDimensionList[count].TextPosition = locationPoint[count].ToXyz(); count++; } TransactionManager.Instance.TransactionTaskDone(); } } }
public static Dictionary <string, object> SetBelowValue(global::Revit.Elements.Dimension dimension, List <string> belowValue) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; //convert to internal dimension Autodesk.Revit.DB.Dimension internalDimension = (Autodesk.Revit.DB.Dimension)dimension.InternalElement; List <Autodesk.Revit.DB.Dimension> internalDimensionList = new List <Autodesk.Revit.DB.Dimension> { internalDimension }; //lists to output success or not success List <global::Revit.Elements.Element> set = new List <global::Revit.Elements.Element>(); List <global::Revit.Elements.Element> notSet = new List <global::Revit.Elements.Element>(); try { if (internalDimension.NumberOfSegments > 1) //set the multi segment ones { List <DimensionSegment> dimSegments = new List <DimensionSegment>(); foreach (DimensionSegment seg in internalDimension.Segments) { dimSegments.Add(seg); } //check if lists are even bool cond = belowValue.Count < 2 && dimSegments.Count > 1; IEnumerable <string> repeatedSequence = Enumerable.Repeat(belowValue.First(), dimSegments.Count); if (cond) { int count = 0; TransactionManager.Instance.EnsureInTransaction(doc); while (count < dimSegments.Count) { dimSegments[count].Below = repeatedSequence.ElementAt(count); count++; } TransactionManager.Instance.TransactionTaskDone(); set.Add(dimension); } else { int count = 0; TransactionManager.Instance.EnsureInTransaction(doc); while (count < dimSegments.Count) { dimSegments[count].Below = belowValue[count]; count++; } TransactionManager.Instance.TransactionTaskDone(); set.Add(dimension); } } else // set the single ones { //check if lists are even bool cond = belowValue.Count < 2 && internalDimensionList.Count > 1; IEnumerable <string> repeatedSequence = Enumerable.Repeat(belowValue.First(), internalDimensionList.Count); if (cond) { int count = 0; TransactionManager.Instance.EnsureInTransaction(doc); while (count < internalDimensionList.Count) { internalDimensionList[count].Below = repeatedSequence.ElementAt(count); count++; } TransactionManager.Instance.TransactionTaskDone(); set.Add(dimension); } else { int count = 0; TransactionManager.Instance.EnsureInTransaction(doc); while (count < internalDimensionList.Count) { internalDimensionList[count].Below = belowValue[count]; count++; } TransactionManager.Instance.TransactionTaskDone(); set.Add(dimension); } } } catch (Exception) { notSet.Add(dimension); } //returns the outputs var outInfo = new Dictionary <string, object> { { "set", set }, { "notSet", notSet } }; return(outInfo); }