iztok13 发表于 2022-7-6 15:12:46

如何读取垂直于f的多段线

你好
 
我有问题,使lsp文件,这将读取多边形x,y,z坐标顶点的txt文件命名的多段线。
我有一堆多段线,我需要用名称标记它们,并附上它们的x,y,z坐标。
所以基本上我需要选择polyline,然后必须问我polyline的名称,然后用名称和坐标x,y,z记录到txt文件中。我有很多,所以我需要被要求另一条多段线,一次又一次,并放在同一个txt文件中。
 
有什么建议吗?

Lee Mac 发表于 2022-7-6 15:18:29

也许是这个?
 

(defun c:plco (/ File oFile pLin pStr nlist pLen wLine)
   (if    (setq File (getfiled "Create a Text File" "C:\\" "txt" 9))
   (progn
       (setq oFile (open file "W"))
       (while (setq pLin (ssget ":S"
                  (list (cons 0 "LWPOLYLINE,POLYLINE")
                      (cons 410 (getvar "CTAB"))
                  ) ;_end list
               ) ;_end ssget
          ) ;_end setq
       (sssetfirst nil pLin)
       (if (/= (setq pStr (getstring t "\nSpecify Name for Selected Polyline >> ")) "")
         (progn (foreach x (entget (ssname pLin 0))
                  (if (eq 10 (car x))
                  (setq nlist (cons (cdr x) nlist))
                  ) ;_end if
            ) ;_end foreach
            (setq pLen (length nlist))
            (while (not (minusp (setq pLen (1- pLen))))
                  (setq wLine (strcat (rtos (car (nth pLen nlist)) 2 2)
                        ","
                        (rtos (cadr (nth pLen nlist)) 2 2)
                      ) ;_end strcat
                  ) ;_end setq
                  (if (caddr (nth pLen nlist))
                  (strcat wLine "," (rtos (caddr (nth pLen nlist)) 2 2))
                  ) ;_end if
            ) ;_end while
            (write-line (strcat pStr "\t" wLine) oFile)
         ) ;_end progn
         (princ "\n<!> No Line Name Specified. <!>")
       ) ;_end if
       (sssetfirst nil)
       ) ;_end while
       (close oFile)
   ) ;_end progn
   (princ "\n<!> No File Selected. <!> ")
   ) ;_end if
   (princ)
) ;_end defun


Lee Mac 发表于 2022-7-6 15:19:29

对不起,我错了,最初的帖子只能读第一个顶点。
 

(defun c:plco (/ File oFile pLin pStr nlist pLen wLine wfLine)
   (if    (setq File (getfiled "Create a Text File" "C:\\" "txt" 9))
   (progn
       (setq oFile (open file "W"))
       (while (setq pLin (ssget ":S" (list (cons 0 "LWPOLYLINE") (cons 410 (getvar "CTAB")))))
       (sssetfirst nil pLin)
       (if (/= (setq pStr (getstring t "\nSpecify Name for Selected Polyline >> ")) "")
         (progn (foreach x (entget (ssname pLin 0))
                  (if (eq 10 (car x))
                  (setq nlist (cons (cdr x) nlist))))
       (setq nlist (reverse nlist) pLen (length nlist) wfLine "")
            (while (not (minusp (setq pLen (1- pLen))))
                  (setq wLine (strcat (rtos (car (nth pLen nlist)) 2 2) ","
                        (rtos (cadr (nth pLen nlist)) 2 2)))
                  (if (caddr (nth pLen nlist))
                  (strcat wLine "," (rtos (caddr (nth pLen nlist)) 2 2)))
          (setq wfLine (strcat wLine "\t" wfLine))
            ) ;_end while
            (write-line (strcat pStr "\t" wfLine) oFile)
         ) ;_end progn
         (princ "\n<!> No Line Name Specified. <!>")
       ) ;_end if
       (sssetfirst nil)
       ) ;_end while
       (close oFile)
   ) ;_end progn
   (princ "\n<!> No File Selected. <!> ")
   ) ;_end if
   (princ))

CarlB 发表于 2022-7-6 15:23:45

