I use the routine below in my tool JLG.Dimension (http://perso.orange.fr/jlg.outils) to calculate the length of a Bezier curve.<br />This is my little contribution to this discussion. To obtain the length as a string, you have to use a routine to convert a AIReal number into a string.<br />I hope this will help somebody.<br /><br />extern void BezierLength(AIArtHandle *path, short unit, AIReal scale, char BezierlengthText[])<br /> {//Calculate in BezierlengthText the total length of the Bezier curve (path). The result is a string.<br /> //If unit is 0 the length will be mm, 1 cm, 2 inches, 3 points, 4 picas and 5 for meters. <br /> AIErr error=kNoErr;<br /> long i, j;<br /> short pathCount, NtS;//NtS for number to string.<br /> AIBoolean IsClosed;<br /> AIRealBezier PtBezier;<br /> AIPathSegment Pt1, Pt2;<br /> //At the beginning, the length is zero.<br /> AIReal LengthOfBezier=0.0;<br /> <br /><br /> error = sPath->GetPathSegmentCount(*path, &pathCount );<br /> //If the path analyzed is closed, it will be necessary to add the length of the last part of the Bezier curve. <br /> error=sPath->GetPathClosed(*path, &IsClosed);<br /><br /> for(j=0;j<pathCount-1;j++)<br /> {//One point and the next point.<br /> error = sPath->GetPathSegments( *path, j, 1, &Pt1);<br /> error = sPath->GetPathSegments( *path, j+1, 1, &Pt2);<br /><br /> PtBezier.p0.h=Pt1.p.h;<br /> PtBezier.p0.v=Pt1.p.v;<br /> <br /> PtBezier.p1.h=Pt1.out.h;<br /> PtBezier.p1.v=Pt1.out.v;<br /><br /> PtBezier.p2.h=Pt2.in.h;<br /> PtBezier.p2.v=Pt2.in.v;<br /><br /> PtBezier.p3.h=Pt2.p.h;<br /> PtBezier.p3.v=Pt2.p.v;<br /><br /> LengthOfBezier+=sBezier->Length(&PtBezier, 1.0);<br /> }<br /><br /> if(IsClosed)<br /> {//The path is closed, we must calculate the length of the last segment (point 0 and point pathCount-1).<br /> error = sPath->GetPathSegments( *path, 0, 1, &Pt1);<br /> error = sPath->GetPathSegments( *path, pathCount-1, 1, &Pt2);<br /><br /> PtBezier.p0.h=Pt1.p.h;<br /> PtBezier.p0.v=Pt1.p.v;<br /><br /> PtBezier.p1.h=Pt1.in.h;<br /> PtBezier.p1.v=Pt1.in.v;<br /><br /> PtBezier.p2.h=Pt2.out.h;<br /> PtBezier.p2.v=Pt2.out.v;<br /><br /> PtBezier.p3.h=Pt2.p.h;<br /> PtBezier.p3.v=Pt2.p.v; <br /> LengthOfBezier+=sBezier->Length(&PtBezier, 1.0);<br /> }<br /><br /> //At this moment, LengthOfBezier contains the total length of the curve but the unit used is the point.<br /> switch(unit)<br /> {case 0://millimeters.<br /> LengthOfBezier=LengthOfBezier* 25.4 / 72.0 / scale;<br /> //Transform the length into a string.<br /> NtS=NumberToString(LengthOfBezier, BezierlengthText);<br /> //Add the unit.<br /> std::strcat(BezierlengthText, " mm");<br /> break;<br /> case 1://centimeters.<br /> LengthOfBezier=LengthOfBezier* 2.54 / 72.0/ scale;<br /> //Transform the length into a string.<br /> NtS=NumberToString(LengthOfBezier, BezierlengthText);<br /> //Add the unit.<br /> std::strcat(BezierlengthText, " cm");<br /> break;<br /> case 2://Inches.<br /> LengthOfBezier=LengthOfBezier/ 72.0 / scale;<br /> //Transform the length into a string.<br /> NtS=NumberToString(LengthOfBezier, BezierlengthText);<br /> //Add the unit.<br /> std::strcat(BezierlengthText, " in");<br /> break;<br /> case 3://Points.<br /> LengthOfBezier=LengthOfBezier/ scale;<br /> //Transform the length into a string.<br /> NtS=NumberToString(LengthOfBezier, BezierlengthText);<br /> //Add the unit.<br /> std::strcat(BezierlengthText, " pt");<br /> break;<br /> case 4://Picas.<br /> LengthOfBezier=LengthOfBezier/ 12.0/ scale;<br /> //Transform the length into a string.<br /> NtS=NumberToString(LengthOfBezier, BezierlengthText);<br /> //Add the unit.<br /> std::strcat(BezierlengthText, " pi");<br /> break;<br /> case 5://Meters.<br /> LengthOfBezier=LengthOfBezier * 0.0254 / 72.0 / scale;<br /> //Transform the length into a string.<br /> NtS=NumberToString(LengthOfBezier, BezierlengthText);<br /> //Add the unit.<br /> std::strcat(BezierlengthText, " m");<br /> break;<br /> default:<br /> break;<br /> }<br /> }<br /><br />JLG.