本帖最后由 highflybird 于 2011-9-2 23:24 编辑
很久以前写的了。
- ;;;******************************************************
- ;;;一个求多义线各段参数(如果是弧段则有半径弧长)的lisp程序
- ;;;编号 1:凸度,2:弦长或直段长,3:半径,4:弧长,5:圆心--
- ;;;加载程序,运行bulge,则显示上述参数-------------------
- (defun C:Bulge (/ sel ent lst obj vex ifclose
- i par 1stPt EndPt judge tu pt1
- pt2 dis radius h h1 half-angle
- arc-length pa cen
- )
- (if (setq sel (ssget '((0 . "LWPOLYLINE"))))
- (progn
- (setq ent (ssname sel 0))
- (setq lst (entget ent))
- (setq obj (vlax-ename->vla-object ent))
- (setq vex (cdr (assoc 90 lst)))
- (setq ifclose (cdr (assoc 70 lst)))
- (setq i 0
- par nil
- )
- (setq 1stPt (vlax-Curve-GetPointAtParam ent 0))
- (setq EndPt (vlax-Curve-GetPointAtParam ent (1- vex)))
- (if (or (equal 1stPt EndPt 1e-8) (= ifclose 0))
- (setq vex (1- vex))
- )
- (repeat vex
- (setq tu (vla-GetBulge obj i))
- (setq pt1 (vlax-Curve-GetPointAtParam ent i))
- (if (and (= i (1- vex)) judge)
- (setq pt2 (vlax-Curve-GetPointAtParam ent 0))
- (setq pt2 (vlax-Curve-GetPointAtParam ent (1+ i)))
- )
- (setq dis (distance pt1 pt2))
- (if (/= tu 0)
- (progn
- (setq radius (/ (* (1+ (* tu tu)) dis 0.25) (abs tu)))
- (setq h (* dis (abs tu) 0.5)
- h1 (- radius h)
- )
- (setq half-angle (atan (/ dis 2) h1))
- (setq arc-length (* 2 half-angle radius))
- (setq cen (midp pt1 pt2))
- (setq cen (polar cen
- (+ (angle pt1 pt2)
- (if (or nil
- (and (> h1 0) (> tu 0))
- (and (< h1 0) (< tu 0))
- )
- (* pi 0.5)
- (* pi -0.5)
- )
- )
- (abs h1)
- )
- )
- (setq pa (list tu dis radius arc-length cen))
- (setq par (cons pa par))
- )
- (progn
- (setq pa (list tu dis))
- (setq par (cons pa par))
- )
- )
- (setq i (1+ i))
- )
- (setq par (reverse par))
- (princ "\n下面为此曲线的各段列表,3,4,5编号为弧段才有:")
- (princ "\n1:凸度 2:弦长(或直线长) 3:半径 4:弧长 5:圆心")
- (foreach n par
- (princ "\n")
- (princ n)
- )
- (princ)
- )
- (alert "你没有选中物体或者选择的不是多义线!")
- )
- (princ)
- )
- ;;;******************************************************
|