乐筑天下

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

[编程交流] 需要有关顶点的帮助

[复制链接]

17

主题

59

帖子

44

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
83
发表于 2022-7-5 20:06:14 | 显示全部楼层 |阅读模式
提前感谢您的帮助。
lisp无法提供我需要的所有应用程序,但我选择了多段线,并列出了所有点和包含多段线的半径
 
  1. (defun c:test1 ( ); / e i n s x
  2.    (if (setq s (ssget "x" '((0 . "LWPOLYLINE")(8 . "DDD"))))
  3.        (progn
  4.            (setq i 0
  5.                  n (sslength s)
  6.            )
  7.            (while (< i n)
  8.                (setq e (ssname s i)
  9.                      x (cdr (assoc 10 (entget e)))
  10.                                   i (1+ i)
  11.                )
  12.                (print x)
  13.                 );end wile
  14.        );end progn
  15.    );end if
  16.    (princ)
  17. );end defun

 
我找到了下面的代码,但我意识到不能更改,以帮助我,我需要给我的点多段线弧半径接近,但不是如果它包含
 
  1. (defun getPolySegs (/ ent entl p1 pt bulge seg ptlst)
  2. (setvar "ERRNO" 0)
  3. ;; repeat request for polyline until user either picks
  4. ;; a polyline or exits without picking
  5. (while (and (not ent) (/= (getvar "ERRNO") 52))
  6.    (if (and (setq ent (car (entsel "\nSelect polyline: ")))
  7.             (/= (cdr (assoc 0 (setq entl (entget ent)))) "LWPOLYLINE")
  8.        )
  9.      (setq ent nil)
  10.    )
  11. ); end while
  12. (cond (ent ;; save start point if polyline is closed
  13.         (if (= (logand (cdr (assoc 70 entl)) 1) 1)
  14.           (setq p1 (cdr (assoc 10 entl)))
  15.         )
  16.         ;; run thru entity list to collect list of segments
  17.         (while (setq entl (member (assoc 10 entl) entl))
  18.           ;; if segment then add to list
  19.           (if (and pt bulge)
  20.             (setq seg (list pt bulge))
  21.           ); end if
  22.           ;; save next point and bulge
  23.           (setq pt    (cdr (assoc 10 entl))
  24.                 bulge (cdr (assoc 42 entl))
  25.           )
  26.           ;; if segment is build then add last point to segment
  27.           ;; and add segment to list
  28.           (if seg
  29.             (setq seg (append seg (list pt))
  30.                   ptlst (cons seg ptlst))
  31.           ); end if
  32.           ;; reduce list and clear temporary segment
  33.           (setq entl  (cdr entl)
  34.                 seg   nil
  35.           )
  36.         ); end while
  37.        )
  38. ); end cond
  39. ;; if polyline is closed then add closing segment to list
  40. (if p1 (setq ptlst (cons (list pt bulge p1) ptlst)))
  41. ;; reverse and return list of segments
  42. (reverse ptlst)
  43. ); end defun

 
我还找到了lisp例程,列出半径,但没有点
 
 
  1. (defun getArcInfo (segment / a p1 bulge p2 c c|2 gamma midp p phi r r2 s theta)
  2. ;; assign variables to values in argument
  3. (mapcar 'set '(p1 bulge p2) segment)
  4. ;; find included angle
  5. ;; remember that bulge is negative if drawn clockwise
  6. (setq theta (* 4.0 (atan (abs bulge))))
  7. ;; output included angle
  8. (princ (strcat "\n Included angle: " (rtos theta)" rad ("(angtos theta 0)" degrees)"))
  9. ;; find height of the arc
  10. (setq c (distance p1 p2) s (* (/ c 2.0) (abs bulge)))
  11. ;; output height of arc
  12. (princ (strcat "\n Height of arc:  " (rtos s)))
  13. ;; output chord length
  14. (princ (strcat "\n Chord length:   " (rtos c)))
  15. ;; If this function is used without making sure that the segment
  16. ;; is not simply a line segment (bulge = 0.0), it will produce
  17. ;; a division-by-zero error in the following. Therefore we want
  18. ;; to be sure that it doesn't process line segments.
  19. (cond ((not (equal bulge 0.0 1E-6))
  20.         ;; find radius of arc
  21.         ;; first find half the chord length
  22.         (setq c|2 (/ c 2.0)
  23.               ;; find radius with Pythagoras (used as output)
  24.               r   (/ (+ (expt c|2 2.0) (expt s 2.0)) (* s 2.0))
  25.               ;; find radius with trigonometry
  26.               r2  (/ c|2 (sin (/ theta 2.0)))
  27.         )
  28.         (princ (strcat "\n Radius of arc:  " (rtos r)))
  29.         ;; find center point of arc with angle arithmetic
  30.         ;; (used as output)
  31.         (setq gamma (/ (- pi theta) 2.0)
  32.               phi   (if (>= bulge 0)
  33.                       (+ (angle p1 p2) gamma)
  34.                       (- (angle p1 p2) gamma)
  35.                     )
  36.               p     (polar p1 phi r)
  37.         )
  38.         ;; find center point of arc with Pythagoras
  39.         (setq a    (sqrt (- (expt r 2.0) (expt c|2 2.0)))
  40.               midp (polar p1 (angle p1 p2) c|2)
  41.               p2   (if (>= bulge 0)
  42.                      (polar midp (+ (angle p1 p2) (/ pi 2.0)) a)
  43.                      (polar midp (- (angle p1 p2) (/ pi 2.0)) a)
  44.                    )
  45.         )
  46.         ;; output coordinates of center point
  47.         (princ (strcat "\n Center of arc:  "(rtos (car p))","(rtos (cadr p))))
  48.        )
  49.        (T (princ "\n Segment has no arc info"))
  50. )
  51. (princ)
  52. )
  53. (defun c:POLYARCS (/ a polysegs seg)
  54. ;; make a list of polyline segments of a
  55. ;; selected polyline
  56. (cond ((setq polysegs (getPolySegs))
  57.         ;; a is just an informative counter
  58.         (setq a 0)
  59.                 ;; run thru each segment
  60.         (foreach seg polysegs
  61.           (setq a (1+ a))
  62.                   ;; only process the segment if it's an arc
  63.                   ;; i.e. bulge /= 0.0
  64.           (cond ((not (zerop (cadr seg)))
  65.                  (princ (strcat "\nSegment " (itoa a) ": "))
  66.                                         ;;
  67.                  (getArcInfo seg)
  68.                 )
  69.           )
  70.         )
  71.        )
  72. )
  73. )

 
但没能把它们放在一个Lisp程序的地方一起做,
我需要给我一个lisp,所有点和半径,都在一个列表中闭合多段线
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 22:05:43 | 显示全部楼层
只需根据下面的代码添加另一个defun,VLISP支持将坐标作为属性,就像长度和面积一样。
 
  1. (defun plcords (/ ent obj plobs )
  2. (vla-load-com)
  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 ( / I)
  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 numb (/ (length co-ords) 2))
  16. (setq I 0)
  17. (repeat numb
  18. (setq xy (list (nth (+ I 1) co-ords)(nth I co-ords) ))
  19. (setq coordsxy (cons xy coordsxy))
  20. (setq I (+ I 2))
  21. ) ; end repeat
  22. )
  23. (setq plobjs (ssget (list (cons 0 "lwpolyline"))))
  24. (setq numb1 (sslength plobjs))
  25. (setq x numb1)
  26. (repeat numb1
  27. (setq obj (ssname plobjs (setq x (- x 1))))
  28. (setq co-ords (getcoords obj))
  29. )
  30. (co-ords2xy)
  31. (setq inc (length coordsxy))
  32. (repeat (/ inc  2)
  33. (setq x (rtos (nth (setq inc (- inc 1)) co-ords) 2 3 ))
  34. (setq y (rtos (nth (setq inc (- inc 1)) co-ords) 2 3 ))  
  35. (setq xy (strcat x "," y ))
  36. (princ xy)
  37. (princ "\n ")
  38. )
  39. )
  40. (plcords)
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 08:52 , Processed in 0.657403 second(s), 56 queries .

© 2020-2025 乐筑天下

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