乐筑天下

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

[编程交流] 按层划分的线交点

[复制链接]

2

主题

6

帖子

4

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 23:15:14 | 显示全部楼层 |阅读模式
大家好,
 
我的情况是,我有许多样条线在不同的层中。我将这些线与“0”层中的许多线相交。
 
我想能够提取x,y,z格式的交点。
 
我当前的步骤是选择我想要的曲线层,使用下面的lisp,对所有线重复,使用数据提取按层排序的x、y、z。
 
001519qrpl91l2d59n5lp0.jpg
 
当前,INTLINES查找任何直线的交点并在其中放置一个点。
 
我需要lisp在被相交的直线层中创建点?有人能帮我吗?
 
 
  1. (vl-load-com)
  2. ;;-----------------------------------------------
  3. ;; CDNC5-02.LSP
  4. ;; Bill Kramer
  5. ;; (modifications and enhancements by CAD Studio, www.cadstudio.cz , 2010-2014)
  6. ;;
  7. ;; ILSIMPLEMODE = T  for single intersection only  (large coord problem)
  8. ;;
  9. ;; Find all intersections between objects in
  10. ;; the selection set SS.
  11. ;;
  12. ;; ---------------------------------------------- BEGIN LISTING 1
  13. ;;
  14. (defun get_all_inters_in_SS (SS /
  15.                      SSL ;length of SS
  16.                      PTS ;returning list
  17.                      aObj1 ;Object 1
  18.                      aObj2 ;Object 2
  19.                      N1  ;Loop counter
  20.                      N2  ;Loop counter
  21.                      iPts ;intersects
  22.                          C1 C2 C3
  23.                      )
  24. (defun iL->L (iPts / Pts) ; convert coordlist -> pointlist
  25. (while (> (length iPts) 0)
  26. (setq Pts (cons (list        (car iPts)
  27.                                         (cadr iPts)
  28.                                         (caddr iPts))
  29.                                 Pts)
  30.     iPts (cdddr iPts)))
  31. Pts
  32. )
  33. (defun iL2->L (iPts / Pts) ; convert coordlist -> pointlist 2D
  34. (while (> (length iPts) 0)
  35. (setq Pts (cons (list        (car iPts)
  36.                                         (cadr iPts)
  37.                                         '0.0)
  38.                                 Pts)
  39.     iPts (cddr iPts)))
  40. Pts
  41. )
  42. (defun DelDup ( l / x r ) ; remove duplicates
  43.    (while l
  44.        (setq x (car l)
  45.              l (vl-remove x (cdr l))
  46.              r (cons x r)
  47.        )
  48.    )
  49.    (reverse r)
  50. )
  51. (setq N1 0 ;index for outer loop
  52. SSL (sslength SS))
  53. ; Outer loop, first through second to last
  54. (while (< N1 (1- SSL)) ;  nebo <= ?
  55.    ; Get object 1, convert to VLA object type
  56.    (setq aObj1 (ssname SS N1)
  57.   aObj1 (vlax-ename->vla-object aObj1)
  58.   N2 (1+ N1)) ;index for inner loop
  59.   ; self-intersections:
  60. (if (vlax-property-available-p aObj1 'Coordinates)(progn ; is it a curve? LWPOLY
  61.         (setq C1 (iL2->L (vlax-get aObj1 'Coordinates)))
  62.         (setq C2 (iL->L (vlax-invoke aObj1 'IntersectWith aObj1 0)))
  63.         (setq C3 (vl-remove-if '(lambda ( x ) (member x C1)) C2))
  64. ;                (PRINT C1)(PRINT C2)(PRINT C3)
  65.         (if C3 (foreach x C3 (setq Pts (cons x Pts)))) ; add selfs
  66. ))
  67. (if (= (vlax-get aObj1 'ObjectName) "AcDbSpline")(progn ; SPLINE
  68.         (setq C1 (iL->L (vlax-invoke aObj1 'IntersectWith aObj1 0)))
  69. ;                (PRINT C1)
  70.         (if C1 (foreach x C1 (setq Pts (cons x Pts)))) ; add selfs
  71. ))
  72.    ; Inner loop, go through remaining objects
  73.    (while (< N2 SSL) ; innser loop
  74.      ; Get object 2, convert to VLA object
  75.      (setq aObj2 (ssname SS N2)
  76.     aObj2 (vlax-ename->vla-object aObj2)
  77.     ; Find intersections of Objects
  78.     iPts (vla-intersectwith aObj1
  79.            aObj2 0)
  80.     ; variant result
  81.     iPts (vlax-variant-value iPts))
  82.      ; Variant array has values?
  83.      (if (> (vlax-safearray-get-u-bound iPts 1)
  84.      0)
  85. (progn ;array holds values, convert it
  86.   (setq iPts ;to a list.
  87.          (vlax-safearray->list iPts))
  88.   ;Loop through list constructing points
  89. ;          (setq Pts (iL->L iPts)) ; must be global
  90. ;(if (> (length iPts) 3)(PRINT iPts)) --- LIST DUPLICATE INTERSECTIONS - THE RED/GREEN CASE GIVES TWO INTERSECTIONS !
  91.   (while (> (length iPts) 0)
  92.     (setq Pts (cons (list (car iPts)
  93.                           (cadr iPts)
  94.                           (caddr iPts))
  95.                     Pts)
  96.           iPts (cdddr iPts))
  97.         (if ILSIMPLEMODE (setq iPts nil))  ; ILSIMPLEMODE - take only the first intersection
  98.   )
  99. ))
  100.      (setq N2 (1+ N2))) ;inner loop end
  101.    (setq N1 (1+ N1))) ;outer loop end
  102. Pts) ;return list of points found
  103. ;;-----------------------------------------------   END LISTING 1
  104. ;;
  105. ;; Remaining lines of code for download version, used to demonstrate and test the utility in Listing 1.
  106. ;;
  107. ;; Process - Create drawing with intersecting lines and lwpolylines.
  108. ;;           Load function set
  109. ;;           Run command function INTLINES
  110. ;;           Intersections are marked with POINT objects on current layer
  111. ;;
  112. (defun C:INTLINES ( / SS1 PT ptl oldos)
  113. (prompt "\nINTLINES running to demonstrate GET_ALL_INTERS_IN_SS function.")
  114. (setq SS1 (ssget);(ssget "_X");(get_all_lines_as_SS)
  115. PTS (get_all_inters_in_ss SS1)
  116.        )
  117. (setq ptl (length PTS)   PTS (deldup PTS)) ; duplicates - shouldn't be any
  118. (if (> ptl (length PTS)) (princ (strcat "\n" (itoa (- (length PTS) ptl)) " duplicates removed")))
  119. (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
  120. (setvar "CMDECHO" 0)
  121. (setq oldos (getvar "OSMODE"))(setvar "OSMODE" 0)
  122. (foreach PT PTS ;;Loop through list of points
  123.    (command "_POINT" PT)) ;;Create point object (you can also use INSERT, CIRCLE, etc. here)
  124. (setvar "PDMODE" 34) ;;display points so you can see them
  125. (command "_REGEN")
  126. (setvar "OSMODE" oldos)
  127. (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
  128. (princ (strcat (itoa (length PTS)) " intersections found."))
  129. (princ)
  130. )
  131. ;;
  132. ;;-----------------------------------------------
  133. ;;  Get all lines and lwpolyline objects in the
  134. ;;  drawing and return as a selection set.
  135. ;;
  136. (defun get_all_Lines_as_SS ()
  137. (ssget "_X" '((0 . "LINE,LWPOLYLINE"))))
  138. ;;
  139. (princ "\n(get_all_inters_in_SS) function and INTLINES command loaded.")
  140. (prin1)

 
或者,如果有人知道以特定间隔提取曲线x,y坐标的任何替代方法,我将非常感谢您的来信。
 
谨致问候,
 
ssredman公司
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

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

铜币
211
发表于 2022-7-5 23:22:58 | 显示全部楼层
它们是否已经存在直线和样条曲线?
回复

使用道具 举报

2

主题

6

帖子

4

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 23:26:38 | 显示全部楼层
样条线和垂直线已经存在。
 
我已经放置了垂直线,以便可以拉出足够数量的数据点。如果有一种提取点的替代方法,那么这些线将是不必要的,也不需要开始。
 
谢谢
 
001523qs3t3h9ndn0tfhtd.jpg
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

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

铜币
211
发表于 2022-7-5 23:32:53 | 显示全部楼层
点实体是否放置在给定距离上?或段数?
 
无论如何。。。在给定距离下尝试此提示。
 
  1. (defun c:pntat (/ dist splines i e layer pts sp ep d)
  2. (if (and (setq dist (getdist "\nEnter Segment Distance: ")
  3.          ds   dist
  4.    )
  5.    (setq splines (ssget '((0 . "SPLINE"))))
  6.      )
  7.    (repeat (setq i (sslength splines))
  8.      (setq e (ssname splines (setq i (1- i))))
  9.      (setq layer (cdr (assoc 8 (entget e))))
  10.      (setq pts        (list (vlax-curve-getStartPoint e)
  11.               (vlax-curve-getEndPoint e)
  12.         )
  13.      )
  14.      (setq pts        (if (< (Caar pts) (caadr pts))
  15.           pts
  16.           (reverse pts)
  17.         )
  18.      )
  19.      (setq sp (list (min (Caar pts) (caadr pts))
  20.              (setq y (min (cadar pts) (cadadr pts)))
  21.              0.0
  22.        )
  23.     ep (list (max (Caar pts) (caadr pts))
  24.              y
  25.              0.0
  26.        )
  27.     d  (distance sp ep)
  28.      )
  29.      (while (< dist d)
  30. (entmakex
  31.   (list        (cons 0 "POINT")
  32.         (cons 8 layer)
  33.         (cons 10
  34.               (vlax-curve-getClosestPointToProjection
  35.                 e
  36.                 (polar sp 0.0 dist)
  37.                 '(0 1 0)
  38.               )
  39.         )
  40.   )
  41. )
  42. (setq dist (+ dist ds))
  43.      )
  44.      (setq dist ds)
  45.    )
  46. )
  47. (princ)
  48. )

 
无论样条曲线的起点在哪里。距离始终是从左到右
 
HTH公司
回复

使用道具 举报

0

主题

301

帖子

301

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 23:37:19 | 显示全部楼层
埃德曼先生,
 
你真的需要你的点在恒定的x距离吗?
 
如果不是,请查看“vlax curve getPointAtDist”
 
这将为您提供曲线上31个点的列表:
 
[code](defun c:test()(if(setq en(car(entsel“\n选择多段线:)))(progn(setq dtot(vlax curve getDistAtPoint en(vlax curve getEndPoint en))dist(/dtot 30)pointlist nil cum 0)(而(
回复

使用道具 举报

2

主题

6

帖子

4

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 23:47:09 | 显示全部楼层
谢谢你,pBe,效果很好。
 
也感谢ymg3。
回复

使用道具 举报

3

主题

12

帖子

9

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-5 23:50:56 | 显示全部楼层
所以,为了找到两条直线或曲线之间的交点,我必须学习Lisp?AutoCAD中没有执行此任务的命令?
 
谢谢你的回答。
回复

使用道具 举报

0

主题

301

帖子

301

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 23:58:02 | 显示全部楼层
赫奇科,
 
对象捕捉到交点或明显交点即可
从命令行。不过,一次只能一点。
 
ymg公司
回复

使用道具 举报

3

主题

12

帖子

9

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-6 00:04:05 | 显示全部楼层
谢谢ymg3,首先我必须在工具栏中找到明显的交点。
回复

使用道具 举报

0

主题

301

帖子

301

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-6 00:07:11 | 显示全部楼层
它不在工具栏中,而是一个Osnap。
 
在命令中单击鼠标右键时,弹出菜单
将显示您选择的外观。
 
ymg公司
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-7 09:02 , Processed in 1.846732 second(s), 75 queries .

© 2020-2025 乐筑天下

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