本帖最后由 x_s_s_1 于 2026-2-4 15:44 编辑
如上图所示,任意lwpolyline,先选择图元,再选择图元外任意一点(point),在图元接近选择点的端头增设200长的线段,线段与原始线段夹角45度,且指向point所在方位(象限)。用向量解法,谢谢
以下是我自己的代码,没解决anchorpt所在方位的判断问题,也就是方位点在基线的哪个象限

网友答: 本帖最后由 夏生生 于 2026-2-5 17:38 编辑
搞定了,现在在外,稍后发上来

网友答: 本帖最后由 ytl1223 于 2026-2-4 13:28 编辑
搬别人得代码 之后 自己改得 看看你 适用不适用

网友答:
谢谢您的帮助,但抱歉,不是这样的网友答: 本帖最后由 ytl1223 于 2026-2-4 16:58 编辑
试试这次得这个 是不是你想要的啊

网友答:
再次感谢,还是不对,角度是固定的,和select point的区位有关系,但角度和它没关系,角度固定是45度网友答: 本帖最后由 xyp1964 于 2026-2-5 18:38 编辑
网友答:
谢谢院长,您这个只对单段直线段,对于多段线和首尾带弧段的不适用。网友答:
如果只是达到这个效果的话 可以先判断点击点是否在多段线内 ,如果在多段线圆弧内, 且圆弧向上凸,则短线角度取正45度 否则在圆弧外且向上凸则取正135度 ;反之,如果点击点在多段线圆弧内,且圆弧向下凸,则角度取-45度,否则若在圆弧外 且向下凸,则取-135度
网友答: 本帖最后由 xyp1964 于 2026-2-5 20:02 编辑
利用 vla-addVertex 函数应该更专业
如上图所示,任意lwpolyline,先选择图元,再选择图元外任意一点(point),在图元接近选择点的端头增设200长的线段,线段与原始线段夹角45度,且指向point所在方位(象限)。用向量解法,谢谢
以下是我自己的代码,没解决anchorpt所在方位的判断问题,也就是方位点在基线的哪个象限

