创建施工线
大家好,我想知道你是否可以帮我,我有这个代码(如下),
当用户选择两条线时,它会在它们之间创建另一条线,但当您选择构造线时,它不起作用,
你能把这个也修好用在施工线上吗?
非常感谢。
埃亚尔
;;LineBetween.lsp
;;To draw a Line whose endpoints are halfway Between those of two
;; User-selected Lines or Polyline line segments.
;;Draws Line on current Layer.
;;Accounts for Lines or Polyline line segments running generally in
;; same or opposite directions, and for 3rd dimension if applicable.
;;May draw Line between "wrong" halfway-between points if objects
;; cross, or if one crosses their apparent intersection, because routine
;; has no way to judge which possibility is expected -- try reversing
;; one object to get "right" result.
;;Result will not necessarily lie along angle bisector between selected
;; objects; will do so only if objects' relationship is symmetrical.
;;Kent Cooper, 5 March 2013
(defun C:LB ; = Line Between
(/ *error* noZ svnames svvals esel ent edata etype pick s1 e1 s2 e2 int)
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
(princ (strcat "\nError: " errmsg))
); if
(command "_.undo" "_end")
(mapcar 'setvar svnames svvals)
(princ)
); defun - *error*
(defun noZ (pt) (list (car pt) (cadr pt)))
(setq
svnames '(cmdecho aperture); = System Variable NAMES
svvals (mapcar 'getvar svnames); = System Variable VALueS
); setq
(mapcar 'setvar svnames (list 0 (getvar 'pickbox)))
; aperture = pickbox to prevent Osnap Center seeing wrong object
(command "_.undo" "_begin")
(foreach num '("1" "2")
(while
(not
(and
(setq esel (entsel (strcat "\nSelect Line/Polyline line segment #" num ": ")))
(setq
ent (car esel)
edata (entget ent)
etype (cdr (assoc 0 edata))
pick (osnap (cadr esel) "nea"); for (vlax-curve-...) later
); setq
(wcmatch etype "LINE,*POLYLINE")
(not (osnap pick "_cen")); if Polyline, not fit-curved or on arc segment
(if (= etype "POLYLINE") (= (boole 1 4 (cdr (assoc 70 edata))) 0) T)
; not spline-curved 2D "heavy" or 3D Polyline
); and
); not
(prompt "\nNothing, or Polyline curve, or invalid object type, selected --")
); while
(set (read (strcat "s" num)); s1 or s2
(if (= etype "LINE")
(cdr (assoc 10 edata)); then
(vlax-curve-getPointAtParam ent (fix (vlax-curve-getParamAtPoint ent pick))); else
); if
); set
(set (read (strcat "e" num)); e1 or e2
(if (= etype "LINE")
(cdr (assoc 11 edata)); then
(vlax-curve-getPointAtParam ent (1+ (fix (vlax-curve-getParamAtPoint ent pick)))); else
); if
); set
); foreach
(setq int (inters (noZ s1) (noZ s2) (noZ e1) (noZ e2))); T or nil -- opposite directions
(entmake
(list
'(0 . "LINE")
(cons 10 (mapcar '/ (mapcar '+ s1 (if int e2 s2)) '(2 2 2)))
(cons 11 (mapcar '/ (mapcar '+ e1 (if int s2 e2)) '(2 2 2)))
); list
); entmake
(command "_.undo" "_end")
(mapcar 'setvar svnames svvals)
(princ)
); defun
(prompt "\nType LB to draw a Line halfway Between two Lines/Polyline line segments.")
以下内容将构造一个XLine平分线:
;; XLine Bisector-Lee Mac
;; Constructs an XLine bisector between two selected XLines
(defun c:xlb ( / int pt1 pt2 vc1 vc2 xl1 xl2 )
(if (and (setq xl1 (LM:selectifobject "\nSelect 1st xline: " "XLINE"))
(setq xl2 (LM:selectifobject "\nSelect 2nd xline: " "XLINE"))
)
(entmake
(vl-list*
'(000 . "XLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbXline")
(if (setq xl1 (entget xl1)
xl2 (entget xl2)
pt1 (cdr (assoc 10 xl1))
pt2 (cdr (assoc 10 xl2))
vc1 (cdr (assoc 11 xl1))
vc2 (cdr (assoc 11 xl2))
int (inters (trans pt1 0 1) (trans (mapcar '+ pt1 vc1) 0 1) (trans pt2 0 1) (trans (mapcar '+ pt2 vc2) 0 1) nil)
)
(list
(cons 10 (trans int 1 0))
(cons 11 (mapcar (if (< (distance vc1 vc2) (distance vc1 (mapcar '- vc2))) '+ '-) vc1 vc2))
)
(list
(cons 10 (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) pt1 pt2))
(cons 11 vc1)
)
)
)
)
)
(princ)
)
;; Select if Object-Lee Mac
;; Continuously prompts the user for a selection of a specific object type
(defun LM:selectifobject ( msg typ / ent )
(while
(progn (setvar 'errno 0) (setq ent (car (entsel msg)))
(cond
( (= 7 (getvar 'errno))
(princ "\nMissed, try again.")
)
( (null ent) nil)
( (not (wcmatch (cdr (assoc 0 (entget ent))) typ))
(princ "\nInvalid object selected.")
)
)
)
)
ent
)
(princ) 嗨,李,
干得好,我觉得这一套很有用。
它做了一些3D测试。
当我看代码时,z似乎遗漏了
如果它也可以用在z中,那就太酷了!
汉斯 汉斯,
听起来你在挑战这位强大的数学家。 我认为一行或两行可能由该名男子自己的地方,就可以了
谢谢你,汉斯,我很高兴你发现这个程序很有用,我感谢你的广泛测试。
现在,我已经更新了代码,使其能够在任何UCS构建平面中成功地使用构造线。 很高兴来到这里!
也是OP? 我测试了LB和xlb例程。
如果管线为非同平面,则LB表现良好。
当事物是非共平面时,XLB不能在事物的中间创建一条好的xline。
也许李先生或比我有更好的编码技能的人可以看看这个,修复一些东西,更好地使用3D。
https://drive.google.com/file/d/0B6-6JB1a0xTccVFMUjVLOUhqNjg/view?usp=sharing
谢谢
3D中的xlb。图纸 李,
这真是太有用了!在过去的几个小时里,我已经用了大约10次了。
有什么方法可以添加用户输入来指定第n个分区数吗。(即:输入2表示二等分,输入3表示三等分,ect…)
谢谢
马修22
页:
[1]