Hi,
I am facing problem while adding dimension text location for small sketch entities.
Please refer below sample code which I have used:
//=======================================================================
CComPtr<Point2d> pt1 = TransientGeometry::MethodCreatePoint2d(0.01, 0.01);
CComPtr<Point2d> pt2 = TransientGeometry::MethodCreatePoint2d(0.02, 0.04);
CComPtr<Point2d> pt3 = TransientGeometry::MethodCreatePoint2d(0.05, 0.03);
CComPtr<Point2d> pt4 = TransientGeometry::MethodCreatePoint2d(0.04, 0.07);
CComPtr<SketchPoint> sketchPt1 = SketchPoints::MethodAdd(pt1, FALSE);
CComPtr<SketchPoint> sketchPt2 = SketchPoints::MethodAdd(pt2, FALSE);
CComPtr<SketchPoint> sketchPt3 = SketchPoints::MethodAdd(pt3, FALSE);
CComPtr<SketchPoint> sketchPt4 = SketchPoints::MethodAdd(pt4, FALSE);
CComPtr<SketchLine> sketchLine1 = SketchLines::MethodAddByTwoPoints(sketchPt1, sketchPt2);
CComPtr<SketchLine> sketchLine2 = SketchLines::MethodAddByTwoPoints(sketchPt3, sketchPt4);
CComPtr<DimensionConstraints> dimConstraints;
PlanarSketch::get_DimensionConstraints(&dimConstraints);
CComPtr<Point2d> textPoint = TransientGeometry::MethodCreatePoint2d(0.03, 0.02); // Mid-point of sketchPt1 and sketchPt3
CComPtr<TwoPointDistanceDimConstraint>distanceConstraint;
dimConstraints->AddTwoPointDistance(sketchPt1, sketchPt3, kAlignedDim, textPoint, FALSE, &distanceConstraint);
CComPtr<Point2d> tmpPt = distanceConstraint->GetTextPoint();
double x = tmpPt->GetX();
double y = tmpPt->GetY();
//=======================================================================
I have put text location point as mid-point of sketchPt1 and sketchPt3. But the API "AddTwoPointDistance" modifies the point internally. This would be verified by retrieving text point from output distanceConstraint which is differnet than the input textPoint.
My observation is that, for smaller entities the text location gets modified far away from the entites. Please see attached snap "DimensionTextLocation.jpg".
Please tell me,
why it happens for smaller sketch entities?
Is there any solution for placing the dimension text at specified location for smaller sketch entities?
Why the dimension lines drawn so long? How they could be placed appropriately?
Thanks in advance!!!
Hi,
Others might jump in quicker to double-check things if you provide code in VBA which is very easy to test:
Sub SmallSketch() Dim doc As PartDocument Set doc = ThisApplication.ActiveDocument Dim sk As PlanarSketch Set sk = doc.ComponentDefinition.Sketches(1) Dim tr As TransientGeometry Set tr = ThisApplication.TransientGeometry Dim pt1 As Point2d Set pt1 = tr.CreatePoint2d(0.01, 0.01) Dim pt2 As Point2d Set pt2 = tr.CreatePoint2d(0.02, 0.04) Dim pt3 As Point2d Set pt3 = tr.CreatePoint2d(0.05, 0.03) Dim pt4 As Point2d Set pt4 = tr.CreatePoint2d(0.04, 0.07) Dim sketchPt1 As SketchPoint Set sketchPt1 = sk.SketchPoints.Add(pt1, False) Dim sketchPt2 As SketchPoint Set sketchPt2 = sk.SketchPoints.Add(pt2, False) Dim sketchPt3 As SketchPoint Set sketchPt3 = sk.SketchPoints.Add(pt3, False) Dim sketchPt4 As SketchPoint Set sketchPt4 = sk.SketchPoints.Add(pt4, False) Dim sketchLine1 As SketchLine Set sketchLine1 = sk.SketchLines.AddByTwoPoints(sketchPt1, sketchPt2) Dim sketchLine2 As SketchLine Set sketchLine2 = sk.SketchLines.AddByTwoPoints(sketchPt3, sketchPt4) Dim dimConstraints As DimensionConstraints Set dimConstraints = sk.DimensionConstraints Dim textPoint As Point2d Set textPoint = tr.CreatePoint2d(0.03, 0.02) Dim distanceConstraint As TwoPointDistanceDimConstraint Set distanceConstraint = dimConstraints.AddTwoPointDistance(sketchPt1, sketchPt3, kAlignedDim, textPoint, False) Dim tmpPt As Point2d Set tmpPt = distanceConstraint.textPoint End Sub
Another thing that can be useful is to try to reproduce the same behaviour in the UI. If you can reproduce it there too, then it's not an API issue and it's worth asking about it on the product forum.
E.g. I could only create the same dimension using the "Automatic Dimensions and Constraints" command and that exhibits the same behaviour.
Cheers,