September 24, 2012

Dynamic Viewport Scale Bar

While on technical support at Ideate, we often receive requests from our customers for items or features that aren’t currently part of AutoCAD and Civil 3D. One recent request was for a Viewport Scale Bar that dynamically updates its values when a user changes the Viewport scale in their drawing.

Although this can be done by linking blocks with fields to Sheet Set Views, not all users use sheet sets or take the time to set them up with a linked scale. In this case, we were able to create a custom made viewport scale bar linked to the Viewport itself without the use of Sheet Sets. 

The scale bar we were looking for is fairly standard. It is divided into three 1-inch sections, each linked to a multiple of the viewport scale. To the right of the 0 value, a whole number representing the viewport scale and a double value of the scale are shown. To the left, half and whole value increments are displayed.
*image not to scale

This Scale bar is dynamically linked to the Viewport through the use of Fields.  When a Viewport Scale is specified (1:10 in the example) and the drawing is regenerated, the SCALE: item is updated along with the values for 10, 20, -5 and -10. Although it seems easy enough, these are not standard Field options and require some manipulation of the Field codes. 

In each case, a Field was inserted for the value, with the Field Name and Field Category set to Object. The Viewport was selected as the Object Type and Custom Scale was set as the Property.

In the Format section, the 1:# and 1”=#’ options were the starting points for the modified field codes. 

To get the whole number value, I started with the code for 1:#
%<\AcObjProp Object(%<\_ObjId 8796083731456>%).CustomScale \f “1:%lu2%ct1%qf2816”>%
From that, removing the highlighted 1: item produces just the # value in the field (1:10 becomes 10). 

The revised code looks like this:
%<\AcObjProp Object(%<\_ObjId 8796083731456>%).CustomScale \f “%lu2%ct1%qf2816”>%
For the 0.5x and 2x multiple values, the 1”=#’ code was the starting point
%<\AcObjProp.16.2 Object(%<\_ObjId 8796083731456>%).CustomScale \f “1\” = %lu2%zs12%ct9[0.0833333333333333]’”>%
Since this code was created to apply a multiplier of 0.0833333333333333 to the original scale factor, all I needed to do was change that to 0.5 and 2 respectively. Once that was done, removing the 1/”= portion of the code left me with only the multiplied values. The “-“ was also added to the codes on the left side of the 0 value (-10 is the code from above with a “-“ added to it). 

The resulting code for -0.5x and 2x values are
%<\AcObjProp.16.2 Object(%<\_ObjId 8796083731456>%).CustomScale \f “-%lu2%zs12%ct9[0.5]’”>%
%<\AcObjProp.16.2 Object(%<\_ObjId 8796083731456>%).CustomScale \f “%lu2%zs12%ct9[2]’”>%
The result is a dynamic Viewport Scale bar that updates (after REGENALL) if a user changes the Viewport scale.

That said, it is not without its faults. Here are some tips and items to consider when using this custom scale bar.
  1. Because Fields are linked to specific objects in a file, the Dynamic Scale bar cannot be copied and pasted directly into another drawing. BOTH items (Scale bar and Viewport) need to be copied in order for it to work in another file.
  2. The modified code used to generate the required values is NOT supported since it is a modification to background coding intended for use with Object Fields. Use of these objects is at your own risk.
  3. Updating of the values is not triggered automatically. Users are required to REGENALL for the numbers to update after a viewport scale is changed.  Always remember to verify the scale with the Scale Bar regardless of dynamic functionality.
  4. The scale bar in our sample file was set up for engineering scales (i.e. 1:10, 1:20 etc.). It will also convert fractional (Architectural) scales to this format. A ¼”=1’-0” scale would display as 1:48 using this Scale Bar.
  5. Viewports and Scale Bars can be saved to your drawing template (.DWT) file so that they automatically appear in new files. The size of the viewport can be adjusted as needed after the drawing is created.
  6. Layouts can be created with pre-defined paper sizes (Page Setups) that include these Viewports and Scale Bars. Use the Design Center to copy these into existing drawings or to add them to a template (.DWT) file.
  7. Do Not convert the Scale Bar into a Block. The Scale Bar needs to remain un-blocked in order for the Fields to function properly after it is copied.
If you want to check this out for yourself, here's a drawing file (.DWG) that includes a viewport and scale bar. Per item 6 above, you can use the Design Center to copy one of these layouts into your own drawing files and adjust the Viewport as needed once they’re in the file.

Matt Miyamoto, P.E.
Ideate AEC Application Specialist

Matt is a licensed Civil Engineer in the state of Hawaii. Matt obtained a BS in Mechanical Engineering from the University of Hawaii at Manoa, and has 7 years of private sector design experience which he applies in his role as an application specialist with Ideate, Inc. His project experience includes residential and commercial site development, private and public sewer, water and drainage systems, harbors improvements, and roadway improvements. While in Hawaii, Matt was involved in multidisciplinary projects for City and County agencies, State Departments, the Army COE and private developers. @MattM_PE

Get it. Know it. Use it.