本帖最后由 lgx9612 于 2014-7-27 13:56 编辑
之前确因有一贴妙作,发贴不过10贴的不给看,故在不了解版规的情况下发了不少图片充数,确有炫耀和广告之嫌.在此实在是不好意思,虽写出几个小程序但本人笨拙,写的代码量很多,就不一一展示了.对本人来说计算最小点,最大点虽教程到处都可找到,但spline线对我来说是小有困难,费了我很大的心思.下面就spline线的最小点及最大点给出如下代码,请大家批评指正.- (;计算最小点,最大点主程式,spline线
- ;ss_minbox_lgx是选集
- ;.......................略
- (setq nx_lgx (sslength ss_minbox_lgx))
- (repeat nx_lgx
- (setq partname_lgx (ssname ss_minbox_lgx (setq nx_lgx (1- nx_lgx))))
- (setq typepart_lgx (cdr (assoc 0 (entget partname_lgx))))
- (if (/= typepart_lgx "SPLINE")
- (progn
- ;不是spline线的计算
- )
- (calspline_lgx partname_lgx)
- )
- )
- )
- (defun calspline_lgx(partname_lgx)
- (setq pl-temp_min_point nil)
- (setq pl-temp_max_point nil)
- (setq p_lgx nil)
- (setq lowest nil)
- (setq bbb (entget partname_lgx))
- (while (/= (assoc 10 bbb) nil)
- (setq p1_lgx (assoc 10 bbb))
- (setq p_lgx (cons (cdr p1_lgx) p_lgx))
- (setq bbb (vl-remove p1_lgx bbb))
- )
- (setq pl-temp_min_point (apply 'mapcar (cons 'min p_lgx)))
- (setq pl-temp_max_point (apply 'mapcar (cons 'max p_lgx)))
- (setq pl-temp_min_point (list (- (car pl-temp_min_point) 3)(- (cadr pl-temp_min_point) 3)))
- (setq pl-temp_max_point (list (+ (car pl-temp_max_point) 3)(+ (cadr pl-temp_max_point) 3)))
- (setq vla-object(vlax-ename->vla-object partname_lgx))
- (progn
- (setq pl_min_point pl-temp_min_point)
- (setq pl_max_point pl-temp_max_point)
- (setq zzl (/ (- (car pl_max_point)(car pl_min_point)) 10))
- (setq givenPnt (list (car pl_min_point)(cadr pl_max_point)))
- (setq type_lgx "y")
- (calculate_lgx )
- (setq y2 topnt)
- )
- (progn
- (setq pl_min_point pl-temp_min_point)
- (setq pl_max_point (list (car pl-temp_max_point)(cadr pl-temp_min_point)))
- (setq zzl (/ (- (car pl_max_point)(car pl_min_point)) 10))
- (setq givenPnt (list (car pl_min_point)(cadr pl_max_point)))
- (setq type_lgx "y" )
- (calculate_lgx)
- (setq y1 topnt)
- )
- (progn
- (setq pl_min_point pl-temp_min_point)
- (setq pl_max_point (list (car pl-temp_min_point)(cadr pl-temp_max_point)))
- (setq zzl (/ (- (cadr pl_max_point)(cadr pl_min_point)) 10))
- (setq givenPnt pl_min_point)
- (setq type_lgx "x" )
- (calculate_lgx )
- (setq x1 topnt)
- )
- (progn
- (setq pl_min_point (list (car pl-temp_max_point)(cadr pl-temp_min_point)))
- (setq pl_max_point pl-temp_max_point)
- (setq zzl (/ (- (cadr pl_max_point)(cadr pl_min_point)) 10))
- (setq givenPnt pl_min_point)
- (setq type_lgx "x" )
- (calculate_lgx )
- (setq x2 topnt)
- )
- (setq llpoint (list (car x1) (cadr y1)))
- (setq urpoint (list (car x2) (cadr y2)))
- )
- (defun calculate_lgx()
- (setq lowest nil)
- (while (>= zzl 0.02)
- (repeat 11
- (setq topnt (vlax-curve-getClosestPointTo vla-object givenPnt ))
- ;;;(command "line" givenPnt topnt "")
- (if (or (>= lowest (distance givenPnt topnt)) (= lowest nil))
- (progn
- (setq lowest (distance givenPnt topnt))
- (setq lowestpoint givenPnt)
- )
- )
- (if (= type_lgx "y")
- (setq givenPnt (list (+ (car givenPnt) zzl)(cadr pl_max_point)))
- (setq givenPnt (list (car pl_min_point)(+ (cadr givenPnt) zzl)))
- )
- )
- (if (= type_lgx "y")
- (setq givenPnt (list (- (car lowestpoint) zzl) (cadr pl_max_point)))
- (setq givenPnt (list (car pl_min_point) (- (cadr lowestpoint) zzl)))
- )
- (setq zzl (/ zzl 5))
- )
- (setq topnt (vlax-curve-getClosestPointTo vla-object lowestpoint ));;;givenPnt改为 lowestpoint
- (setq lowest nil)
- )
|