修改并不太多:
- (defun c:test ( / doc ent format obj pt ) (vl-load-com)
- (setq format "%lu2%ct8[[color=red]0.01[/color]]") ;; Field Formatting Code
- (while
- (progn (setvar 'ERRNO 0) (setq ent (car (entsel)))
- (cond
- ( (= 7 (getvar 'ERRNO))
- (princ "\nMissed, try again.")
- )
- ( (eq 'ENAME (type ent))
- (if
- (and
- (vlax-property-available-p (setq obj (vlax-ename->vla-object ent)) '[color=red]length[/color])
- (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-[color=red]length[/color] (list obj))))
- )
- (if (setq pt (getpoint "\nSpecify Point for Field: "))
- (vla-addtext
- (vlax-get-property (setq doc (vla-get-activedocument (vlax-get-acad-object)))
- (if (= 1 (getvar 'CVPORT))
- 'Paperspace
- 'Modelspace
- )
- )
- (strcat
- "%<\\AcObjProp Object(%<\\_ObjId "
- (if
- (and
- (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
- (vlax-method-applicable-p (vla-get-utility doc) 'getobjectidstring)
- )
- (vla-getobjectidstring (vla-get-utility doc) obj :vlax-false)
- (itoa (vla-get-objectid obj))
- )
- ">%).[color=red]Length[/color] \\f "" format "">%"
- )
- (vlax-3D-point (trans pt 1 0))
- (getvar 'TEXTSIZE)
- )
- )
- (princ "\nInvalid Object.")
- )
- )
- )
- )
- )
- (princ)
- )
也许更好的方法是创建一个子函数,该子函数需要属性和字段格式作为参数,然后从两个程序中调用该子函数:
在这里,您可以为面积字段键入“afield”,为长度字段键入“lfield”。注意,我是如何通过这些命令为子函数提供参数的。 |