- (defun vec-Rot2D (v a / c s x y)
- (setq c (cos a)
- s (sin a))
- (setq x (car v)
- y (cadr v))
- (list (- (* x c) (* y s)) (+ (* x s) (* y c))))
- (defun vec-unit (v / norm)
- (setq norm (vec-norm v))
- (cond ((= 1. norm) v)
- ((> norm 1e-14) (vec-vxs v (/ 1. norm)))
- ((equal 0. norm 1e-14) nil)))
- (defun vec-norm (v)
- (sqrt (apply (function +) (vec-v*v v v))))
- (defun vec-vxs (v sc)
- (mapcar (function (lambda (n) (* n sc))) v))
- (defun vec-Dot (v1 v2)
- (apply (function +) (vec-v*v v1 v2)))
- (defun vec-v*v (v1 v2)
- (mapcar (function *) v1 v2))
- (defun xty-make-gjxg (en selectpt anchorpt)
- (setq pts (vlax-curve-getstartpoint en)
- pte (vlax-curve-getendpoint en)
- len (vlax-curve-getdistatpoint en pte)
- selectpt (vlax-curve-getclosestpointto en selectpt)
- len1 (vlax-curve-getdistatpoint en selectpt))
- (if (<= len1 (- len len1))
- (progn (setq v (vlax-curve-getfirstDeriv
- en
- (vlax-curve-getstartparam en))
- v (vec-unit v)
- v (vec-Rot2D v (* 0.25 pi)))
- (vl-cmdf "pline"
- "none"
- pts
- "none"
- (mapcar '+ pts (vec-vxs v 200))
- ""))
- (progn (setq v (vlax-curve-getfirstDeriv en (vlax-curve-getendparam en))
- v (vec-unit v)
- v (vec-Rot2D v (* 0.75 pi)))
- (vl-cmdf "pline"
- "none"
- pte
- "none"
- (mapcar '+ pte (vec-vxs v 200))
- "")))
- (setq ss (ssadd)
- ss (ssadd en ss)
- ss (ssadd (entlast) ss))
- (vl-cmdf "pedit" "m" ss "" "j" "" ""))
- (defun c:tt ()
- (setq en (entsel)
- pt (cadr en)
- en (car en))
- (xty-make-gjxg en pt (getpoint)))
网友答: 本帖最后由 夏生生 于 2026-2-5 17:38 编辑
搞定了,现在在外,稍后发上来

- (defun make-gjxg (en selectpt anchorpt / gjxg_j
- en1 len len1 pte1 pte2
- pte3 pteparam pts1 pts2 pts3
- ptsparam)
- (defun gjxg_j
- (en P1 P2 P3 p ang / cen ptn ptn1 ptn2 ptt1 ptt2 v v1 v2 va)
- (setq v (vlax-curve-getfirstDeriv
- en
- (vlax-curve-getparamatpoint en p1)) ;_起始(终)点切向量
- v (vec-unit v) ;_起始(终)点单位切向量
- v1 (vec-Rot2D v ang) ;_正旋转
- v2 (vec-Rot2D v (- ang)) ;_负旋转
- ptn1 (mapcar '+ p1 (vec-vxs v1 200)) ;_正旋转点
- ptn2 (mapcar '+ p1 (vec-vxs v2 200))) ;_负旋转点
- (if (setq cen (G-3ptcen p1 p2 p3))
- (if (< (distance p (car cen)) (cadr cen)) ;_方向点是否在圆内
- (setq ptn ptn1)
- (setq ptn ptn2))
- (progn (setq ptt1 (g-pertoline p P1 p3) ;_方向点在线段上投影
- va (mapcar '- p ptt1) ;_方向点向量
- ptt2 (mapcar '+ p1 va)) ;_起始(终)点偏移
- (if (< (G-PerDistToLine ptn1 ptt1 ptt2)
- (G-PerDistToLine ptn2 ptt1 ptt2)) ;_离偏移线近者为所需
- (setq ptn ptn1)
- (setq ptn ptn2))))
- (make-lwpl (list p1 ptn) 0 0))
- (setq pts1 (vlax-curve-getstartpoint en) ;_起点
- ptsparam (vlax-curve-getstartparam en) ;_起点参数
- pts2 (vlax-curve-getpointatparam en (+ ptsparam 0.5)) ;_起始段中间点
- pts3 (vlax-curve-getpointatparam en (1+ ptsparam)) ;_起始段终点
- pte1 (vlax-curve-getendpoint en) ;_终点
- pteparam (vlax-curve-getendparam en) ;_终点参数
- pte2 (vlax-curve-getpointatparam en (- pteparam 0.5)) ;_终止段中间点
- pte3 (vlax-curve-getpointatparam en (1- pteparam)) ;_终止段起点
- len (vlax-curve-getdistatpoint en pte1) ;_线段长
- selectpt (vlax-curve-getclosestpointto en selectpt) ;_选择点在线上的投影
- len1 (vlax-curve-getdistatpoint en selectpt)) ;_投影点距起点距离
- (if (<= len1 (- len len1)) ;_当离起点近
- (setq en1 (gjxg_j en pts1 pts2 pts3 anchorpt (* 0.25 pi)))
- (setq en1 (gjxg_j en pte1 pte2 pte3 anchorpt (* 0.75 pi)))
- )
- (vl-cmdf "pedit" "m" en en1 "" "j" "" ""))
- (defun c:tt ()
- (setq en (entsel)
- pt (cadr en)
- en (car en))
- (make-gjxg en pt (getpoint)))
网友答: 本帖最后由 ytl1223 于 2026-2-4 13:28 编辑
搬别人得代码 之后 自己改得 看看你 适用不适用

- (defun c:AA (/ ee p d pp enf)
- (setq ee (nentselp (getpoint)))
- (setq p (cadr ee))
- (setq d 50)
- (setq pp (list (mapcar '- p (list d 0)) p (mapcar '+ p (list d 0))))
- (foreach p pp
- (setq enf (apv p))
- )
- (entmod
- (subst (cons 10 (mapcar '+ p (mapcar '- (getpoint "\n 插入点") p)))
- (cons 10 (list (car p) (cadr p)))
- enf
- )
- )
- (princ)
- )
- (defun apv (p / *error* a b e h l n r v w x z en lp)
- (defun *error* (msg)
- (LM:endundo (LM:acdoc))
- (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
- (princ (strcat "\nError: " msg))
- )
- (princ)
- )
- (cond
- ((null p)
- nil
- )
- ((null (setq e (nentselp p)))
- (princ "\n not lie on a polyline.")
- )
- ((= 4 (length e))
- (princ
- "\nThis program is not compatible with nested objects."
- )
- )
- ((/= "LWPOLYLINE" (cdr (assoc 0 (entget (setq e (car e))))))
- (princ "\nThe specified point does not lie on a polyline.")
- )
- )
- (if (and p
- e
- (setq p (vlax-curve-getclosestpointto e (trans p 1 0))
- n (vlax-curve-getparamatpoint e p)
- )
- )
- (if (not (equal n (fix n) 1e-8))
- (progn
- (setq e (entget e)
- h (reverse (member (assoc 39 e) (reverse e)))
- v (assoc 90 h)
- l (LM:LWVertices e)
- z (assoc 210 e)
- )
- ;;; (print l )
- (repeat (fix n)
- (setq a (cons (car l) a)
- l (cdr l)
- )
- )
- (setq x (car l)
- r (- n (fix n))
- w (cdr (assoc 40 x))
- w (+ w (* r (- (cdr (assoc 41 x)) w)))
- b (atan (cdr (assoc 42 x)))
- )
- (LM:startundo (LM:acdoc))
- (setq en (entmod
- (append
- (subst (cons 90 (1+ (cdr v))) v h)
- (apply 'append (reverse a))
- (list
- (assoc 10 x)
- (assoc 40 x)
- (cons 41 w)
- (cons 42 (tan (* r b)))
- ;;; (cons 42 0.414214)
- (cons 10 (trans p 0 (cdr z)))
- (cons 40 w)
- (assoc 41 x)
- (cons 42 (tan (* (- 1.0 r) b)))
- )
- (apply 'append (cdr l))
- (list z)
- )
- )
- )
- (LM:endundo (LM:acdoc))
- )
- )
- )
- (princ)
- en
- )
- (defun tan (x)
- (if (not (equal 0.0 (cos x) 1e-10))
- (/ (sin x) (cos x))
- )
- )
- (defun LM:LWVertices (e)
- (if (setq e (member (assoc 10 e) e))
- (cons
- (list
- (assoc 10 e)
- (assoc 40 e)
- (assoc 41 e)
- (assoc 42 e)
- )
- (LM:LWVertices (cdr e))
- )
- )
- )
- (defun LM:startundo (doc)
- (LM:endundo doc)
- (vla-startundomark doc)
- )
- (defun LM:endundo (doc)
- (while (= 8 (logand 8 (getvar 'undoctl)))
- (vla-endundomark doc)
- )
- )
- (defun LM:acdoc nil
- (eval (list 'defun
- 'LM:acdoc
- 'nil
- (vla-get-activedocument (vlax-get-acad-object))
- )
- )
- (LM:acdoc)
- )
- ;;----------------------------------------------------------------------;;
- (vl-load-com)
- (princ)
网友答:
ytl1223 发表于 2026-2-4 13:26
搬别人得代码 之后 自己改得 看看你 适用不适用
谢谢您的帮助,但抱歉,不是这样的网友答: 本帖最后由 ytl1223 于 2026-2-4 16:58 编辑
试试这次得这个 是不是你想要的啊

- (defun c:vv (/ ee p d pp enf)
- (setq ee (nentselp (getpoint)))
- (setq p (cadr ee))
- (setq enf (apv p))
- (princ)
- )
- (defun apv (p / *error* a b e h l n r v w x z en lp RR P2)
- (defun *error* (msg)
- (LM:endundo (LM:acdoc))
- (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
- (princ (strcat "\nError: " msg))
- )
- (princ)
- )
- ;;; (while
- ;;; (progn ;;(setq p (getpoint "\nSpecify point for new vertex: "))
- (cond
- ((null p)
- nil
- )
- ((null (setq e (nentselp p)))
- (princ "\n not lie on a polyline.")
- )
- ((= 4 (length e))
- (princ
- "\nThis program is not compatible with nested objects."
- )
- )
- ((/= "LWPOLYLINE" (cdr (assoc 0 (entget (setq e (car e))))))
- (princ "\nThe specified point does not lie on a polyline.")
- )
- )
- (if (and p
- e
- (setq p (vlax-curve-getclosestpointto e (trans p 1 0))
- n (vlax-curve-getparamatpoint e p)
- )
- )
- (if T
- ;;(not (equal n (fix n) 1e-8))
- (progn
- (setq e (entget e)
- h (reverse (member (assoc 39 e) (reverse e)))
- v (assoc 90 h)
- l (LM:LWVertices e)
- z (assoc 210 e)
- )
- (if (< n (/ (1- (cdr v)) 2))
- (setq n 0)
- (setq n (1- (cdr v)))
- )
- ;;; (print l )
- ;;; (if (> n 1) (+1 n) 0)
- (print (length l))
- (repeat (fix n)
- (setq a (cons (car l) a)
- l (cdr l)
- )
- )
- (setq x (car l))
- (LM:startundo (LM:acdoc))
- (setq RR (/ (* 180
- (angle (cdr (assoc 10 x))
- (getpoint (cdr (assoc 10 x)))
- )
- )
- PI
- )
- )
- (setq RR
- (cond
- ((<= RR 90) (* pi 0.25))
- ((<= RR 180) (* pi 0.75))
- ((<= RR 270) (* pi 1.25))
- ((<= RR 360) (* pi 1.75))
- )
- )
- (setq p2 (polar (cdr (assoc 10 x)) RR 200))
- (setq en (entmod
- (append
- (subst (cons 90 (1+ (cdr v))) v h)
- (apply 'append (reverse a))
- (if (> n (/ (1- (cdr v)) 2))
- (apply 'append (list x))
- )
- (list
- (cons 10 p2)
- (cons 40 0)
- (cons 41 0)
- (cons 42 0)
- )
- (if (< n (/ (1- (cdr v)) 2))
- (apply 'append l)
- (apply 'append (cdr l))
- )
- (list z)
- )
- )
- )
- (LM:endundo (LM:acdoc))
- )
- )
- )
- (princ)
- en
- )
- ;; Tangent - Lee Mac
- ;; Args: x - real
- (defun tan (x)
- (if (not (equal 0.0 (cos x) 1e-10))
- (/ (sin x) (cos x))
- )
- )
- ;; LW Vertices - Lee Mac
- ;; Returns a list of lists in which each sublist describes
- ;; the position, starting width, ending width and bulge of the
- ;; vertex of a supplied LWPolyline
- (defun LM:LWVertices (e)
- (if (setq e (member (assoc 10 e) e))
- (cons
- (list
- (assoc 10 e)
- (assoc 40 e)
- (assoc 41 e)
- (assoc 42 e)
- )
- (LM:LWVertices (cdr e))
- )
- )
- )
- ;; Start Undo - Lee Mac
- ;; Opens an Undo Group.
- (defun LM:startundo (doc)
- (LM:endundo doc)
- (vla-startundomark doc)
- )
- ;; End Undo - Lee Mac
- ;; Closes an Undo Group.
- (defun LM:endundo (doc)
- (while (= 8 (logand 8 (getvar 'undoctl)))
- (vla-endundomark doc)
- )
- )
- ;; Active Document - Lee Mac
- ;; Returns the VLA Active Document Object
- (defun LM:acdoc nil
- (eval (list 'defun
- 'LM:acdoc
- 'nil
- (vla-get-activedocument (vlax-get-acad-object))
- )
- )
- (LM:acdoc)
- )
- ;;----------------------------------------------------------------------;;
- (vl-load-com)
- (princ)
网友答:
ytl1223 发表于 2026-2-4 16:48
试试这次得这个 是不是你想要的啊
再次感谢,还是不对,角度是固定的,和select point的区位有关系,但角度和它没关系,角度固定是45度网友答: 本帖最后由 xyp1964 于 2026-2-5 18:38 编辑

- (defun c:tt ()
- "tt(象限画线)"
- (defun line (p1 p2)
- (entmakex (list '(0 . "LINE")'(100 . "AcDbEntity")'(100 . "AcDbLine")(cons 10 p1)(cons 11 p2)))
- )
- (defun abc(s1 s2)(command "pedit" "m" s1 s2 "" "j" "" ""))
- (if (and (setq e (entsel "\n选择: "))
- (setq s1 (car e))
- (setq p1 (cadr e))
- (= (cdr (assoc 0 (entget s1))) "LWPOLYLINE")
- (setq p0 (getpoint "\n基点<退出>: "))
- )
- (progn
- (mapcar 'set'(pt1 pt2)(list (vlax-curve-getStartPoint s1)(vlax-curve-getEndPoint s1)))
- (setq ps (if (< (distance p0 pt1) (distance p0 pt2)) pt1 pt2)
- r1 (angle p1 p0)
- )
- (cond ((< 0 r1 (* pi 0.5))(line ps (polar ps (* pi 0.25) 200))(abc s1 (entlast)))
- ((< (* pi 0.5) r1 (* pi 1))(line ps (polar ps (* pi 0.75) 200))(abc s1 (entlast)))
- ((< (* pi 1) r1 (* pi 1.5))(line ps (polar ps (* pi 1.25) 200))(abc s1 (entlast)))
- ((< (* pi 1.5) r1 (* pi 2))(line ps (polar ps (* pi 1.75) 200))(abc s1 (entlast)))
- )
- )
- )
- (princ)
- )
xyp1964 发表于 2026-2-4 19:16
谢谢院长,您这个只对单段直线段,对于多段线和首尾带弧段的不适用。网友答:
如果只是达到这个效果的话 可以先判断点击点是否在多段线内 ,如果在多段线圆弧内, 且圆弧向上凸,则短线角度取正45度 否则在圆弧外且向上凸则取正135度 ;反之,如果点击点在多段线圆弧内,且圆弧向下凸,则角度取-45度,否则若在圆弧外 且向下凸,则取-135度
网友答: 本帖最后由 xyp1964 于 2026-2-5 20:02 编辑
利用 vla-addVertex 函数应该更专业