kiethchung 发表于 2022-9-18 08:10:49

我想编辑 pcode.lsp 在 AutoCAD 中显示点号。可以帮忙 ?

我想编辑 pcode.lsp 在 AutoCAD 中显示点号。可以帮忙 ?
(defun c:pcode (/ *error* fn f l p ok lay XYZ RL CODE )
         (defun *error* (msg)
         (if    (and f (= (type f) 'FILE))
             (close f) ;close the file
             ) ;_ end of if
         ) ;_ end of defun
         
         (if (and (setq fn (getfiled "\n" "" "csv;pnt;txt;*" 16)) ; get csv file
         (setq f (open fn "r"))
         ) ;_ end of and
         (progn
         (while (setq $ (read-line f))
             (setq l (read (strcat "( " (vl-string-translate "," " " $) " )"))) ; retriction layer/pcode without spacing
             (if (setq ok (= (length l) 5)) ; format = '( p x y z d )
      (progn (foreach x (list car last)
             (setq l (subst (vl-princ-to-string (x l)) (x l) l)))
               (if (and    (setq lay (last l)
                      p      (vl-remove-if-not 'numberp (cdr l))
                      ) ;_ end of setq
                (= 3 (length p)) ; format = '( x y z )
                (setq p (trans p 1 0)) ; convert point to ucs
                ) ;_ end of and
             (foreach xyz '(
                              (list
                     '(0 . "POINT")
                     (cons 8 "XYZ") ;(cons 8 "POINT")
                     (cons 10 p)
                     )
                     )
               (entmakex (eval xyz)) ; create text & point entity foreach supplied dxf data
               (foreach RL '(
                              (list
                     '(0 . "TEXT")
                     (cons 8 "RL")
                     (cons 10 p)
                     (cons 1 (rtos (caddr p) 2 2))
                     (cons 40 (getvar 'textsize))
                  (cons 11 p)
                  (cons 71 0) ;Flags 0=Normal, 2=Backward, 4=Upside down
                  (cons 72 2) ;Horizontal text justification,0=Left,1=Center,2=Right,4=Center,5=Fit
                  (cons 73 1) ;Vertical text justification, 0=Baseline,1=Bottom,2=Middle,3=Top
      
                     )
                     )
               (entmakex (eval RL)) ; create text & point entity foreach supplied dxf data
               (foreach code '(
                              (list
                     '(0 . "TEXT")
                     (cons 8 "CODE")
                     (cons 10 p)
                     (cons 1 (strcat lay))
                     (cons 40 (getvar 'textsize))
                  (cons 11 p)
                  (cons 71 0) ;Flags 0=Normal, 2=Backward, 4=Upside down
                  (cons 72 2) ;Horizontal text justification,0=Left,1=Center,2=Right,4=Center,5=Fit
                  (cons 73 3) ;Vertical text justification, 0=Baseline,1=Bottom,2=Middle,3=Top
                     )
                     )
               (entmakex (evalcode)) ; create text & point entity foreach supplied dxf data
      (foreach PTNO '(
                              (list
                     '(0 . "TEXT")
                     (cons 8 "PTNO")
                     (cons 10 p)
                     (cons 1 (strcat ptnum));HOW TO ADD POINT NUMBER
                     (cons 40 (getvar 'textsize))
                  (cons 11 p)
                  (cons 71 0) ;Flags 0=Normal, 2=Backward, 4=Upside down
                  (cons 72 2) ;Horizontal text justification,0=Left,1=Center,2=Right,4=Center,5=Fit
                  (cons 73 1) ;Vertical text justification, 0=Baseline,1=Bottom,2=Middle,3=Top
                     )
                     )
               (entmakex (evalPTNO)) ; create text & point entity foreach supplied dxf data
      
      ) ;_ end of foreach
      ) ;_ end of foreach
      ) ;_ end of foreach
      ) ;_ end of foreach
             ) ;_ end of if
               ) ;_ end of progn
      (setq $ nil) ; exit invalid format
      ) ;_ end of if
             ) ;_ end of while
      (if (not ok)(alert "Invalid format! Should be PXYZD"))
         )
               ) ;_ end of if
         (if (and f (= (type f) 'FILE))
         (close f) ;close the file
         ) ;_ end of if
         (princ)
         ) ;_ end of defun

BIGAL 发表于 2022-9-18 09:17:43

看看
页: [1]
查看完整版本: 我想编辑 pcode.lsp 在 AutoCAD 中显示点号。可以帮忙 ?