你以前帮过我一个Lisp程序,我正试图对另一个Lisp程序做同样的事情,但没有成功。
我原来的帖子
http://www.cadtutor.net/forum/showthread.php?104566-修改lisp将增量编号添加到区域文本
我的目标和我的第一篇帖子一样,在文本中的“L”字母旁边添加增量数字
我要更改的lisp:
- ;;-------------------------=={ Length Field }==-------------------------;;
- ;; ;;
- ;; This program allows a user to generate a field expression ;;
- ;; referencing the length/perimeter/circumference of one or more ;;
- ;; selected objects. In the case of selecting multiple objects, the ;;
- ;; field expression will reference the sum of the lengths of all ;;
- ;; objects in the selection. ;;
- ;; ;;
- ;; The user may opt to specify a point at which to create a new ;;
- ;; multiline text object housing the field expression, pick a table ;;
- ;; cell in which the field should be inserted, or select an existing ;;
- ;; single-line text, multiline text, multileader, or attribute to ;;
- ;; be populated with the field expression. ;;
- ;; ;;
- ;; Upon issuing the command syntax 'LF' (Length Field) at the AutoCAD ;;
- ;; command-line, the program first prompts the user to make a ;;
- ;; selection of objects for which to return the length summation. ;;
- ;; ;;
- ;; At this prompt, the user may select any number of Arcs, Circles, ;;
- ;; Lines, 2D Polylines (light or heavy), or 3D Polylines. ;;
- ;; ;;
- ;; The user is then prompted to specify a point or table cell to ;;
- ;; insert a field expression referencing the summation of the lengths ;;
- ;; of the selected objects. ;;
- ;; ;;
- ;; At this prompt, the user may also choose the 'Object' option in ;;
- ;; order to populate the content of an existing annotation object ;;
- ;; with the field expression. ;;
- ;; ;;
- ;; Upon choosing this option, the user may select any single-line ;;
- ;; text (DText), multiline text (MText), single-line or multiline ;;
- ;; attribute, attributed block, or multileader (MLeader) with either ;;
- ;; multiline text or attributed block content. ;;
- ;; ;;
- ;; If the user selects an attributed block or attributed multileader ;;
- ;; with more than one attribute, the user is presented with a dialog ;;
- ;; interface listing the available attributes, and is prompted to ;;
- ;; select a destination for the field expression. ;;
- ;; ;;
- ;; The user may optionally predefine the target block/multileader ;;
- ;; attribute by specifying the attribute tag where noted at the top ;;
- ;; of the program source code. ;;
- ;; ;;
- ;; The resulting field expression will display the sum of the lengths ;;
- ;; of the selected objects, formatted using the field formatting code ;;
- ;; specified at the top of the program. ;;
- ;; ;;
- ;;----------------------------------------------------------------------;;
- ;; Author: Lee Mac, Copyright © 2017 - www.lee-mac.com ;;
- ;;----------------------------------------------------------------------;;
- ;; Version 1.0 - 2017-08-06 ;;
- ;; ;;
- ;; - First release. ;;
- ;;----------------------------------------------------------------------;;
- ;; Version 1.1 - 2017-08-06 ;;
- ;; ;;
- ;; - Program modified to account for selection of existing annotation ;;
- ;; objects which already contain a field expression. ;;
- ;;----------------------------------------------------------------------;;
- (defun c:lf ( / *error* ent enx flg fmt idx lst obj oid prp sel str tab tag tmp typ )
- (setq fmt "L=%lu6%pr2 cm" ;; Field Formatting ;; L1, L2, L3, L...
- tag nil ;; Optional predefined attribute tag
- )
-
- (defun *error* ( msg )
- (LM:endundo (LM:acdoc))
- (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
- (princ (strcat "\nError: " msg))
- )
- (princ)
- )
- (LM:startundo (LM:acdoc))
- (setq prp
- '(
- ("AcDbArc" . "ArcLength")
- ("AcDbCircle" . "Circumference")
- ("AcDbLine" . "Length")
- ("AcDbPolyline" . "Length")
- ("AcDb2dPolyline" . "Length")
- ("AcDb3dPolyline" . "Length")
- )
- )
- (if
- (setq sel
- (LM:ssget "\nSelect objects to obtain total length <exit>: "
- (list
- (list
- '(000 . "ARC,CIRCLE,LINE,*POLYLINE")
- '(-04 . "<NOT")
- '(-04 . "<AND")
- '(000 . "POLYLINE") '(-04 . "&") '(070 . 80)
- '(-04 . "AND>")
- '(-04 . "NOT>")
- (if (= 1 (getvar 'cvport))
- (cons 410 (getvar 'ctab))
- '(410 . "Model")
- )
- )
- )
- )
- )
- (progn
- (if (= 1 (sslength sel))
- (setq obj (vlax-ename->vla-object (ssname sel 0))
- str
- (strcat
- "%<\\AcObjProp Object(%<\\_ObjId "
- (LM:objectid obj)
- ">%)." (cdr (assoc (vla-get-objectname obj) prp)) " \\f "" fmt "">%"
- )
- )
- (progn
- (repeat (setq idx (sslength sel))
|