In the provided code, it looks like you're trying to create and adjust the position of the text for an AngularDimension object in Rhino. The movement of the dimension text might not be working as expected due to how the text position is being transformed or due to the specific properties of the AngularDimension object.
Here's a revised version of your code, with commented explanations and a focus on how to move the text of the dimension effectively:
public static List<AngularDimension> AngularDimantionFromCurve(Curve inputCurve, double offsetAngularDimensions, DimensionStyle textStyle)
{
List<Curve> explodedCurves = new List<Curve>();
Curve[] explodedCurveSegments = inputCurve.DuplicateSegments();
explodedCurves.AddRange(explodedCurveSegments);
List<AngularDimension> outAngularDimensions = new List<AngularDimension>();
var joinedFilletCurve = JoinCurvesFilletNutralAXes(explodedCurveSegments.ToList());
Plane currentDocPlane = RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.ConstructionPlane();
for (int i = 0; i < explodedCurves.Count - 1; i++)
{
Point3d startPointMainLine = explodedCurves[i].PointAtStart;
Point3d endPointMainLine = explodedCurves[i].PointAtEnd;
Point3d startPointSideLine = explodedCurves[i + 1].PointAtStart;
Point3d endPointSideLine = explodedCurves[i + 1].PointAtEnd;
Vector3d mainLineVector = endPointMainLine - startPointMainLine;
mainLineVector.Unitize();
Vector3d sideLineVector = endPointSideLine - startPointSideLine;
sideLineVector.Unitize();
Vector3d betweenLineVector = mainLineVector + sideLineVector;
betweenLineVector.Unitize();
double multiplyFactor = Math.Min(explodedCurves[i].GetLength() / 3, explodedCurves[i + 1].GetLength() / 3);
Point3d arcPointStart = EIToolsTl.movePointByVector(endPointMainLine, mainLineVector * multiplyFactor);
Point3d arcMidPoint = EIToolsTl.movePointByVector(endPointMainLine, betweenLineVector * multiplyFactor);
Point3d arcEndPoint = EIToolsTl.movePointByVector(endPointMainLine, sideLineVector * multiplyFactor);
// Create the arc for the angular dimension
Arc arcDimension = new Arc(arcPointStart, arcMidPoint, arcEndPoint);
AngularDimension angularDimension = AngularDimension.Create(textStyle, currentDocPlane, mainLineVector, endPointMainLine, arcPointStart, arcEndPoint, arcMidPoint);
// Set dimension properties
angularDimension.ParentDimensionStyle = textStyle;
angularDimension.AlternateBelowLine = false;
angularDimension.TextHeight = 2.5;
angularDimension.ArrowSize = 0.5;
angularDimension.TextOrientation = TextOrientation.InView;
// Here, we want to move the text for the angular dimension
Vector3d textOffset = new Vector3d(0, offsetAngularDimensions, 0); // Create an offset vector for text
Transform textTransform = Transform.Translation(textOffset); // Create a translation transform
angularDimension.TextPosition.Transform(textTransform); // Transform the text position
outAngularDimensions.Add(angularDimension);
}
return outAngularDimensions;
}
Key Changes and Recommendations:
-
Vector3d for Text Movement: Instead of trying to compute the text offset based on the center and position, I've provided a straightforward method to create a Vector3d directly related to the desired offset. You can adjust this vector to control the direction and amount to move the text.
-
Transform directly on TextPosition: It's important to perform Transform operations on the TextPosition directly. Your original method attempted to move based on a difference between the center and text position, but simplifying it to a predefined offset should yield more consistent results.
-
Debugging Transformations: If transformations aren't appearing as expected, I recommend adding diagnostic output (e.g., using Rhino.RhinoApp.WriteLine(...)) to check the text position before and after transformations.
-
Checking Text Visibility: Ensure the text position after transformation is within the bounds of the viewport where you are viewing the dimensions. If they move outside the bounds (off-screen), that might give an impression that they haven't moved.
-
Creating Dimensions: Ensure that dimensions are added to the document at the end of your dimension generation (you may already be doing this outside this function or could add it here).
By following these suggestions, the code should now effectively reposition the dimension text according to your defined offset. If you encounter further issues, please provide additional details about any error messages or unexpected behaviors you're observing.