乐筑天下

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

[编程交流] 在多段线上创建顶点

[复制链接]

6

主题

19

帖子

13

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 15:36:13 | 显示全部楼层 |阅读模式
样本2。图纸
 
大家好,
 
我有六条折线,其中一条是闭合的。我需要在闭合多段线上创建顶点。随附样品图。要创建的顶点坐标是其他多段线的第一个顶点的坐标。
 
到目前为止,我只存储了一条多段线起始顶点的坐标。
 
  1. (vl-load-com)
  2. (setq s1 (car (entsel)))
  3. (setq pl (vlax-ename->vla-object s1))
  4. (defun vlax-list->2D-point  (lst)
  5. (if lst
  6.    (cons (list (car lst) (cadr lst))
  7.          (vlax-list->2D-point (cddr lst)))))
  8. (setq vertCoord(vlax-list->2D-point (vlax-get pl 'Coordinates)))
  9. (setq vertStart (car vertCoord))

 
谢谢你的帮助。
非常感谢。
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 15:43:06 | 显示全部楼层
如果多段线闭合,以下是3种不同类型的检查:
  1. (if (setq polyline (car (entsel)))
  2. (or
  3.    (= 1 (logand 1 (cdr (assoc 70 (entget polyline)))))
  4.    (vlax-curve-isClosed polyline)
  5.    (eq :vlax-true (vla-get-Closed (vlax-ename->vla-object polyline)))
  6. )
  7. )
回复

使用道具 举报

6

主题

19

帖子

13

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 15:50:25 | 显示全部楼层
 
有趣的方法可能会有所帮助。谢谢
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 15:57:05 | 显示全部楼层
打开或关闭的工程
 
  1. ; pline co-ords example
  2. ; By Alan H
  3. (defun getcoords (ent)
  4. (vlax-safearray->list
  5.    (vlax-variant-value
  6.      (vlax-get-property
  7.    (vlax-ename->vla-object ent)
  8.    "Coordinates"
  9.      )
  10.    )
  11. )
  12. )
  13. (defun co-ords2xy ()
  14. ; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
  15. (setq len (length co-ords))
  16. (setq numb (/ len 2)) ; even and odd check required
  17. (setq I 0)
  18. (repeat numb
  19. (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
  20. ; odd (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) ))
  21. (setq co-ordsxy (cons xy co-ordsxy))
  22. (setq I (+ I 2))
  23. )
  24. )
  25. ; program starts here
  26. (setq co-ords (getcoords (car (entsel "\nplease pick pline"))))
  27. (co-ords2xy) ; list of 2d points making pline
回复

使用道具 举报

58

主题

3353

帖子

33

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1761
发表于 2022-7-5 16:00:07 | 显示全部楼层
 
Fwiw。。你已经得到了一些大问题的完整解决方案。是时候开始学习钓鱼了,而不是期待一顿饭。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:06:10 | 显示全部楼层
下面是一个如何将顶点添加到多段线的示例。
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 16:09:09 | 显示全部楼层
OP创建了3个与此问题相关的主题。Ronjonp已经提供了一个解决方案。
回复

使用道具 举报

6

主题

19

帖子

13

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 16:16:51 | 显示全部楼层
 
你说得对,对不起。我刚刚接触AutoLISP,时间紧迫。但慢慢地掌握了Lisp程序的诀窍
回复

使用道具 举报

6

主题

19

帖子

13

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 16:24:46 | 显示全部楼层
 
谢谢,比格尔
回复

使用道具 举报

6

主题

19

帖子

13

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 16:30:40 | 显示全部楼层
 
谢谢你,李。我用的是你的AddLWPolylineVertexV1-0。lsp例程。你能解释一下你的代码吗?我理解不了。
我开始一行一行地分解程序
 
  1. ;;----------------=={ Add LWPolyline Vertex }==---------------;;
  2. ;;                                                            ;;
  3. ;;  Adds a new vertex to an LWPolyline at a point specified   ;;
  4. ;;  by the user; compatible with LWPolylines at any           ;;
  5. ;;  orientation, with varying width and arc segments.         ;;
  6. ;;------------------------------------------------------------;;
  7. ;;  Author: Lee Mac, Copyright © 2012 - www.lee-mac.com       ;;
  8. ;;------------------------------------------------------------;;
  9. ;;  Version 1.0    -    17-12-2012                            ;;
  10. ;;                                                            ;;
  11. ;;  First release.                                            ;;
  12. ;;------------------------------------------------------------;;
  13. (defun c:apv ( / a b e h l n p r w x z )
  14.    (while ;;inf loop
  15.        (progn (setq p (getpoint "\nPick Point for New Vertex: "))
  16.            (cond
  17.                (   (null p) nil) ;; 1st cond - if p not equal 0 return nil
  18.                (   (null (setq e (nentselp p))) ;; 2nd cond ? The nentselp function returns a 4×4 transformation matrix. What for?
  19.                    (princ "\nPoint does not lie on an LWPolyline.") ;; so if the returned matrix is empty (nil), print this
  20.                )
  21.                (   (= 4 (length e)) ;; 3rd cond - ??
  22.                    (princ "\nObject is Nested.") ;; what is nested object?
  23.                )
  24.                (   (/= "LWPOLYLINE" (cdr (assoc 0 (entget (setq e (car e)))))) ;; 4th cond - compare. If not equal...       
  25.                    (princ "\nObject is not an LWPolyline.") ;; ...print this
  26.                )
  27.            )
  28.        )
  29.    )
  30.    (if (and p e ;; expression returns T if both p and e are not nil, else nil
  31.            (setq p (vlax-curve-getclosestpointto e (trans p 1 0)) ;; the UCS is rotated 90 degrees counterclockwise around the WCS Z axis?? Closest point between e and rotated list
  32.                  n (vlax-curve-getparamatpoint e p) ;; still don't understand what getparamatpoint means
  33.            )
  34.        )
  35.        (if (not (equal n (fix n) 1e-) ;; checks if not equal - n and its truncated value with fuzz distance of 1e-8
  36.            (progn
  37.                (setq e (entget e)
  38.                      h (reverse (member (assoc 39 e) (reverse e))) ;; returns list consisting of 14 lists - what for?
  39.                      l (LM:LWVertices e)
  40.                      z (assoc 210 e)
  41.                )
  42.                (repeat (fix n)
  43.                    (setq a (cons (car l) a)
  44.                          l (cdr l)
  45.                    )
  46.                )
  47.                (setq x (car l)
  48.                      r (- n (fix n))
  49.                      w (cdr (assoc 40 x))
  50.                      w (+ w (* r (- (cdr (assoc 41 x)) w)))
  51.                      b (atan (cdr (assoc 42 x)))
  52.                )
  53.                (entmod
  54.                    (append h
  55.                        (apply 'append (reverse a))
  56.                        (list
  57.                            (assoc 10 x)
  58.                            (assoc 40 x)
  59.                            (cons  41 w)
  60.                            (cons  42 (tan (* r b)))
  61.                        )
  62.                        (list
  63.                            (cons  10 (trans p 0 (cdr z)))
  64.                            (cons  40 w)
  65.                            (assoc 41 x)
  66.                            (cons  42 (tan (* (- 1.0 r) b)))
  67.                        )
  68.                        (apply 'append (cdr l))
  69.                        (list z)
  70.                    )
  71.                )
  72.            )
  73.        )
  74.    )
  75.    (princ)
  76. )
  77. ;; Tangent  -  Lee Mac
  78. ;; Args: x - real
  79. (defun tan ( x )
  80.    (if (not (equal 0.0 (cos x) 1e-10))
  81.        (/ (sin x) (cos x))
  82.    )
  83. )
  84. ;; LW Vertices  -  Lee Mac
  85. ;; Returns a list of lists in which each sublist describes
  86. ;; the position, starting width, ending width and bulge of the
  87. ;; vertex of a supplied LWPolyline
  88. (defun LM:LWVertices ( e )
  89.    (if (setq e (member (assoc 10 e) e))
  90.        (cons
  91.            (list
  92.                (assoc 10 e)
  93.                (assoc 40 e)
  94.                (assoc 41 e)
  95.                (assoc 42 e)
  96.            )
  97.            (LM:LWVertices (cdr e))
  98.        )
  99.    )
  100. )
  101. (vl-load-com) (princ)
  102. ;;------------------------------------------------------------;;
  103. ;;                        End of File                         ;;
  104. ;;------------------------------------------------------------;;
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-1 10:50 , Processed in 0.356435 second(s), 72 queries .

© 2020-2025 乐筑天下

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