李,
 
这段代码似乎不适用于“多段线”?我看到它们可以被选中,但代码似乎只对顶点使用组码10(因此适用于“lwpolylinwes”)。要获得规则(重量级)多段线的顶点,需要使用不同的方法,例如使用“entnext”单步执行。看到OP也要求z值,他甚至可能希望它适用于三维多段线。

Lee Mac 发表于 2022-7-6 15:26:09

对不起,卡尔,我会整理的。

Lee Mac 发表于 2022-7-6 15:29:16

好的,试试这个:
 

(defun c:plco (/ File oFile pLin pStr pEnt nlist pLen wLine wfLine vPt wvLine)
   (if    (setq File (getfiled "Create a Text File" "C:\\" "txt" 9))
   (progn
       (setq oFile (open file "W"))
       (while (setq pLin (ssget ":S" (list (cons 0 "LWPOLYLINE,POLYLINE") (cons 410 (getvar "CTAB")))))
       (sssetfirst nil pLin)
       (if (/= (setq pStr (getstring t "\nSpecify Name for Selected Polyline >> ")) "")
         (progn
         (setq pEnt (ssname pLin 0))
         (cond ((= "LWPOLYLINE" (cdr (assoc 0 (entget pEnt))))
                  (foreach    x (entget pEnt)
                  (if (eq 10 (car x))
                      (setq nlist (cons (cdr x) nlist))
                  ) ;_end if
                  ) ;_end foreach
                  (setq nlist(reverse nlist)
                  pLen   (length nlist)
                  wfLine ""
                  ) ;_end setq
                  (while (not (minusp (setq pLen (1- pLen))))
                  (setq wLine (strcat (rtos (car (nth pLen nlist)) 2 2)
                              ","
                              (rtos (cadr (nth pLen nlist)) 2 2)
                        ) ;_end strcat
                  ) ;_end setq
                  (setq wfLine (strcat wLine "\t" wfLine))
                  ) ;_end while
                  (write-line (strcat pStr "\t" wfLine) oFile)
               )
               ((= "POLYLINE" (cdr (assoc 0 (entget pEnt))))
                  (setq wvLine ""
                  pEnt   (entnext pEnt)
                  ) ;_end setq
                  (while (/= (cdr (assoc 0 (entget pEnt))) "SEQEND")
                  (setq vPt    (cdr (assoc 10 (entget pEnt)))
                  wvLine    (strcat    (rtos (car vPt) 2 2)
                           ","
                           (rtos (cadr vPt) 2 2)
                           ","
                           (rtos (caddr vPt) 2 2)
                           "\t"
                           wvLine
                     ) ;_end strcat
                  pEnt    (entnext pEnt)
                  ) ;_end setq
                  ) ;_end while
                  (write-line (strcat pStr "\t" wvLine) oFile)
               )
         ) ;_end cond
         ) ;_end progn
         (princ "\n<!> No Line Name Specified. <!>")
       ) ;_end if
       (sssetfirst nil)
       ) ;_end while
       (close oFile)
   ) ;_end progn
   (princ "\n<!> No File Selected. <!> ")
   ) ;_end if
   (princ)
) ;_end defun

iztok13 发表于 2022-7-6 15:34:12

thx李Mac,工作完美。这就是我需要的。再次使用thx

Lee Mac 发表于 2022-7-6 15:38:04

太好了,很高兴它对你有用。
 
为了处理3DPolyline,我不得不把它弄得有点乱,因为我通常只在2D中工作,但最终还是成功了

iztok13 发表于 2022-7-6 15:39:15

李·麦克:
 
很抱歉,它没有像一个魅力,我注意到,如果我有很多polyly,坐标变得混乱,基本上第一个多边形是好的,然后第二个多边形有2倍多的顶点,我试图纠正这一点,但我没有成功。
任何想法。&还有如果可以在坐标前面加上多边形的名字?
 
谢谢

Lee Mac 发表于 2022-7-6 15:44:20

我去看看
页: [1] 2
查看完整版本: 如何读取垂直于f的多段线