Setting dimension override string in the required format?

<?xml encoding=”UTF-8″>By Daniel Du

Issue

How can I set the overridden text in the required units and format for a given dimension object? For example, I am using the “AddDimAligned” method to create a dimension between two lines, that is 3′-0″. I then use the “TextOverride” property to override the dimension of 3′-0″ to 1.667′ but 1.667′ is now a string. How can I convert the 1.667′ value to display it in Architectural units as 1′-8″?

Solution

TextOverride is a string property and hence you can use data type conversion utilities to format the number to the style you want. In the following VBA example, RealToString method of Utility object is used to format the number to the required style. To control the suppression of zeros, set the DIMZIN system variable.

In this example the value of DIMZIN is set to 1. This will Include zero feet and precisely zero inches while performing the conversions using realToString. You can also use this string “<>” in the TextOverride to display the actual measurement.
For example, you can specify dimobj.TextOverride = “length = <> mm”. This would set the override as “length = 10 mm” if the dimension’s measurement is 10mm.

<span><font color="#0000ff" face="新宋体"><font>Sub</font></font></span><font><font face="新宋体"><font color="#000000"> f_test()<br>    </font><span><font color="#0000ff">Dim</font></span><font color="#000000"> po_dim </font><span><font color="#0000ff">As</font></span></font><font face="新宋体"><font color="#000000"> AcadDimAligned<br>    </font><span><font color="#0000ff">Dim</font></span><font color="#000000"> p1(2) </font><span><font color="#0000ff">As</font></span><font color="#000000"> </font><span><font color="#0000ff">Double</font></span><br><font color="#000000">    </font><span><font color="#0000ff">Dim</font></span><font color="#000000"> p2(2) </font><span><font color="#0000ff">As</font></span><font color="#000000"> </font><span><font color="#0000ff">Double</font></span><br></font><font face="新宋体"><font color="#000000"> <br>    p1(0) = 0 : p1(1) = 0<br>    p2(0) = 10 : p2(1) = 10<br> <br>    po_dim = ThisDrawing.ModelSpace.AddDimAligned(p1, p2, p2)<br>    po_dim.TextOverride = ThisDrawing.Utility.RealToString(1.667 * 12,<br>                                                acArchitectural, 6)<br> <br>    </font><span><font color="#008000">'set the DIMZIN to required format</font></span><br><font color="#000000">    ThisDrawing.SetVariable(</font><span><font color="#a31515">"DIMZIN"</font></span></font><font face="新宋体"><font color="#000000">, 1)<br> <br>    </font><span><font color="#008000">'to test the required format</font></span><br></font></font><font face="新宋体"><font><font color="#000000">    MsgBox(ThisDrawing.Utility.RealToString(48, acArchitectural, 6))<br> </font><br><span><font color="#0000ff">End</font></span><font color="#000000"> </font></font><span><font color="#0000ff">Sub</font></span></font><br>

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading