Here's one based on a similar area program I wrote here.
Code:
;;--------------------=={ Length Field }==--------------------;;
;; ;;
;; Creates an MText Field referencing the sum of the lengths ;;
;; of selected objects. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
(defun c:LenField ( / acdoc acspc format pt ss )
(setq format "%lu6%qf1") ;; Field Formatting
(setq acdoc (vla-get-activedocument (vlax-get-acad-object))
acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace))
)
(if
(and
(ssget '((0 . "LINE,*POLYLINE")))
(setq pt (getpoint "\nPick Point for Field: "))
)
(
(lambda ( ss fld )
(vlax-for obj ss
(setq fld
(strcat fld "%<\\AcObjProp Object(%<\\_ObjId "
(LM:GetObjectID acdoc obj) ">%).Length>% + "
)
)
)
(vla-addMText acspc (vlax-3D-point (trans pt 1 0)) 0.
(setq fld
(strcat
(substr fld 1
(- (strlen fld) (if (< 1 (vla-get-Count ss)) 3 5))
)
" \\f \"" format "\">%"
)
)
)
(vla-delete ss)
)
(setq ss (vla-get-ActiveSelectionSet acdoc))
(if (< 1 (vla-get-Count ss)) "%<\\AcExpr " "")
)
)
(princ)
)
;;-------------------=={ Get ObjectID }==---------------------;;
;; ;;
;; Returns the ObjectID string for the supplied VLA-Object ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; doc - VLA Document Object (req'd for 64-bit systems) ;;
;; obj - VLA Object to query ;;
;;------------------------------------------------------------;;
;; Returns: ObjectID string for VLA-Object ;;
;;------------------------------------------------------------;;
(defun LM:GetObjectID ( doc obj )
(if (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
(vlax-invoke-method (vla-get-Utility doc) 'GetObjectIdString obj :vlax-false)
(itoa (vla-get-Objectid obj))
)
)