本帖最后由 kucha007 于 2024-3-23 18:08 编辑
- ;返回实体或对象最小边界框的WCS坐标(左下角和右上角)@Gu_xl
- (defun K:GetWCSBox (obj / p1 p2 p3 p4 WCSBox)
- (if (eq 'ENAME (type obj))(setq obj (vlax-ename->vla-object obj)))
- (vla-GetBoundingBox obj 'p1 'p3)
- (setq p1 (vlax-safearray->list p1)
- p3 (vlax-safearray->list p3)
- p2 (list (car p1) (cadr p3) (caddr p1))
- p4 (list (car p3) (cadr p1) (caddr p1))
- )
- (if (eq "AcDbSpline" (Vla-Get-ObjectName obj));样条曲线取投影
- (progn
- (setq WCSBox (mapcar
- '(lambda (a b) (vlax-curve-getClosestPointToProjection obj a b t))
- (list p1 p2 p3 p4)
- '((1.0 0 0) (0 -1.0 0) (-1.0 0 0) (0 1.0 0))
- )
- )
- (list
- (apply 'mapcar (cons 'min WCSBox));表中最小
- (apply 'mapcar (cons 'max WCSBox));表中最大
- )
- )
- (list p1 p3)
- )
- )
- ;返回实体或对象最小边界框的UCS坐标(左下角和右上角)@Kucha
- (defun K:GetUCSBox (obj / K:CvtMatrix UCSBox)
- (if (eq 'ENAME (type obj))(setq obj (vlax-ename->vla-object obj)))
- ;矩阵转换/坐标系转换
- (defun K:CvtMatrix (from to)
- (append
- (mapcar
- (function
- (lambda (v o)
- (append (trans v from to t) (list o))
- )
- )
- '((1.0 0.0 0.0)
- (0.0 1.0 0.0)
- (0.0 0.0 1.0)
- )
- (trans '(0.0 0.0 0.0) to from)
- )
- '((0.0 0.0 0.0 1.0))
- )
- )
- (vla-transformby obj (vlax-tmatrix (K:CvtMatrix 1 0)));对象转换到WCS
- (setq UCSBox (K:GetWCSBox obj));获取转换后的最小矩形框(WCS)
- (vla-transformby obj (vlax-tmatrix (K:CvtMatrix 0 1)));对象转换回UCS
- UCSBox
- )
- ;获取选择集所有实体的最小边界框表(WCS/UCS)@Kucha
- (defun K:SSAllBoxLst (WCS TgtSS / i en SSBox)
- (if TgtSS
- (repeat (setq i (sslength TgtSS))
- (setq en (ssname TgtSS (setq i (1- i))))
- (setq SSBox
- (cons
- (if WCS (K:GetWCSBox en) (K:GetUCSBox en))
- SSBox
- )
- )
- )
- )
- SSBox
- )
- ;获取选择集的最小边界框(WCS/UCS)@Kucha
- (defun K:SSMinBoxLst (WCS TgtSS / i en Box BoxMin BoxMax MinPt MaxPt)
- (if TgtSS
- (repeat (setq i (sslength TgtSS))
- (setq en (ssname TgtSS (setq i (1- i))))
- (setq Box (if WCS (K:GetWCSBox en) (K:GetUCSBox en)))
- (setq BoxMin (car Box) BoxMax (cadr Box))
- (setq MinPt (mapcar 'min BoxMin (cond (MinPt) (BoxMin))))
- (setq MaxPt (mapcar 'max BoxMax (cond (MaxPt) (BoxMax))))
- )
- )
- (list MinPt MaxPt)
- )
- ;获取选择集最小边界框表的最小值,即左下角(WCS/UCS)@Kucha
- (defun K:SSBoxMinPT (WCS TgtSS / i en BoxMin MinPt)
- (if TgtSS
- (repeat (setq i (sslength TgtSS))
- (setq en (ssname TgtSS (setq i (1- i))))
- (setq BoxMin (car (if WCS (K:GetWCSBox en) (K:GetUCSBox en))))
- (setq MinPt (mapcar 'min BoxMin (cond (MinPt) (BoxMin))))
- )
- )
- MinPt
- )
|