本帖最后由 夏生生 于 2022-10-27 08:12 编辑
老帖子了,正好看到,搞了一下,试试
- ;;;向量相关函数来自明经网友高飞鸟
- (defun c:tt (/ lst pt pt1 pt2 pt3 ss v v1 v2)
- (defun xty-tr-ss2lst (ss form / n en lst)
- (repeat (setq n (sslength ss))
- (setq en (ssname ss (setq n (1- n))))
- (setq lst (cons en lst))
- )
- (setq lst (reverse lst))
- (if form
- lst
- (mapcar (function vlax-ename->vla-object) lst)
- )
- )
- (defun xty-vec-v*v (v1 v2)
- (mapcar (function *) v1 v2)
- )
- (defun xty-vec-vxs (v sc)
- (mapcar (function (lambda (n) (* n sc))) v)
- )
- (defun xty-vec-vxv (u v)
- (list
- (- (* (cadr u) (caddr v)) (* (cadr v) (caddr u)))
- (- (* (car v) (caddr u)) (* (car u) (caddr v)))
- (- (* (car u) (cadr v)) (* (car v) (cadr u)))
- )
- )
- (defun xty-vec-norm (v)
- (sqrt (apply (function +) (xty-vec-v*v v v)))
- )
- (defun xty-vec-unit (v / norm)
- (setq norm (xty-vec-norm v))
- (cond ((= 1. norm) v)
- ((> norm 1e-14) (xty-vec-vxs v (/ 1. norm)))
- ((equal 0. norm 1e-14) nil)
- )
- )
- (defun xty-vec-DispToMatrix (mat disp)
- (append
- (mapcar 'append mat (mapcar 'list disp))
- '((0. 0. 0. 1.))
- )
- )
- (defun xty-vec-Trans (from to)
- (xty-vec-DispToMatrix
- (mapcar
- (function (lambda (v) (trans v from to t)))
- '((1. 0. 0.) (0. 1. 0.) (0. 0. 1.))
- )
- (trans '(0 0 0) to from)
- )
- )
- (setq ss (ssget '((0 . "*polyline")))
- lst (xty-tr-ss2lst ss nil)
- pt (getpoint "\n插入点:")
- )
- (foreach en lst
- (setq en (vla-copy en)
- pt1 (vlax-curve-getstartpoint en)
- pt2 (vlax-curve-getpointatparam en 1)
- pt3 (vlax-curve-getpointatparam en 2)
- v1 (mapcar '- pt2 pt1)
- v2 (mapcar '- pt3 pt1)
- v (xty-vec-unit (xty-vec-vxv v1 v2))
- )
- (vla-TransformBy
- en
- (vlax-tmatrix (xty-vec-Trans v '(0 0 1)))
- )
- (vla-getboundingbox en 'pt1 'pt2)
- (vla-move en
- pt1
- (vlax-3d-point pt)
- )
- (vla-getboundingbox en 'pt1 'pt2)
- (setq pt (list (car (vlax-safearray->list pt2))
- (cadr (vlax-safearray->list pt1))
- (caddr (vlax-safearray->list pt1))
- )
- )
- )
- )
|