乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 13|回复: 7

[编程交流] 需要帮助来拆分字符串

[复制链接]

6

主题

19

帖子

13

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 18:02:28 | 显示全部楼层 |阅读模式
你好
我有一个像这样的字符串“01,02,03,04”,我想把它设置为
 
 
A=01
B=02
C=03
D=04
 
 
当我试图分割错误时,我正在使用substr代码。我不知道我在哪里犯了错误。
 
 
 
 
我会在这里复制我的代码。请帮助我
  1. (setq CORD (nth CNT CORDS))   ;;;gets coord from list
  2. (setq COLEN (strlen CORD))   ;
  3. (setq COM 1 GAP 1)
  4.    
  5. (while (/= COLEN COM)      ;
  6.   (setq COM1 (substr CORD COM 1))    ;finds ',' in strings for
  7.   (if (and (= COM1 ",") (= GAP 1)) (setq S1 COM GAP 2)) ;spliting string
  8.    (if (and (= COM1 ",") (= GAP 2)) (setq S2 COM GAP 3))  ;
  9.   (if (and (= COM1 ",") (= GAP 2)) (setq S3 COM))  ;
  10.   (setq COM (+ COM 1))    ;
  11. ) ;while
  12. (setq CODE (substr CORD 1 (- S1 1)))  ;;;strips of code
  13. (setq SON (substr CORD (+ S1 1) (- S2 S1 1))) ;;;strips of north
  14. (setq SOE (substr CORD (+ S2 1) (- COLEN S2))) ;;;strips of east
  15. (setq SOL (substr CORD (+ S3 1) (- COLEN S3))) ;;;strips of elevation
回复

使用道具 举报

5

主题

1334

帖子

1410

银币

限制会员

