CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz]
CZ | EN | DE
Login or
registration
  Visitors: 6767
Plex.Earth connects AutoCAD and Google Earth

CAD tip CAD tip # 13737:

   
Question CAD 
 %  platform  category 
Q - question

Formatting leading zeros in AutoCAD fields (and automatic field update).

A - answer Using lookup tables and dynamic blocks, you can in some cases solve the formatting of automatic labels (fields) using leading zeros (and the "+" sign) - that is, formatting that preserves the number of decimal places before the decimal point/comma.

An example of such a block ("Lead0") can be found in the sample DWG drawing FmtBlk.dwg - see Block 22544 for download. This block displays the formatted value of the current rotation angle. Similarly, a distance parameter, number of elements, etc. can be used. To align the resulting text, it would be neccessary to move the text position, e.g. by using another lookup table.

The use of the dynamic Lead0 block is then illustrated in the video:

The video also uses the "trick" of automatic update of the text field value (so no manual regeneration of the drawing is required). The LISP reactor is used for this, which updates the fields after each block grip edit. However, it is not suitable for larger drawings (performance). To activate it, load the following LISP code (via .LSP file or by copying it to the command line or to ACADDOC.LSP):

;Auto-update block fields after grip edit
(vl-load-com)
(if (not autoUpFldReactor)(setq autoUpFldReactor (VLR-Command-Reactor nil '((:VLR-commandEnded . autoUpFldCB)))))
(princ "\nBlock grip reactor active")

(defun autoUpFldCB (reactor objectlist / sset blk)
 (if (= (car objectlist) "GRIP_STRETCH")
  (progn
   (if (setq sset (ssget "_I" '((0 . "INSERT")(2 . "`*U*"))))
    (setq blk (ssname sset 0))
   )
   (if blk
    (vla-SendCommand (vla-get-activedocument (vlax-get-acad-object)) "_UPDATEFIELD ")
   )
  )
 )
)
(princ)
ACADACLTADTACADMPlantMapCivil3D
100% *  CAD 
17.5.2023    69015×  

See also:
Tip 13712:Why do I have an inactive "thousands separator" item in AutoCAD text field formatting?
Tip 13426:Use of alternative units for arithmetic in dimensions (without square brackets).
Tip 13006:Calculated property descriptions (tobogan slide from floor to floor)
Tip 13000:Labels of dimensional parameter values in dynamic blocks (parameters->attributes)
Tip 12790:Centered dynamic label (e.g. area label).


Back   All CAD Tips



Have we helped you? If you want to support the CAD Forum web service, consider buying one of our CAD applications, or our custom software development offerings, or donating via PayPal (see above). You may also add a link to your web - like this "fan" link: CAD Forum - tips, utilities, blocks for Autodesk products
CAD:    OS:    Categ: 
Text:  FAQ glossary   



Featuring:
Publish interactive 3D PDF models from AutoCAD, Inventor or Revit with Share3D More info


Please use these tips at your own risk.
Arkance Systems is not responsible for possible problems that may occur as a result of using any of these tips.
TOPlist