乐筑天下

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

[编程交流] 创建施工线

[复制链接]

9

主题

23

帖子

14

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-5 16:31:10 | 显示全部楼层 |阅读模式
大家好,
 
我想知道你是否可以帮我,我有这个代码(如下),
当用户选择两条线时,它会在它们之间创建另一条线,但当您选择构造线时,它不起作用,
 
你能把这个也修好用在施工线上吗?
 
非常感谢。
埃亚尔
 
  1. ;;  LineBetween.lsp [command name: LB]
  2. ;;  To draw a Line whose endpoints are halfway Between those of two
  3. ;;    User-selected Lines or Polyline [of any variety] line segments.
  4. ;;  Draws Line on current Layer.
  5. ;;  Accounts for Lines or Polyline line segments running generally in
  6. ;;    same or opposite directions, and for 3rd dimension if applicable.
  7. ;;  May draw Line between "wrong" halfway-between points if objects
  8. ;;    cross, or if one crosses their apparent intersection, because routine
  9. ;;    has no way to judge which possibility is expected -- try reversing
  10. ;;    one object to get "right" result.
  11. ;;  Result will not necessarily lie along angle bisector between selected
  12. ;;    objects; will do so only if objects' relationship is symmetrical.
  13. ;;  Kent Cooper, 5 March 2013
  14. (defun C:LB ; = Line Between
  15. (/ *error* noZ svnames svvals esel ent edata etype pick s1 e1 s2 e2 int)
  16. (defun *error* (errmsg)
  17.    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
  18.      (princ (strcat "\nError: " errmsg))
  19.    ); if
  20.    (command "_.undo" "_end")
  21.    (mapcar 'setvar svnames svvals)
  22.    (princ)
  23. ); defun - *error*
  24. (defun noZ (pt) (list (car pt) (cadr pt)))
  25. (setq
  26.    svnames '(cmdecho aperture); = System Variable NAMES
  27.    svvals (mapcar 'getvar svnames); = System Variable VALueS
  28. ); setq
  29. (mapcar 'setvar svnames (list 0 (getvar 'pickbox)))
  30.    ; aperture = pickbox to prevent Osnap Center seeing wrong object
  31. (command "_.undo" "_begin")
  32. (foreach num '("1" "2")
  33.    (while
  34.      (not
  35.        (and
  36.          (setq esel (entsel (strcat "\nSelect Line/Polyline line segment #" num ": ")))
  37.          (setq
  38.            ent (car esel)
  39.            edata (entget ent)
  40.            etype (cdr (assoc 0 edata))
  41.            pick (osnap (cadr esel) "nea"); for (vlax-curve-...) later
  42.          ); setq
  43.          (wcmatch etype "LINE,*POLYLINE")
  44.          (not (osnap pick "_cen")); if Polyline, not fit-curved or on arc segment
  45.          (if (= etype "POLYLINE") (= (boole 1 4 (cdr (assoc 70 edata))) 0) T)
  46.            ; not spline-curved 2D "heavy" or 3D Polyline [T for Line]
  47.        ); and
  48.      ); not
  49.      (prompt "\nNothing, or Polyline curve, or invalid object type, selected --")
  50.    ); while
  51.    (set (read (strcat "s" num)); s1 or s2 [start]
  52.      (if (= etype "LINE")
  53.        (cdr (assoc 10 edata)); then
  54.        (vlax-curve-getPointAtParam ent (fix (vlax-curve-getParamAtPoint ent pick))); else
  55.      ); if
  56.    ); set
  57.    (set (read (strcat "e" num)); e1 or e2 [end]
  58.      (if (= etype "LINE")
  59.        (cdr (assoc 11 edata)); then
  60.        (vlax-curve-getPointAtParam ent (1+ (fix (vlax-curve-getParamAtPoint ent pick)))); else
  61.      ); if
  62.    ); set
  63. ); foreach
  64. (setq int (inters (noZ s1) (noZ s2) (noZ e1) (noZ e2))); T or nil -- opposite directions
  65. (entmake
  66.    (list
  67.      '(0 . "LINE")
  68.      (cons 10 (mapcar '/ (mapcar '+ s1 (if int e2 s2)) '(2 2 2)))
  69.      (cons 11 (mapcar '/ (mapcar '+ e1 (if int s2 e2)) '(2 2 2)))
  70.    ); list
  71. ); entmake
  72. (command "_.undo" "_end")
  73. (mapcar 'setvar svnames svvals)
  74. (princ)
  75. ); defun
  76. (prompt "\nType LB to draw a Line halfway Between two Lines/Polyline line segments.")
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:43:18 | 显示全部楼层
以下内容将构造一个XLine平分线:
  1. ;; XLine Bisector  -  Lee Mac
  2. ;; Constructs an XLine bisector between two selected XLines
  3. (defun c:xlb ( / int pt1 pt2 vc1 vc2 xl1 xl2 )
  4.    (if (and (setq xl1 (LM:selectifobject "\nSelect 1st xline: " "XLINE"))
  5.             (setq xl2 (LM:selectifobject "\nSelect 2nd xline: " "XLINE"))
  6.        )
  7.        (entmake
  8.            (vl-list*
  9.               '(000 . "XLINE")
  10.               '(100 . "AcDbEntity")
  11.               '(100 . "AcDbXline")
  12.                (if (setq xl1 (entget xl1)
  13.                          xl2 (entget xl2)
  14.                          pt1 (cdr (assoc 10 xl1))
  15.                          pt2 (cdr (assoc 10 xl2))
  16.                          vc1 (cdr (assoc 11 xl1))
  17.                          vc2 (cdr (assoc 11 xl2))
  18.                          int (inters (trans pt1 0 1) (trans (mapcar '+ pt1 vc1) 0 1) (trans pt2 0 1) (trans (mapcar '+ pt2 vc2) 0 1) nil)
  19.                    )
  20.                    (list
  21.                        (cons 10 (trans int 1 0))
  22.                        (cons 11 (mapcar (if (< (distance vc1 vc2) (distance vc1 (mapcar '- vc2))) '+ '-) vc1 vc2))
  23.                    )
  24.                    (list
  25.                        (cons 10 (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) pt1 pt2))
  26.                        (cons 11 vc1)
  27.                    )
  28.                )
  29.            )
  30.        )
  31.    )
  32.    (princ)
  33. )
  34. ;; Select if Object  -  Lee Mac
  35. ;; Continuously prompts the user for a selection of a specific object type
  36. (defun LM:selectifobject ( msg typ / ent )
  37.    (while
  38.        (progn (setvar 'errno 0) (setq ent (car (entsel msg)))
  39.            (cond
  40.                (   (= 7 (getvar 'errno))
  41.                    (princ "\nMissed, try again.")
  42.                )
  43.                (   (null ent) nil)
  44.                (   (not (wcmatch (cdr (assoc 0 (entget ent))) typ))
  45.                    (princ "\nInvalid object selected.")
  46.                )
  47.            )
  48.        )
  49.    )
  50.    ent
  51. )
  52. (princ)
回复

使用道具 举报

37

主题

264

帖子

236

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
185
发表于 2022-7-5 16:53:30 | 显示全部楼层
嗨,李,
 
 
干得好,我觉得这一套很有用。
它做了一些3D测试。
当我看代码时,z似乎遗漏了
如果它也可以用在z中,那就太酷了!
 
 
汉斯
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 16:53:42 | 显示全部楼层
汉斯,
听起来你在挑战这位强大的数学家。
回复

使用道具 举报

37

主题

264

帖子

236

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
185
发表于 2022-7-5 17:03:54 | 显示全部楼层
我认为一行或两行可能由该名男子自己的地方,就可以了
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:10:22 | 显示全部楼层
 
谢谢你,汉斯,我很高兴你发现这个程序很有用,我感谢你的广泛测试。
 
现在,我已经更新了代码,使其能够在任何UCS构建平面中成功地使用构造线。
回复

使用道具 举报

37

主题

264

帖子

236

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
185
发表于 2022-7-5 17:16:17 | 显示全部楼层
很高兴来到这里!
也是OP?
回复

使用道具 举报

37

主题

264

帖子

236

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
185
发表于 2022-7-5 17:31:01 | 显示全部楼层
我测试了LB和xlb例程。
如果管线为非同平面,则LB表现良好。
当事物是非共平面时,XLB不能在事物的中间创建一条好的xline。
也许李先生或比我有更好的编码技能的人可以看看这个,修复一些东西,更好地使用3D。
 
 
https://drive.google.com/file/d/0B6-6JB1a0xTccVFMUjVLOUhqNjg/view?usp=sharing
 
 
谢谢
3D中的xlb。图纸
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 17:31:35 | 显示全部楼层
李,
 
这真是太有用了!在过去的几个小时里,我已经用了大约10次了。
有什么方法可以添加用户输入来指定第n个分区数吗。(即:输入2表示二等分,输入3表示三等分,ect…)
 
谢谢
马修22
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-8-21 01:56 , Processed in 0.599600 second(s), 71 queries .

© 2020-2025 乐筑天下

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