乐筑天下

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

[编程交流] 如何读取垂直于f的多段线

[复制链接]

5

主题

28

帖子

23

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-6 15:12:46 | 显示全部楼层 |阅读模式
你好
 
我有问题,使lsp文件,这将读取多边形x,y,z坐标顶点的txt文件命名的多段线。
我有一堆多段线,我需要用名称标记它们,并附上它们的x,y,z坐标。
所以基本上我需要选择polyline,然后必须问我polyline的名称,然后用名称和坐标x,y,z记录到txt文件中。我有很多,所以我需要被要求另一条多段线,一次又一次,并放在同一个txt文件中。
 
有什么建议吗?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:18:29 | 显示全部楼层
也许是这个?
 
  1. (defun c:plco (/ File oFile pLin pStr nlist pLen wLine)
  2.    (if    (setq File (getfiled "Create a Text File" "C:\" "txt" 9))
  3.    (progn
  4.        (setq oFile (open file "W"))
  5.        (while (setq pLin (ssget ":S"
  6.                     (list (cons 0 "LWPOLYLINE,POLYLINE")
  7.                       (cons 410 (getvar "CTAB"))
  8.                     ) ;_  end list
  9.                  ) ;_  end ssget
  10.           ) ;_  end setq
  11.        (sssetfirst nil pLin)
  12.        (if (/= (setq pStr (getstring t "\nSpecify Name for Selected Polyline >> ")) "")
  13.            (progn (foreach x (entget (ssname pLin 0))
  14.                   (if (eq 10 (car x))
  15.                   (setq nlist (cons (cdr x) nlist))
  16.                   ) ;_  end if
  17.               ) ;_  end foreach
  18.               (setq pLen (length nlist))
  19.               (while (not (minusp (setq pLen (1- pLen))))
  20.                   (setq wLine (strcat (rtos (car (nth pLen nlist)) 2 2)
  21.                           ","
  22.                           (rtos (cadr (nth pLen nlist)) 2 2)
  23.                       ) ;_  end strcat
  24.                   ) ;_  end setq
  25.                   (if (caddr (nth pLen nlist))
  26.                   (strcat wLine "," (rtos (caddr (nth pLen nlist)) 2 2))
  27.                   ) ;_  end if
  28.               ) ;_  end while
  29.               (write-line (strcat pStr "\t" wLine) oFile)
  30.            ) ;_  end progn
  31.            (princ "\n<!> No Line Name Specified. <!>")
  32.        ) ;_  end if
  33.        (sssetfirst nil)
  34.        ) ;_  end while
  35.        (close oFile)
  36.    ) ;_  end progn
  37.    (princ "\n<!> No File Selected. <!> ")
  38.    ) ;_  end if
  39.    (princ)
  40. ) ;_  end defun
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:19:29 | 显示全部楼层
对不起,我错了,最初的帖子只能读第一个顶点。
 
  1. (defun c:plco (/ File oFile pLin pStr nlist pLen wLine wfLine)
  2.    (if    (setq File (getfiled "Create a Text File" "C:\" "txt" 9))
  3.    (progn
  4.        (setq oFile (open file "W"))
  5.        (while (setq pLin (ssget ":S" (list (cons 0 "LWPOLYLINE") (cons 410 (getvar "CTAB")))))
  6.        (sssetfirst nil pLin)
  7.        (if (/= (setq pStr (getstring t "\nSpecify Name for Selected Polyline >> ")) "")
  8.            (progn (foreach x (entget (ssname pLin 0))
  9.                   (if (eq 10 (car x))
  10.                   (setq nlist (cons (cdr x) nlist))))
  11.        (setq nlist (reverse nlist) pLen (length nlist) wfLine "")
  12.               (while (not (minusp (setq pLen (1- pLen))))
  13.                   (setq wLine (strcat (rtos (car (nth pLen nlist)) 2 2) ","
  14.                           (rtos (cadr (nth pLen nlist)) 2 2)))
  15.                   (if (caddr (nth pLen nlist))
  16.                   (strcat wLine "," (rtos (caddr (nth pLen nlist)) 2 2)))
  17.           (setq wfLine (strcat wLine "\t" wfLine))
  18.               ) ;_  end while
  19.               (write-line (strcat pStr "\t" wfLine) oFile)
  20.            ) ;_  end progn
  21.            (princ "\n<!> No Line Name Specified. <!>")
  22.        ) ;_  end if
  23.        (sssetfirst nil)
  24.        ) ;_  end while
  25.        (close oFile)
  26.    ) ;_  end progn
  27.    (princ "\n<!> No File Selected. <!> ")
  28.    ) ;_  end if
  29.    (princ))
回复

使用道具 举报

0

主题

269

帖子

279

银币

限制会员

铜币
-4
发表于 2022-7-6 15:23:45 | 显示全部楼层
李,
 
这段代码似乎不适用于“多段线”?我看到它们可以被选中,但代码似乎只对顶点使用组码10(因此适用于“lwpolylinwes”)。要获得规则(重量级)多段线的顶点,需要使用不同的方法,例如使用“entnext”单步执行。看到OP也要求z值,他甚至可能希望它适用于三维多段线。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:26:09 | 显示全部楼层
对不起,卡尔,我会整理的。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:29:16 | 显示全部楼层
好的,试试这个:
 
  1. (defun c:plco (/ File oFile pLin pStr pEnt nlist pLen wLine wfLine vPt wvLine)
  2.    (if    (setq File (getfiled "Create a Text File" "C:\" "txt" 9))
  3.    (progn
  4.        (setq oFile (open file "W"))
  5.        (while (setq pLin (ssget ":S" (list (cons 0 "LWPOLYLINE,POLYLINE") (cons 410 (getvar "CTAB")))))
  6.        (sssetfirst nil pLin)
  7.        (if (/= (setq pStr (getstring t "\nSpecify Name for Selected Polyline >> ")) "")
  8.            (progn
  9.            (setq pEnt (ssname pLin 0))
  10.            (cond ((= "LWPOLYLINE" (cdr (assoc 0 (entget pEnt))))
  11.                   (foreach    x (entget pEnt)
  12.                   (if (eq 10 (car x))
  13.                       (setq nlist (cons (cdr x) nlist))
  14.                   ) ;_  end if
  15.                   ) ;_  end foreach
  16.                   (setq nlist  (reverse nlist)
  17.                     pLen   (length nlist)
  18.                     wfLine ""
  19.                   ) ;_  end setq
  20.                   (while (not (minusp (setq pLen (1- pLen))))
  21.                   (setq wLine (strcat (rtos (car (nth pLen nlist)) 2 2)
  22.                               ","
  23.                               (rtos (cadr (nth pLen nlist)) 2 2)
  24.                           ) ;_  end strcat
  25.                   ) ;_  end setq
  26.                   (setq wfLine (strcat wLine "\t" wfLine))
  27.                   ) ;_  end while
  28.                   (write-line (strcat pStr "\t" wfLine) oFile)
  29.                  )
  30.                  ((= "POLYLINE" (cdr (assoc 0 (entget pEnt))))
  31.                   (setq wvLine ""
  32.                     pEnt   (entnext pEnt)
  33.                   ) ;_  end setq
  34.                   (while (/= (cdr (assoc 0 (entget pEnt))) "SEQEND")
  35.                   (setq vPt    (cdr (assoc 10 (entget pEnt)))
  36.                     wvLine    (strcat    (rtos (car vPt) 2 2)
  37.                            ","
  38.                            (rtos (cadr vPt) 2 2)
  39.                            ","
  40.                            (rtos (caddr vPt) 2 2)
  41.                            "\t"
  42.                            wvLine
  43.                        ) ;_  end strcat
  44.                     pEnt    (entnext pEnt)
  45.                   ) ;_  end setq
  46.                   ) ;_  end while
  47.                   (write-line (strcat pStr "\t" wvLine) oFile)
  48.                  )
  49.            ) ;_  end cond
  50.            ) ;_  end progn
  51.            (princ "\n<!> No Line Name Specified. <!>")
  52.        ) ;_  end if
  53.        (sssetfirst nil)
  54.        ) ;_  end while
  55.        (close oFile)
  56.    ) ;_  end progn
  57.    (princ "\n<!> No File Selected. <!> ")
  58.    ) ;_  end if
  59.    (princ)
  60. ) ;_  end defun
回复

使用道具 举报

5

主题

28

帖子

23

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-6 15:34:12 | 显示全部楼层
thx李Mac,工作完美。这就是我需要的。再次使用thx
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:38:04 | 显示全部楼层
太好了,很高兴它对你有用。
 
为了处理3DPolyline,我不得不把它弄得有点乱,因为我通常只在2D中工作,但最终还是成功了
回复

使用道具 举报

5

主题

28

帖子

23

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-6 15:39:15 | 显示全部楼层
李·麦克:
 
很抱歉,它没有像一个魅力,我注意到,如果我有很多polyly,坐标变得混乱,基本上第一个多边形是好的,然后第二个多边形有2倍多的顶点,我试图纠正这一点,但我没有成功。
任何想法。&还有如果可以在坐标前面加上多边形的名字?
 
谢谢
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:44:20 | 显示全部楼层
我去看看
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 19:11 , Processed in 0.429202 second(s), 72 queries .

© 2020-2025 乐筑天下

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