1. (defun C:CTB(/ *error* edata ent issel key lst mstr num opfile path pg pgn)
    2. (defun *error*(msg)
    3. (if opfile (close opfile))
    4. (prin1)
    5. )
    6. (setq path (strcat (Vla-Get-Path (Vlax-Get-Acad-Object)) "\\support\\MyCTB.txt"))
    7. (if (findfile path)
    8. (progn
    9. (setq opfile (open path "r") lst (read (read-line opfile)) pg (nth 0 lst) pgn (nth 1 lst) num (nth 2 lst) key (nth 3 lst) mstr (nth 4 lst) issel (nth 5 lst))
    10. (close opfile)
    11. )
    12. (setq pg 1 pgn 1 num 1 key nil mstr (strcat "页码自增:" (rtos pg)) issel nil)
    13. )
    14. (initget "M m G g S s C c")
    15. (while (setq ent (entsel (strcat "\n选择对象[页码自增或分页(M)/管线号自增(G)/管线号同号(S)/重置页码和管线号(C)]当前【" mstr "】>:")))
    16. (if (= (type ent) 'str)
    17. (progn
    18. (setq ent (strcat ent))
    19. (cond
    20. ((= ent "M")
    21. (if key
    22. (setq key nil pg (if issel (1+ pg) pg) mstr (strcat "页码自增:" (rtos pg)))
    23. (setq key "M" pg (if issel (1- pg) pg) mstr (strcat "页码分页:" (rtos pg) "-" (rtos pgn)))
    24. )
    25. )
    26. ((= ent "G") (setq key "G" mstr (strcat "管线号自增:" (rtos num))))
    27. ((= ent "S") (setq key "S" mstr (strcat "管线号同号:" (rtos num))))
    28. ((= ent "C")
    29. (setq pg 1 pgn 1 num 1 key nil mstr (strcat "页码自增:" (rtos pg)) issel nil)
    30. (write-line (vl-prin1-to-string (list pg pgn num key mstr issel)) (setq opfile (open path "w")))
    31. (close opfile)
    32. )
    33. )
    34. )
    35. (progn
    36. (setq edata (entget (car ent)))
    37. (cond
    38. ((= key nil)
    39. (setq pgn 1 issel nil)
    40. (entmod (subst (cons 1 (strcat "{\\W0.8;" (rtos pg) "}")) (assoc 1 edata) edata))
    41. (setq pg (1+ pg) mstr (strcat "页码自增:" (rtos pg)) )
    42. )
    43. ((= key "M")
    44. (setq issel T)
    45. (entmod (subst (cons 1 (strcat "{\\W0.8;" (rtos pg) "-" (rtos pgn) "}")) (assoc 1 edata) edata))
    46. (setq pgn (1+ pgn) mstr (strcat "页码分页:" (rtos pg) "-" (rtos pgn)))
    47. )
    48. ((= key "G")
    49. (entmod (subst (cons 1 (strcat "{\\fSimSun|b1|i1|c134|p2;" (rtos num) "}")) (assoc 1 edata) edata))
    50. (setq num (1+ num) mstr (strcat "管线号自增:" (rtos num)))
    51. )
    52. ((= key "S")
    53. (entmod (subst (cons 1 (strcat "{\\fSimSun|b1|i1|c134|p2;" (rtos num) "}")) (assoc 1 edata) edata))
    54. (setq mstr (strcat "管线号同号:" (rtos num)))
    55. )
    56. )
    57. )
    58. )
    59. (write-line (vl-prin1-to-string (list pg pgn num key mstr issel)) (setq opfile (open path "w")))
    60. (close opfile)
    61. (initget "M m G g S s C c")
    62. )
    63. (*error* nil)
    64. (prin1)
    65. )