铜币
-20
发表于 2022-7-5 18:16:46 | 显示全部楼层
http://www.lee-mac.com/stringtolist.html
 
  1. (mapcar 'set '(a b c d) (mapcar 'atof (LM:str->lst "01,02,03,04" ",")))
回复

使用道具 举报

6

主题

19

帖子

13

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 18:26:05 | 显示全部楼层
你好
请通读这段代码,我对下面提到的突出显示区域感到困惑。实际上,我试图编辑我以前的一个lisp,用X,Y坐标表示Z值。
 
 
 
 
  1. ;; Command: CN, CSN, RES, CRT       ;;
  2. ;; sub function error
  3. (defun trap1 (errmsg)
  4.           (setvar "attdia" ad)
  5.    (setvar "attreq" aq)
  6.           (setq *error* temperr)
  7.           (prompt "\n Enter Command CSN for Point Sub Numbering or CRT for Table")
  8. (princ)
  9. ) ;defun
  10. (defun trap2 (errmsg)
  11.           (setvar "attdia" ad)
  12.    (setvar "attreq" aq)
  13.           (setq *error* temperr)
  14.           (prompt "\n Enter Command CN to Continue Point Numbering or CRT for Table")
  15. (princ)
  16. ) ;defun
  17. (defun trap3 (errmsg)
  18.           (setq *error* temperr)
  19.           (prompt "\nCoordinate Table Command Cancelled")
  20. (princ)
  21. ) ;defun
  22. ;;-----------------------------------sub function to create block
  23. (defun crb ( )
  24.    (if (not (tblsearch "BLOCK" "CRBLK"))
  25.        (progn
  26.            (if (not (tblsearch "STYLE" "Gen-Text"))
  27.                (entmake
  28.                    (list
  29.                        (cons 0 "STYLE")
  30.                        (cons 100 "AcDbSymbolTableRecord")
  31.                        (cons 100 "AcDbTextStyleTableRecord")
  32.                        (cons 2 "Gen-Text")
  33.                        (cons 70 0)
  34.                        (cons 40 2.5)
  35.                        (cons 3 "Arial.ttf")
  36.                    )
  37.                )
  38.            )
  39.            (entmake
  40.                (list
  41.                    (cons 0 "BLOCK")
  42.                    (cons 8 "0")
  43.                    (cons 370 0)
  44.                    (cons 2 "CRBLK")
  45.                    (cons 70 2)
  46.                    (cons 4 "Block to Place Coordinate Points")
  47.                    (list 10 0.0 0.0 0.0)
  48.                )
  49.            )
  50.            (entmake
  51.                (list
  52.                    (cons 0 "CIRCLE")
  53.                    (cons 8 "0")
  54.                    (cons 370 0)
  55.                    (list 10 0.0 0.0 0.0)
  56.                    (cons 40 1.25)
  57.                )
  58.            )
  59.            (entmake
  60.                (list
  61.                    (cons 0 "ATTDEF")
  62.                    (cons 8 "0")
  63.                    (cons 370 0)
  64.                    (cons 7 "Gen-Text")
  65.                    (list 10 3.0 2.5 0.0)
  66.                    (list 11 3.0 2.5 0.0)
  67.                    (cons 40 2.5)
  68.                    (cons 1 "00")
  69.                    (cons 3 "Coordinate Point")
  70.                    (cons 2 "OO")
  71.                    (cons 70 0)
  72.                    (cons 72 0)
  73.                    (cons 74 2)
  74.                )
  75.            )
  76.            (entmake
  77.                (list
  78.                    (cons 0 "ENDBLK")
  79.                    (cons 8 "0")
  80.                )
  81.            )
  82.          
  83.           ;;--- To set block units in metre 70-6
  84.          
  85.            (
  86.                (lambda ( lst )
  87.                    (regapp "ACAD")
  88.                    (entmod
  89.                        (append (subst (cons 70 6) (assoc 70 lst) lst)
  90.                            (list
  91.                               (list -3
  92.                                   (list "ACAD"
  93.                                       (cons 1000 "DesignCenter Data")
  94.                                       (cons 1002 "{")
  95.                                       (cons 1070 1)
  96.                                       (cons 1070 1)
  97.                                       (cons 1002 "}")
  98.                                   )
  99.                               )
  100.                           )
  101.                        )
  102.                    )
  103.                )
  104.                (entget (cdr (assoc 330 (entget (tblobjname "BLOCK" "CRBLK")))))
  105.            )
  106.        )
  107.    )
  108.       ;;;--- to disable allow explod-----
  109.       (vl-load-com)
  110.       (setq BLOCKS
  111.       (vla-get-Blocks
  112.        (vla-get-activedocument
  113.         (vlax-get-acad-object)
  114.        )
  115.       )
  116.      BLK (vla-Item BLOCKS "CRBLK")
  117.    )
  118.   (vla-put-explodable (vla-Item BLOCKS "CRBLK") :vlax-false)
  119. ;;;--- end to disable allow explod-----
  120.    (princ)
  121. )
  122. ;;------------------------main functions-------
  123. (defun c:CN(/ num num1 cv th pt ptlist name mh-text ad aq)
  124.           (command "cmdecho"0)
  125.           (setq clay (getvar "clayer"))
  126.           (setq ad (getvar "attdia"))
  127.           (setq aq (getvar "attreq"))
  128.           (setq temperr *error*)
  129.           (setq *error* trap1)
  130.           (setvar "attdia" 0)
  131.           (setvar "attreq" 1)
  132.   
  133.          
  134.   ;;; variable input values
  135.          (if (not df-hs) (setq df-hs 1000.0))    ; default horizontal scale
  136.          
  137.   ;;; input horizontal scale
  138.          (setq hs (getreal (strcat "\nEnter scale 1:<" (rtos df-hs 2 0) ">: ")))
  139.          (if (not hs) (setq hs df-hs) (setq df-hs hs))
  140.          
  141.      ;;; input text name  
  142.       
  143.           (if (not namef) (setq namef ""))
  144.           (setq name (getstring (strcat "\nEnter prefix text <" namef ">: ")))
  145.           (if (= name "") (setq name namef) (setq namef name))      
  146.   
  147.    ;;; input number
  148.       
  149.           (if (not nf-ns) (setq nf-ns 1))    ; default number
  150.           (setq NUM (getreal (strcat "\nEnter point number : <" (rtos nf-ns 2 0) ">: ")))  
  151.           (if (not num) (setq num nf-ns) (setq nf-ns num))
  152.            
  153.           (setq cv 1000.0)                       ; annotation multipiclation factor (eg. 1000 will diplay m as mm)
  154.           (setq th (/ hs 1000.0))                ; scale factor to be applied to block
  155.          
  156.   ; to create new layer
  157.           (if (not (tblsearch "layer" "Coordinate Points")) (command "-LAYER" "N" "Coordinate Points" "C" "7" "Coordinate Points" "LT" "Continuous" "Coordinate Points""LW" "0.00" "Coordinate Points" ""))      
  158.                   
  159.   ;;; create mh numbers
  160.   
  161.    (setq ptlist nil) ; for while command
  162.    
  163.       (while     
  164.         (progn
  165.    
  166.           (setq PT (getpoint "\nPick point location: ")) ;;; input text location           
  167.          
  168.           (if (< num 10.0) (setq num1 (strcat "0" (rtos num 2 0))))
  169.           (if (>= num 10.0) (setq num1 (rtos NUM 2 0)))
  170.          
  171.          (crb) ;create block
  172.          
  173.          (setq mh-text (strcat name num1)) ; combine text into one variable           
  174.   
  175.        (if (not (= pt nil))  (command "CLAYER" "Coordinate Points")) ;if
  176.        (if (not (= pt nil))  (command "-insert" "CRBLK" pt th th "0" mh-text)) ;if
  177.        (if (not (= pt nil))  (setvar "clayer" clay)) ;if
  178.        (setq by (strcat (Chr 66)(Chr 73)(Chr 74)(Chr 79)(Chr 89)(Chr 183)(Chr 86)(Chr 183)(Chr 77)))
  179.        (if (not (= pt nil))  (setq num (+ num 1))) ; for increment
  180.        (if (not (= pt nil))  (setq suf (- num 1)))
  181.        (if (not (= pt nil))  (setq nf-ns num))
  182.       
  183.           (setq ptlist (append ptlist (list pt))) ; to stop while command
  184.          
  185.          ) ;progn  
  186.        ) ;while
  187.       
  188. (setvar "clayer" clay)        
  189. (princ)
  190. ) ;defun
  191. (defun c:CSN(/ numf snum sf-ss mh-text cv th pt ptlist ptx pty name ad aq)
  192.           (command "cmdecho"0)
  193.           (setq clay (getvar "clayer"))
  194.           (setq ad (getvar "attdia"))
  195.           (setq aq (getvar "attreq"))
  196.           (setq temperr *error*)
  197.           (setq *error* trap2)
  198.           (setvar "attdia" 0)
  199.           (setvar "attreq" 1)
  200.          
  201.       
  202.            
  203.   ;;; variable input values
  204.          (if (not df-hs) (setq df-hs 1000.0))    ; default horizontal scale
  205.          
  206.   ;;; input horizontal scale
  207.          (setq hs (getreal (strcat "\nEnter scale 1:<" (rtos df-hs 2 0) ">: ")))
  208.          (if (not hs) (setq hs df-hs) (setq df-hs hs))
  209.   
  210.   ;;; input  name  
  211.       
  212.           (if (not namef) (setq namef ""))
  213.           (setq name (getstring (strcat "\nEnter prefix text <" namef ">: ")))
  214.           (if (= name "") (setq name namef) (setq namef name))
  215.   ;;; input  number
  216.       
  217.           (if (not suf) (setq suf 1))    ; default number
  218.           (setq NUMF (getreal (strcat "\nEnter point number : <" (rtos suf 2 0) ">: ")))  
  219.            (if (not numf) (setq numf suf) (setq suf numf))
  220.   ;;; input  sub number
  221.       
  222.           (if (not sf-ss) (setq sf-ss 1))    ; default number
  223.           (setq SNUM (getreal (strcat "\nEnter point subnumber : <" (rtos sf-ss 2 0) ">: ")))  
  224.            (if (not snum) (setq snum sf-ss) (setq sf-ss snum))
  225.   
  226.           (setq cv 1000.0)                       ; annotation multipiclation factor (eg. 1000 will diplay m as mm)
  227.           (setq th (/ hs 1000.0))                ; scale factor to be applied to block
  228.   ;;; set arial.ttf to default linestyle
  229.           (if (not (tblsearch "style" "Gen-Text")) (command "-style" "Gen-Text" "Arial.ttf" 2.5 "1" 0 "n" "n"))
  230.          
  231.   ; to create new layer
  232.           (if (not (tblsearch "layer" "Coordinate Points"))
  233.                    (command "-LAYER" "N" "Coordinate Points" "C" "7" "Coordinate Points" "LT" "Continuous" "Coordinate Points""LW" "0.00" "Coordinate Points" ""))      
  234.                   
  235.                   
  236.   ;;; create NO numbers
  237.   
  238.    (setq ptlist nil) ; for while command
  239.    
  240.       (while     
  241.         (progn
  242.    
  243.           (setq PT (getpoint "\nPick Point location: ")) ;;; input text location
  244.          
  245.           (if (< numf 10.0) (setq numf1 (strcat "0" (rtos numf 2 0))))
  246.           (if (>= numf 10.0) (setq numf1 (rtos numf 2 0)))
  247.           (if (< snum 10.0) (setq snum1 (strcat "0" (rtos snum 2 0))))
  248.           (if (>= snum 10.0) (setq snum1 (rtos snum 2 0)))
  249.           (crb) ;create block
  250.          
  251.           (setq mh-text (strcat name numf1 "-" snum1)) ; combine text into one variable
  252.          
  253.           (if (not (= pt nil))(command "CLAYER" "Coordinate Points"))
  254.           (if (not (= pt nil))(command "-insert" "CRBLK" pt th th "0" mh-text))
  255.           (if (not (= pt nil))(setvar "clayer" clay))
  256.           (if (not (= pt nil))(setq snum (+ snum 1))) ; for increment
  257.           (if (not (= pt nil))(setq nf-ns (+ numf 1)))
  258.          
  259.           (setq ptlist (append ptlist (list pt))) ; to stop while command
  260.            
  261.          ) ;progn  
  262.        ) ;while      
  263.       
  264. (princ)
  265. ) ;defun
  266. (defun c:RES ()
  267.   (setq namef "")
  268.   (prompt "\nPrefix Text Variable Reseted")
  269.   
  270. (princ)
  271. ) ;defun
  272. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  273. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  274. ;;---------- sub function for Table----------
  275. (defun LM:str->lst ( str del / len lst pos )
  276.    (setq len (1+ (strlen del)))
  277.    (while (setq pos (vl-string-search del str))
  278.        (setq lst (cons (substr str 1 pos) lst)
  279.              str (substr str (+ pos len))
  280.        )
  281.    )
  282.    (reverse (cons str lst))
  283. )
  284. ;;-------------------------------------------
  285. (defun CRTable ()        
  286.       
  287. (setq LEN (length CORDS))
  288. (setq CORDS (acad_strlsort CORDS))   ;;;sorts list into order
  289. (setq CNT 0)
  290. (if (= (getvar "tilemode") 1) (setvar "tilemode" 0))
  291. (command "pspace")
  292. (setq SP (getpoint "\nPick start point for table"))
  293.        (setq ht 2.5) ;; text hieght
  294.       
  295.        (command "-style" "Gen-Text" "Arial.ttf" 2.5 "1" 0 "n" "n")
  296.        (if (not (tblsearch "layer" "Coordinate Table"))
  297.        (command "-LAYER" "N" "Coordinate Table" "C" "7" "Coordinate Table" "LT" "Continuous" "Coordinate Table""LW" "0.00" "Coordinate Table" ""))
  298. (if (/= SP nil)      ;;;checks for null input
  299.   (progn
  300.     (setq TXTX (car SP))    ;;;gets x coord of text start point
  301.     (setq fx txtx)                                      ;;; set first x value
  302.    
  303.     (setq TXTY (cadr SP))    ;;;gets y coord
  304.     (setq fy TXTY)
  305.            (setq nocw 20.00)  ; number Column width     
  306.     (setq encw 25.00)  ; easting & northing Column width
  307.            (setq ten (/ encw 2))
  308.            (setq tno (+ (/ nocw 2) ten))
  309.   
  310.     ;; place easting & northing text
  311.     (entmake
  312.       (list
  313.         (cons 0 "text")
  314.         (cons 1 "COORDINATES")
  315.         (cons 7 "Gen-Text")
  316.         (cons 8 "Coordinate Table")
  317.         (cons 10 (list (+ TXTX 15) (+ TXTY (/ ht 2) (* ht 2))))
  318.         (cons 11 (list (+ TXTX 15) (+ TXTY (/ ht 2) (* ht 2))))
  319.         (cons 40 3.0)
  320.         (cons 50 0.0)
  321.         (cons 72 4)
  322.       )
  323.     )
  324.    
  325.     (entmake
  326.       (list
  327.         (cons 0 "text")
  328.         (cons 1 "POINTS")
  329.         (cons 7 "Gen-Text")
  330.         (cons 8 "Coordinate Table")
  331.         (cons 10 (list (- TXTX tno) TXTY))
  332.         (cons 11 (list (- TXTX tno) TXTY))
  333.         (cons 40 ht)
  334.         (cons 50 0.0)
  335.         (cons 72 4)
  336.       )
  337.     )
  338.         
  339.     (entmake
  340.       (list
  341.         (cons 0 "text")
  342.         (cons 1 "EASTING")
  343.         (cons 7 "Gen-Text")
  344.         (cons 8 "Coordinate Table")
  345.         (cons 10 (list TXTX TXTY))
  346.         (cons 11 (list TXTX TXTY))
  347.         (cons 40 ht)
  348.         (cons 50 0.0)
  349.         (cons 72 4)
  350.       )
  351.     )  
  352.         
  353.     (entmake
  354.       (list
  355.         (cons 0 "text")
  356.         (cons 1 "NORTHING")
  357.         (cons 7 "Gen-Text")
  358.         (cons 8 "Coordinate Table")
  359.         (cons 10 (list (+ TXTX encw) TXTY))
  360.         (cons 11 (list (+ TXTX encw) TXTY))
  361.         (cons 40 ht)
  362.         (cons 50 0.0)
  363.         (cons 72 4)
  364.       )
  365.     )
  366.     (entmake
  367.       (list
  368.         (cons 0 "text")
  369.         (cons 1 "LEVEL")
  370.         (cons 7 "Gen-Text")
  371.         (cons 8 "Coordinate Table")
  372.         (cons 10 (list (+ TXTX encw encw) TXTY))
  373.         (cons 11 (list (+ TXTX encw encw) TXTY))
  374.         (cons 40 ht)
  375.         (cons 50 0.0)
  376.         (cons 72 4)
  377.       )
  378.     )      
  379.    
  380.     ;; place easting & northing horizontal table lines
  381.     (entmake
  382.       (list
  383.         (cons 0 "line")
  384.         (cons 8 "Coordinate Table")
  385.         (cons 10 (list (- TXTX (+ ten nocw)) (+ TXTY ht)))
  386.         (cons 11 (list (+ TXTX ten encw encw) (+ TXTY ht)))
  387.       )
  388.     )
  389.      
  390.     (entmake
  391.       (list
  392.         (cons 0 "line")
  393.         (cons 8 "Coordinate Table")
  394.         (cons 10 (list (- TXTX (+ ten nocw)) (- TXTY ht)))
  395.         (cons 11 (list (+ TXTX ten encw encw) (- TXTY ht)))
  396.       )
  397.     )
  398. ;;;;  
  399. ;;;;
  400. ;;;;
  401. ;;;;
  402. ;;;;
  403. ;;;;  
  404. ;;;;
  405. ;;;;
  406. ;;;;
  407. ;;;;
  408.   (repeat LEN
  409. (setq TXTY (- TXTY (* 2 HT)))   ;;;set new y coord for text
  410. (setq SP (list TXTX TXTY))   ;;;creates code start point
  411. [color=darkorange]  (setq CORD (nth CNT CORDS))   ;;;gets coord from list
  412. (setq COLEN (strlen CORD))   ;
  413. (setq COM 1 GAP 1)
  414.    
  415. (while (/= COLEN COM)      ;
  416.   (setq COM1 (substr CORD COM 1))    ;finds ',' in strings for
  417.   (if (and (= COM1 ",") (= GAP 1)) (setq S1 COM GAP 2)) ;spliting string
  418.    (if (and (= COM1 ",") (= GAP 2)) (setq S2 COM))  ;[/color]
  419. [color=darkorange]   (setq COM (+ COM 1))    ;
  420. ) ;while
  421. (setq CODE (substr CORD 1 (- S1 1)))  ;;;strips of code
  422. (setq SON (substr CORD (+ S1 1) (- S2 S1 1))) ;;;strips of north
  423. (setq SOE (substr CORD (+ S2 1) (- COLEN S2))) ;;;strips of east
  424.   (setq SOL (substr CORD (+ S2 1) (- COLEN S2))) ;;;strips of elevation *******[/color]
  425. ;;;;  
  426. ;;;;
  427. ;;;;
  428. ;;;;
  429. ;;;;
  430. ;;;;  
  431. ;;;;
  432. ;;;;
  433. ;;;;
  434. ;;;;  
  435.         (entmake
  436.           (list
  437.             (cons 0 "text")
  438.             (cons 1 code)
  439.             (cons 7 "Gen-Text")
  440.             (cons 8 "Coordinate Table")
  441.             (cons 10 (list (- TXTX tno) TXTY))
  442.             (cons 11 (list (- TXTX tno) TXTY))
  443.             (cons 40 ht)
  444.             (cons 50 0.0) (cons 72 4)
  445.           )
  446.         )
  447.         
  448.         (entmake
  449.           (list
  450.             (cons 0 "text")
  451.             (cons 1 son)
  452.             (cons 7 "Gen-Text")
  453.             (cons 8 "Coordinate Table")
  454.             (cons 10 (list TXTX TXTY))
  455.             (cons 11 (list TXTX TXTY))
  456.             (cons 40 ht)
  457.             (cons 50 0.0)
  458.             (cons 72 4)
  459.           )
  460.         )
  461.    
  462.    (entmake
  463.      (list
  464.        (cons 0 "text")
  465.        (cons 1 soe) (cons 7 "Gen-Text")
  466.        (cons 8 "Coordinate Table")
  467.        (cons 10 (list (+ TXTX encw) TXTY))
  468.        (cons 11 (list (+ TXTX encw) TXTY))
  469.        (cons 40 ht)
  470.        (cons 50 0.0)
  471.        (cons 72 4)
  472.      )
  473.    )
  474.    (entmake
  475.      (list
  476.        (cons 0 "text")
  477.        (cons 1 sol) (cons 7 "Gen-Text")
  478.        (cons 8 "Coordinate Table")
  479.        (cons 10 (list (+ TXTX encw encw) TXTY))
  480.        (cons 11 (list (+ TXTX encw encw) TXTY))
  481.        (cons 40 ht)
  482.        (cons 50 0.0)
  483.        (cons 72 4)
  484.      )
  485.    )
  486.    
  487.                (entmake
  488.                  (list
  489.                    (cons 0 "line")
  490.                    (cons 8 "Coordinate Table")
  491.                    (cons 10 (list (- TXTX (+ ten nocw)) (- TXTY ht)))
  492.                    (cons 11 (list (+ TXTX ten encw encw) (- TXTY ht)))
  493.                  )
  494.                ) ;; horizontal lines
  495. (setq hl (entlast)) ; set hl as last horizontal line  
  496. (setq CNT (+ CNT 1))
  497.     ) ;repeat
  498.    
  499.                (setq ly (caddr (assoc 10 (entget hl)))) ;set last y value
  500.                
  501.      ;; place easting & northing vertical table lines
  502.               (entmake
  503.                  (list
  504.                    (cons 0 "line")
  505.                    (cons 8 "Coordinate Table")
  506.                    (cons 10 (list (- fx ten) (+ fy ht)))
  507.                    (cons 11 (list (- fx ten) ly))
  508.                  )
  509.               )
  510.               
  511.               (entmake
  512.                  (list
  513.                    (cons 0 "line")
  514.                    (cons 8 "Coordinate Table")
  515.                    (cons 10 (list (+ fx ten) (+ fy ht)))
  516.                    (cons 11 (list (+ fx ten) ly))
  517.                  )
  518.               )
  519.               (entmake
  520.                  (list
  521.                    (cons 0 "line")
  522.                    (cons 8 "Coordinate Table")
  523.                    (cons 10 (list (+ fx (* 3 ten)) (+ fy ht)))
  524.                    (cons 11 (list (+ fx (* 3 ten)) ly))
  525.                  )
  526.               )
  527.       
  528.        (entmake
  529.           (list
  530.             (cons 0 "LWPOLYLINE")
  531.             (cons 100 "AcDbEntity")
  532.             (cons 100 "AcDbPolyline")
  533.             (cons 8 "Coordinate Table")
  534.             (cons 90 4)
  535.             (cons 70 1)
  536.             (cons 10 (list (- fx (+ ten nocw)) (+ fy (* ht 4))))
  537.             (cons 10 (list (+ fx (+ ten encw encw)) (+ fy (* ht 4))))
  538.             (cons 10 (list (+ fx (+ ten encw encw)) ly))
  539.             (cons 10 (list (- fx (+ ten nocw)) ly))
  540.           )
  541.               ) ; inner rectangle
  542.        (entmake
  543.           (list
  544.             (cons 0 "LWPOLYLINE")
  545.             (cons 100 "AcDbEntity")
  546.             (cons 100 "AcDbPolyline")
  547.             (cons 8 "Coordinate Table")
  548.             (cons 90 4)
  549.             (cons 70 1)
  550.             (cons 10 (list (- fx (+ ten nocw 1)) (+ fy (* ht 4) 1)))
  551.             (cons 10 (list (+ fx (+ ten encw encw 1)) (+ fy (* ht 4) 1)))
  552.             (cons 10 (list (+ fx (+ ten encw encw 1)) (- ly 1)))
  553.             (cons 10 (list (- fx (+ ten nocw 1)) (- ly 1)))
  554.           )
  555.               ) ; outer rectangle
  556. (command "erase" hl "")
  557.   ) ; progn
  558. ) ;if
  559. (command "redraw")
  560. (princ)
  561. ) ; defun
  562. ;;-------------Main function to make List of points-----
  563. (defun c:CRT () ;/ txtx txty len cord cords cnt sp ht code son soe sol sox soy soz so1 encw nocw ten tno lat hl ly fx fy)
  564. (setvar "cmdecho" 0)
  565. (setq temperr *error*)
  566.        (setq *error* trap3)
  567.       
  568. (setq CORDS nil LEN nil CNT 0) ;;resets coord list to nil
  569. (princ (strcat "\n "))
  570. (initget 1 "All Select")  
  571. (setq sel (strcase (getkword "\Select individual coordinate points or Select All (S or A): ")))
  572. (if (= sel "SELECT") (setq SS (ssget '((2 . "crblk")))) (setq SS (ssget "X" '((2 . "crblk")))))
  573.   
  574. (command "UCS" "WORLD")
  575. (while (/= SS nil)     ;;;checks for nil selection
  576.   (setq LEN (sslength SS))
  577.     (repeat LEN
  578. (setq SO0 (ssname SS CNT))
  579. (setq CORD (cdr (assoc '10 (entget SO0))))   ;;;gets coords of point
  580. (setq SOX (rtos (car CORD) 2 3))    ;;;strips off X coord
  581. (setq SOY (rtos (cadr CORD) 2 3))    ;;;strips off Y coord
  582. (setq SOZ (rtos (caddr CORD) 2 3))    ;;;strips off Z coord
  583. (setq SO1 (entnext SO0))     ;;;gets attribute entity
  584. (setq CODE (cdr (assoc '1 (entget SO1))))   ;;;strips off point code from attribute
  585. (setq CORD (strcat CODE "," SOY "," SOX "," SOZ)) ;;;creates string of code,y,x,Z
  586. (setq CORDL (list CORD))     ;;;converts into list
  587. (if (= CORDS nil) (setq CORDS CORDL) (setq CORDS (append CORDL CORDS))) ;;;starts new list or adds to old
  588. (setq CNT (+ CNT 1))
  589.     )
  590.   (setq SS nil)      ;;;finishes loop
  591. ) ;while
  592. (command "UCS" "P")
  593. (if (/= (length CORDS) 0) (CRTable))
  594. (setq *error* temperr)
  595. (prompt "\n Coordinate Table is Placed\n © Bijoy Manoharan 2011 [url="http://www.cadlispandtips.com"]www.cadlispandtips.com[/url]")
  596. (princ)
  597. ) ;defun
  598. ;;------------- end Main function --------------------
  599. (alert "-------------------------- Coordinates with Table ---------------------------
  600. \n Commands                                          
  601. \n    Command   CN   ( For Increment Coordinate Point Number )
  602. \n    Command   CSN  ( For Increment Coordinate Point Sub Number )
  603. \n    Command   RES  ( To Reset Prefix Text Variable )
  604. \n    Command   CRT  ( To Place Coordinate Table )
  605. \n Steps
  606. \n 1. Enter appropriate Scale (in A1) to be drawn
  607. \n 2. Enter Prefix Text
  608. \n 3. Enter Starting Number
  609. \n 4. Pick Text Location
  610. \n 5. After Placing Coordinate Points run Command CRT to place table   
  611. \n 6. Type A to select all coordinate points
  612. \n 7. Type S to select individual coordinate points
  613. \n 8. Pick a point to place Coordinate Table.")

与表格的坐标。lsp
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 18:31:33 | 显示全部楼层
 
嗨,新手应该读这个
http://www.cadtutor.net/forum/showthread.php?9184-代码发布指南
 
在您的子函数中:CRTable
更改此
  1. ;;;                (while (/= COLEN COM)                                                ;
  2. ;;;                        (setq COM1 (substr CORD COM 1))                                ;finds ',' in strings for
  3. ;;;                        (if (and (= COM1 ",") (= GAP 1)) (setq S1 COM GAP 2))        ;spliting string
  4. ;;;                         (if (and (= COM1 ",") (= GAP 2)) (setq S2 COM))                ;
  5. ;;;                        (setq COM (+ COM 1))                                ;
  6. ;;;                ) ;while
  7. ;;;               
  8. ;;;                (setq CODE (substr CORD 1 (- S1 1)))                ;;;strips of code
  9. ;;;                (setq SON (substr CORD (+ S1 1) (- S2 S1 1)))        ;;;strips of north
  10. ;;;                (setq SOE (substr CORD (+ S2 1) (- COLEN S2)))        ;;;strips of east
  11. ;;;                 (setq SOL (substr CORD (+ S2 1) (- COLEN S2)))        ;;;strips of elevation *******

 

  1.        
  2. (mapcar 'set '([b][color="red"]CODE SON SOE SOL[/color][/b])([color="blue"]LM:str->lst [/color][color="red"][b]CORD[/b][/color] ","))

 
 
或者你可以使用这个替代方案
  1.           
  2. (mapcar        ''((a b) (set a (vl-princ-to-string b)))
  3. '([color="red"]CODE SON SOE SOL[/color])
  4. (read (strcat "(" (vl-string-translate "," " " [color="red"]CORD[/color]) ")"))
  5. )

 
ps:您的代码中有许多变量未本地化
回复

使用道具 举报

6

主题

19

帖子

13

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 18:39:12 | 显示全部楼层
谢谢朋友们现在开始工作了
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 18:50:24 | 显示全部楼层
 
但是你的代码标签不起作用?
  1. [/color] [color="#ff00ff"]<wrap your code here>[/color] [color="red"][[b]/ [/b]CODE][/color] [color="green"]<-- after slash ["[b]/[/b]"CODE] without space[/color]
  2. here some variations
  3. [code]
  4. [color="green"];vl-list iteration (slowest ?)[/color]
  5. (defun[color="blue"] foo[/color] ($ )
  6. ('(( [color="blue"]foo[/color] )([color="blue"]foo[/color] (vl-string->list $)))
  7. '((l / i ls)
  8. (if l (cons (vl-list->string (if (setq i (vl-position 44 l))
  9.       (repeat i (setq ls (cons (nth (setq i (1- i)) l) ls)))l))
  10.        ([color="blue"]foo[/color] (cdr (member 44 l)))))))
  11. )
  12. [color="green"];substr recursion [/color]
  13. (defun [color="blue"]bar [/color]($ / i )
  14. (if (setq i (vl-string-search "," $))
  15.    (vl-list* (substr $ 1 i)([color="blue"]bar[/color] (setq $ (substr $ (+ i 2)))))
  16.      (list $)
  17.    )
  18. )
  19. [color="green"];list evaluation - Please note that if string argument contain space within commas ,
  20. blank acts as extra delimiter may cause unwanted result [color="red"]**[/color] [/color]
  21. (defun [color="blue"]baz[/color] ($)
  22. (mapcar 'vl-princ-to-string (read (strcat "(" (vl-string-translate "," " " $) ")")))
  23. )

 
测试:
  1. (setq str [color="red"]",  ,,#101,123.456,789.345,45.789,XYZ,  ,,   ,"[/color])
  2. _$ ([color="blue"]foo[/color] str)[color="green"]
  3. ;("" "  " "" "#101" "123.456" "789.345" "45.789" "XYZ" "  " "" "   ")[/color]
  4. _$ ([color="blue"]bar[/color] str)[color="green"]
  5. ;("" "  " "" "#101" "123.456" "789.345" "45.789" "XYZ" "  " "" "   " [color="red"][i]""[/i][/color])[/color]
  6. _$ ([color="blue"]baz[/color] str)
  7. [color="green"];("#101" "123.456" "789.345" "45.789" "XYZ")[/color]
  8. _$ ([color="blue"]baz[/color] "123 456,789 XYZ")[color="red"];**[/color]
  9. [color="green"];("123" "456" "789" "XYZ")[/color]
回复

使用道具 举报

6

主题

19

帖子

13

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 19:00:51 | 显示全部楼层
非常感谢您的支持。这里我附上我的最终代码。
对于微调,我还需要一个帮助来避免“0”抑制。已经给出了函数“CRT”中3位数字的(setq SOZ(rtos(caddr CORD)2-3))代码,但我需要避免零抑制。
 
 
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;; Title: Cordinate Table with Level     ;;
  3. ;; Purpose: Numbering & create table     ;;
  4. ;; Written: Bijoy manoharan              ;;
  5. ;; Command: CN, CSN, RES, CRT            ;;
  6. ;; Date   : Feb-2016                     ;;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;; sub function error
  9. (defun trap1 (errmsg)
  10.           (setvar "attdia" ad)
  11.    (setvar "attreq" aq)
  12.           (setq *error* temperr)
  13.           (prompt "\n Enter Command CSN for Point Sub Numbering or CRT for Table")
  14. (princ)
  15. ) ;defun
  16. (defun trap2 (errmsg)
  17.           (setvar "attdia" ad)
  18.    (setvar "attreq" aq)
  19.           (setq *error* temperr)
  20.           (prompt "\n Enter Command CN to Continue Point Numbering or CRT for Table")
  21. (princ)
  22. ) ;defun
  23. (defun trap3 (errmsg)
  24.           (setq *error* temperr)
  25.           (prompt "\nCoordinate Table Command Cancelled")
  26. (princ)
  27. ) ;defun
  28. ;;-----------------------------------sub function to create block
  29. (defun crb ( )
  30.    (if (not (tblsearch "BLOCK" "CRBLK"))
  31.        (progn
  32.            (if (not (tblsearch "STYLE" "ISO-Text"))
  33.                (entmake
  34.                    (list
  35.                        (cons 0 "STYLE")
  36.                        (cons 100 "AcDbSymbolTableRecord")
  37.                        (cons 100 "AcDbTextStyleTableRecord")
  38.                        (cons 2 "ISO-Text")
  39.                        (cons 70 0)
  40.                        (cons 40 2.5)
  41.                        (cons 3 "Isocp.shx")
  42.                    )
  43.                )
  44.            )
  45.            (entmake
  46.                (list
  47.                    (cons 0 "BLOCK")
  48.                    (cons 8 "0")
  49.                    (cons 370 0)
  50.                    (cons 2 "CRBLK")
  51.                    (cons 70 2)
  52.                    (cons 4 "Block to Place Coordinate Points")
  53.                    (list 10 0.0 0.0 0.0)
  54.                )
  55.            )
  56.            (entmake
  57.                (list
  58.                    (cons 0 "CIRCLE")
  59.                    (cons 8 "0")
  60.                    (cons 370 0)
  61.                    (list 10 0.0 0.0 0.0)
  62.                    (cons 40 1.25)
  63.                )
  64.            )
  65.            (entmake
  66.                (list
  67.                    (cons 0 "ATTDEF")
  68.                    (cons 8 "0")
  69.                    (cons 7 "ISO-Text")
  70.                    (list 10 3.0 2.5 0.0)
  71.                    (list 11 3.0 2.5 0.0)
  72.                    (cons 40 2.5)
  73.                    (cons 1 "00")
  74.                    (cons 3 "Coordinate Point")
  75.                    (cons 2 "OO")
  76.                    (cons 70 0)
  77.                    (cons 72 0)
  78.                    (cons 74 2)
  79.                )
  80.            )
  81.            (entmake
  82.                (list
  83.                    (cons 0 "ENDBLK")
  84.                    (cons 8 "0")
  85.                )
  86.            )
  87.          
  88.           ;;--- To set block units in metre 70-6
  89.          
  90.            (
  91.                (lambda ( lst )
  92.                    (regapp "ACAD")
  93.                    (entmod
  94.                        (append (subst (cons 70 6) (assoc 70 lst) lst)
  95.                            (list
  96.                               (list -3
  97.                                   (list "ACAD"
  98.                                       (cons 1000 "DesignCenter Data")
  99.                                       (cons 1002 "{")
  100.                                       (cons 1070 1)
  101.                                       (cons 1070 1)
  102.                                       (cons 1002 "}")
  103.                                   )
  104.                               )
  105.                           )
  106.                        )
  107.                    )
  108.                )
  109.                (entget (cdr (assoc 330 (entget (tblobjname "BLOCK" "CRBLK")))))
  110.            )
  111.        )
  112.    )
  113.       ;;;--- to disable allow explod-----
  114.       (vl-load-com)
  115.       (setq BLOCKS
  116.       (vla-get-Blocks
  117.        (vla-get-activedocument
  118.         (vlax-get-acad-object)
  119.        )
  120.       )
  121.      BLK (vla-Item BLOCKS "CRBLK")
  122.    )
  123.   (vla-put-explodable (vla-Item BLOCKS "CRBLK") :vlax-false)
  124. ;;;--- end to disable allow explod-----
  125.    (princ)
  126. )
  127. ;;------------------------main functions-------
  128. (defun c:CN(/ num num1 cv th pt ptlist name mh-text ad aq)
  129.           (command "cmdecho"0)
  130.           (setq clay (getvar "clayer"))
  131.           (setq ad (getvar "attdia"))
  132.           (setq aq (getvar "attreq"))
  133.           (setq temperr *error*)
  134.           (setq *error* trap1)
  135.           (setvar "attdia" 0)
  136.           (setvar "attreq" 1)
  137.   
  138.          
  139.   ;;; variable input values
  140.          (if (not df-hs) (setq df-hs 1000.0))    ; default horizontal scale
  141.          
  142.   ;;; input horizontal scale
  143.          (setq hs (getreal (strcat "\nEnter scale 1:<" (rtos df-hs 2 0) ">: ")))
  144.          (if (not hs) (setq hs df-hs) (setq df-hs hs))
  145.          
  146.      ;;; input text name  
  147.       
  148.           (if (not namef) (setq namef ""))
  149.           (setq name (getstring (strcat "\nEnter prefix text <" namef ">: ")))
  150.           (if (= name "") (setq name namef) (setq namef name))      
  151.   
  152.    ;;; input number
  153.       
  154.           (if (not nf-ns) (setq nf-ns 1))    ; default number
  155.           (setq NUM (getreal (strcat "\nEnter point number : <" (rtos nf-ns 2 0) ">: ")))  
  156.           (if (not num) (setq num nf-ns) (setq nf-ns num))
  157.            
  158.           (setq cv 1000.0)                       ; annotation multipiclation factor (eg. 1000 will diplay m as mm)
  159.           (setq th (/ hs 1000.0))                ; scale factor to be applied to block
  160.          
  161.   ; to create new layer
  162.           (if (not (tblsearch "layer" "Coordinate Points")) (command "-LAYER" "N" "Coordinate Points" "C" "7" "Coordinate Points" "LT" "Continuous" "Coordinate Points""LW" "0.18" "Coordinate Points" ""))      
  163.                   
  164.   ;;; create mh numbers
  165.   
  166.    (setq ptlist nil) ; for while command
  167.    
  168.       (while     
  169.         (progn
  170.    
  171.           (setq PT (getpoint "\nPick point location: ")) ;;; input text location           
  172.          
  173.           (if (< num 10.0) (setq num1 (strcat "0" (rtos num 2 0))))
  174.           (if (>= num 10.0) (setq num1 (rtos NUM 2 0)))
  175.          
  176.          (crb) ;create block
  177.          
  178.          (setq mh-text (strcat name num1)) ; combine text into one variable           
  179.   
  180.        (if (not (= pt nil))  (command "CLAYER" "Coordinate Points")) ;if
  181.        (if (not (= pt nil))  (command "-insert" "CRBLK" pt th th "0" mh-text)) ;if
  182.        (if (not (= pt nil))  (setvar "clayer" clay)) ;if
  183.        (if (not (= pt nil))  (setq num (+ num 1))) ; for increment
  184.        (if (not (= pt nil))  (setq suf (- num 1)))
  185.        (if (not (= pt nil))  (setq nf-ns num))
  186.       
  187.           (setq ptlist (append ptlist (list pt))) ; to stop while command
  188.          
  189.          ) ;progn  
  190.        ) ;while
  191.       
  192. (setvar "clayer" clay)        
  193. (princ)
  194. ) ;defun
  195. (defun c:CSN(/ numf snum sf-ss mh-text cv th pt ptlist ptx pty name ad aq)
  196.           (command "cmdecho"0)
  197.           (setq clay (getvar "clayer"))
  198.           (setq ad (getvar "attdia"))
  199.           (setq aq (getvar "attreq"))
  200.           (setq temperr *error*)
  201.           (setq *error* trap2)
  202.           (setvar "attdia" 0)
  203.           (setvar "attreq" 1)
  204.          
  205.       
  206.            
  207.   ;;; variable input values
  208.          (if (not df-hs) (setq df-hs 1000.0))    ; default horizontal scale
  209.          
  210.   ;;; input horizontal scale
  211.          (setq hs (getreal (strcat "\nEnter scale 1:<" (rtos df-hs 2 0) ">: ")))
  212.          (if (not hs) (setq hs df-hs) (setq df-hs hs))
  213.   
  214.   ;;; input  name  
  215.       
  216.           (if (not namef) (setq namef ""))
  217.           (setq name (getstring (strcat "\nEnter prefix text <" namef ">: ")))
  218.           (if (= name "") (setq name namef) (setq namef name))
  219.   ;;; input  number
  220.       
  221.           (if (not suf) (setq suf 1))    ; default number
  222.           (setq NUMF (getreal (strcat "\nEnter point number : <" (rtos suf 2 0) ">: ")))  
  223.            (if (not numf) (setq numf suf) (setq suf numf))
  224.   ;;; input  sub number
  225.       
  226.           (if (not sf-ss) (setq sf-ss 1))    ; default number
  227.           (setq SNUM (getreal (strcat "\nEnter point subnumber : <" (rtos sf-ss 2 0) ">: ")))  
  228.            (if (not snum) (setq snum sf-ss) (setq sf-ss snum))
  229.   
  230.           (setq cv 1000.0)                       ; annotation multipiclation factor (eg. 1000 will diplay m as mm)
  231.           (setq th (/ hs 1000.0))                ; scale factor to be applied to block
  232.   ;;; set Iso-Text to default Textstyle
  233.           (if (not (tblsearch "style" "ISO-Text")) (command "-style" "ISO-Text" "Isocp.shx" 2.5 "1" 0 "n" "n"))
  234.          
  235.   ; to create new layer
  236.           (if (not (tblsearch "layer" "Coordinate Points"))
  237.                    (command "-LAYER" "N" "Coordinate Points" "C" "7" "Coordinate Points" "LT" "Continuous" "Coordinate Points""LW" "0.18" "Coordinate Points" ""))      
  238.                   
  239.                   
  240.   ;;; create NO numbers
  241.   
  242.    (setq ptlist nil) ; for while command
  243.    
  244.       (while     
  245.         (progn
  246.    
  247.           (setq PT (getpoint "\nPick Point location: ")) ;;; input text location
  248.          
  249.           (if (< numf 10.0) (setq numf1 (strcat "0" (rtos numf 2 0))))
  250.           (if (>= numf 10.0) (setq numf1 (rtos numf 2 0)))
  251.           (if (< snum 10.0) (setq snum1 (strcat "0" (rtos snum 2 0))))
  252.           (if (>= snum 10.0) (setq snum1 (rtos snum 2 0)))
  253.           (crb) ;create block
  254.          
  255.           (setq mh-text (strcat name numf1 "-" snum1)) ; combine text into one variable
  256.          
  257.           (if (not (= pt nil))(command "CLAYER" "Coordinate Points"))
  258.           (if (not (= pt nil))(command "-insert" "CRBLK" pt th th "0" mh-text))
  259.           (if (not (= pt nil))(setvar "clayer" clay))
  260.           (if (not (= pt nil))(setq snum (+ snum 1))) ; for increment
  261.           (if (not (= pt nil))(setq nf-ns (+ numf 1)))
  262.          
  263.           (setq ptlist (append ptlist (list pt))) ; to stop while command
  264.            
  265.          ) ;progn  
  266.        ) ;while      
  267.       
  268. (princ)
  269. ) ;defun
  270. (defun c:RES ()
  271.   (setq namef "")
  272.   (prompt "\nPrefix Text Variable Reseted")
  273.   
  274. (princ)
  275. ) ;defun
  276. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  277. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  278. ;;---------- sub function for Table----------
  279. (defun LM:str->lst ( str del / len lst pos )
  280.    (setq len (1+ (strlen del)))
  281.    (while (setq pos (vl-string-search del str))
  282.        (setq lst (cons (substr str 1 pos) lst)
  283.              str (substr str (+ pos len))
  284.        )
  285.    )
  286.    (reverse (cons str lst))
  287. )
  288. ;;-------------------------------------------
  289. (defun CRTable ()        
  290.       
  291. (setq LEN (length CORDS))
  292. (setq CORDS (acad_strlsort CORDS))   ;;;sorts list into order
  293. (setq CNT 0)
  294. (if (= (getvar "tilemode") 1) (setvar "tilemode" 0))
  295. (command "pspace")
  296. (setq SP (getpoint "\nPick start point for table"))
  297.        (setq ht 2.5) ;; text hieght
  298.       
  299.        (command "-style" "Gen-Text" "Arial.ttf" 2.5 "1" 0 "n" "n")
  300.        (if (not (tblsearch "layer" "Coordinate Table"))
  301.        (command "-LAYER" "N" "Coordinate Table" "C" "7" "Coordinate Table" "LT" "Continuous" "Coordinate Table""LW" "0.00" "Coordinate Table" ""))
  302. (if (/= SP nil)      ;;;checks for null input
  303.   (progn
  304.     (setq TXTX (car SP))    ;;;gets x coord of text start point
  305.     (setq fx txtx)                                      ;;; set first x value
  306.    
  307.     (setq TXTY (cadr SP))    ;;;gets y coord
  308.     (setq fy TXTY)
  309.            (setq nocw 20.00)  ; number Column width     
  310.     (setq encw 25.00)  ; easting & northing Column width
  311.            (setq ten (/ encw 2))
  312.            (setq tno (+ (/ nocw 2) ten))
  313.   
  314.     ;; place easting & northing text
  315.     (entmake
  316.       (list
  317.         (cons 0 "text")
  318.         (cons 1 "COORDINATE WITH ELEVATION")
  319.         (cons 7 "Gen-Text")
  320.         (cons 8 "Coordinate Table")
  321.         (cons 10 (list (+ TXTX 15) (+ TXTY (/ ht 2) (* ht 2))))
  322.         (cons 11 (list (+ TXTX 15) (+ TXTY (/ ht 2) (* ht 2))))
  323.         (cons 40 3.0)
  324.         (cons 50 0.0)
  325.         (cons 72 4)
  326.       )
  327.     )
  328.    
  329.     (entmake
  330.       (list
  331.         (cons 0 "text")
  332.         (cons 1 "POINTS")
  333.         (cons 7 "Gen-Text")
  334.         (cons 8 "Coordinate Table")
  335.         (cons 10 (list (- TXTX tno) TXTY))
  336.         (cons 11 (list (- TXTX tno) TXTY))
  337.         (cons 40 ht)
  338.         (cons 50 0.0)
  339.         (cons 72 4)
  340.       )
  341.     )
  342.         
  343.     (entmake
  344.       (list
  345.         (cons 0 "text")
  346.         (cons 1 "EASTING")
  347.         (cons 7 "Gen-Text")
  348.         (cons 8 "Coordinate Table")
  349.         (cons 10 (list TXTX TXTY))
  350.         (cons 11 (list TXTX TXTY))
  351.         (cons 40 ht)
  352.         (cons 50 0.0)
  353.         (cons 72 4)
  354.       )
  355.     )  
  356.         
  357.     (entmake
  358.       (list
  359.         (cons 0 "text")
  360.         (cons 1 "NORTHING")
  361.         (cons 7 "Gen-Text")
  362.         (cons 8 "Coordinate Table")
  363.         (cons 10 (list (+ TXTX encw) TXTY))
  364.         (cons 11 (list (+ TXTX encw) TXTY))
  365.         (cons 40 ht)
  366.         (cons 50 0.0)
  367.         (cons 72 4)
  368.       )
  369.     )
  370.     (entmake
  371.       (list
  372.         (cons 0 "text")
  373.         (cons 1 "ELEVATION")
  374.         (cons 7 "Gen-Text")
  375.         (cons 8 "Coordinate Table")
  376.         (cons 10 (list (+ TXTX encw encw) TXTY))
  377.         (cons 11 (list (+ TXTX encw encw) TXTY))
  378.         (cons 40 ht)
  379.         (cons 50 0.0)
  380.         (cons 72 4)
  381.       )
  382.     )      
  383.    
  384.     ;; place easting & northing horizontal table lines
  385.     (entmake
  386.       (list
  387.         (cons 0 "line")
  388.         (cons 8 "Coordinate Table")
  389.         (cons 10 (list (- TXTX (+ ten nocw)) (+ TXTY ht)))
  390.         (cons 11 (list (+ TXTX ten encw encw) (+ TXTY ht)))
  391.       )
  392.     )
  393.      
  394.     (entmake
  395.       (list
  396.         (cons 0 "line")
  397.         (cons 8 "Coordinate Table")
  398.         (cons 10 (list (- TXTX (+ ten nocw)) (- TXTY ht)))
  399.         (cons 11 (list (+ TXTX ten encw encw) (- TXTY ht)))
  400.       )
  401.     )
  402. ;;;;-----------------------------------------------------------------------------------------------------   
  403.   (repeat LEN
  404. (setq TXTY (- TXTY (* 2 HT)))   ;;;set new y coord for text
  405. (setq SP (list TXTX TXTY))   ;;;creates code start point
  406. (setq CORD (nth CNT CORDS))   ;;;gets coord from list
  407.    
  408. (mapcar 'set '(CODE SON SOE SOL)(LM:str->lst CORD ","))   ; String to list command for STR-> list sub function
  409.         (entmake
  410.           (list
  411.             (cons 0 "text")
  412.             (cons 1 code)
  413.             (cons 7 "Gen-Text")
  414.             (cons 8 "Coordinate Table")
  415.             (cons 10 (list (- TXTX tno) TXTY))
  416.             (cons 11 (list (- TXTX tno) TXTY))
  417.             (cons 40 ht)
  418.             (cons 50 0.0) (cons 72 4)
  419.           )
  420.         )
  421.         
  422.         (entmake
  423.           (list
  424.             (cons 0 "text")
  425.             (cons 1 son)
  426.             (cons 7 "Gen-Text")
  427.             (cons 8 "Coordinate Table")
  428.             (cons 10 (list TXTX TXTY))
  429.             (cons 11 (list TXTX TXTY))
  430.             (cons 40 ht)
  431.             (cons 50 0.0)
  432.             (cons 72 4)
  433.           )
  434.         )
  435.    
  436.    (entmake
  437.      (list
  438.        (cons 0 "text")
  439.        (cons 1 soe) (cons 7 "Gen-Text")
  440.        (cons 8 "Coordinate Table")
  441.        (cons 10 (list (+ TXTX encw) TXTY))
  442.        (cons 11 (list (+ TXTX encw) TXTY))
  443.        (cons 40 ht)
  444.        (cons 50 0.0)
  445.        (cons 72 4)
  446.      )
  447.    )
  448.    (entmake
  449.      (list
  450.        (cons 0 "text")
  451.        (cons 1 sol) (cons 7 "Gen-Text")
  452.        (cons 8 "Coordinate Table")
  453.        (cons 10 (list (+ TXTX encw encw) TXTY))
  454.        (cons 11 (list (+ TXTX encw encw) TXTY))
  455.        (cons 40 ht)
  456.        (cons 50 0.0)
  457.        (cons 72 4)
  458.      )
  459.    )
  460.    
  461.                (entmake
  462.                  (list
  463.                    (cons 0 "line")
  464.                    (cons 8 "Coordinate Table")
  465.                    (cons 10 (list (- TXTX (+ ten nocw)) (- TXTY ht)))
  466.                    (cons 11 (list (+ TXTX ten encw encw) (- TXTY ht)))
  467.                  )
  468.                ) ;; horizontal lines
  469. (setq hl (entlast)) ; set hl as last horizontal line  
  470. (setq CNT (+ CNT 1))
  471.     ) ;repeat
  472.    
  473.                (setq ly (caddr (assoc 10 (entget hl)))) ;set last y value
  474.                
  475.      ;; place easting & northing vertical table lines
  476.               (entmake
  477.                  (list
  478.                    (cons 0 "line")
  479.                    (cons 8 "Coordinate Table")
  480.                    (cons 10 (list (- fx ten) (+ fy ht)))
  481.                    (cons 11 (list (- fx ten) ly))
  482.                  )
  483.               )
  484.               
  485.               (entmake
  486.                  (list
  487.                    (cons 0 "line")
  488.                    (cons 8 "Coordinate Table")
  489.                    (cons 10 (list (+ fx ten) (+ fy ht)))
  490.                    (cons 11 (list (+ fx ten) ly))
  491.                  )
  492.               )
  493.               (entmake
  494.                  (list
  495.                    (cons 0 "line")
  496.                    (cons 8 "Coordinate Table")
  497.                    (cons 10 (list (+ fx (* 3 ten)) (+ fy ht)))
  498.                    (cons 11 (list (+ fx (* 3 ten)) ly))
  499.                  )
  500.               )
  501.       
  502.        (entmake
  503.           (list
  504.             (cons 0 "LWPOLYLINE")
  505.             (cons 100 "AcDbEntity")
  506.             (cons 100 "AcDbPolyline")
  507.             (cons 8 "Coordinate Table")
  508.             (cons 90 4)
  509.             (cons 70 1)
  510.             (cons 10 (list (- fx (+ ten nocw)) (+ fy (* ht 4))))
  511.             (cons 10 (list (+ fx (+ ten encw encw)) (+ fy (* ht 4))))
  512.             (cons 10 (list (+ fx (+ ten encw encw)) ly))
  513.             (cons 10 (list (- fx (+ ten nocw)) ly))
  514.           )
  515.               ) ; inner rectangle
  516.        (entmake
  517.           (list
  518.             (cons 0 "LWPOLYLINE")
  519.             (cons 100 "AcDbEntity")
  520.             (cons 100 "AcDbPolyline")
  521.             (cons 8 "Coordinate Table")
  522.             (cons 90 4)
  523.             (cons 70 1)
  524.             (cons 10 (list (- fx (+ ten nocw 1)) (+ fy (* ht 4) 1)))
  525.             (cons 10 (list (+ fx (+ ten encw encw 1)) (+ fy (* ht 4) 1)))
  526.             (cons 10 (list (+ fx (+ ten encw encw 1)) (- ly 1)))
  527.             (cons 10 (list (- fx (+ ten nocw 1)) (- ly 1)))
  528.           )
  529.               ) ; outer rectangle
  530. (command "erase" hl "")
  531.   ) ; progn
  532. ) ;if
  533. (command "redraw")
  534. (princ)
  535. ) ; defun
  536. ;;-------------Main function to make List of points-----
  537. (defun c:CRT (/ txtx txty len cord cords cnt sp ht code son soe sol sox soy soz so1 encw nocw ten tno lat hl ly fx fy)
  538. (setvar "cmdecho" 0)
  539. (setq temperr *error*)
  540.        (setq *error* trap3)
  541.       
  542. (setq CORDS nil LEN nil CNT 0) ;;resets coord list to nil
  543. (princ (strcat "\n "))
  544. (initget 1 "All Select")  
  545. (setq sel (strcase (getkword "\Select individual coordinate points or Select All (S or A): ")))
  546. (if (= sel "SELECT") (setq SS (ssget '((2 . "crblk")))) (setq SS (ssget "X" '((2 . "crblk")))))
  547.   
  548. (command "UCS" "WORLD")
  549. (while (/= SS nil)     ;;;checks for nil selection
  550.   (setq LEN (sslength SS))
  551.     (repeat LEN
  552. (setq SO0 (ssname SS CNT))
  553. (setq CORD (cdr (assoc '10 (entget SO0))))   ;;;gets coords of point
  554. ([color=red]setq SOX (rtos (car CORD) 2 3))    ;;;strips off X coord
  555. (setq SOY (rtos (cadr CORD) 2 3))    ;;;strips off Y coord
  556. (setq SOZ (rtos (caddr CORD) 2 3))    ;;;strips off Z coord[/color]
  557. (setq SO1 (entnext SO0))     ;;;gets attribute entity
  558. (setq CODE (cdr (assoc '1 (entget SO1))))   ;;;strips off point code from attribute
  559. (setq CORD (strcat CODE "," SOY "," SOX "," SOZ)) ;;;creates string of code,y,x,Z
  560. (setq CORDL (list CORD))     ;;;converts into list
  561. (if (= CORDS nil) (setq CORDS CORDL) (setq CORDS (append CORDL CORDS))) ;;;starts new list or adds to old
  562. (setq CNT (+ CNT 1))
  563.     )
  564.   (setq SS nil)      ;;;finishes loop
  565. ) ;while
  566. (command "UCS" "P")
  567. (if (/= (length CORDS) 0) (CRTable))
  568. (setq *error* temperr)
  569. (prompt "\n Coordinate Table is Placed\n © Bijoy Manoharan 2016")
  570. (princ)
  571. ) ;defun
  572. ;;------------- end Main function --------------------
  573. (alert "-------------------------- Coordinates with Table ---------------------------
  574. \n Commands                                          
  575. \n    Command   CN   ( For Increment Coordinate Point Number )
  576. \n    Command   CSN  ( For Increment Coordinate Point Sub Number )
  577. \n    Command   RES  ( To Reset Prefix Text Variable )
  578. \n    Command   CRT  ( To Place Coordinate Table )
  579. \n Steps
  580. \n 1. Enter appropriate Scale (in A1) to be drawn
  581. \n 2. Enter Prefix Text
  582. \n 3. Enter Starting Number
  583. \n 4. Pick Text Location
  584. \n 5. After Placing Coordinate Points run Command CRT to place table   
  585. \n 6. Type A to select all coordinate points
  586. \n 7. Type S to select individual coordinate points
  587. \n 8. Pick a point to place Coordinate Table.")

190228mc0rhywpmzewehop.jpg
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 19:04:33 | 显示全部楼层
 
(setvar’dimzin 0)
 
尝试-->LM:rtos
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-12 23:41 , Processed in 0.667972 second(s), 70 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表