看看CAD中的Vlisp例程。
用vla-get-Coordinates 得到顶点坐标,用下面的函数处理。
- ;;;--------------------------------------------------------------------;
- ;;; Function: list->variantArray ;
- ;;;--------------------------------------------------------------------;
- ;;; Description: This function takes one parameter representing a ;
- ;;; list of double values, e.g. a list of 2D points: ;
- ;;; '(p1.X p1.Y p2.X p2.Y p3.X p3.Y p4.X p4.Y). ;
- ;;; The list is converted into an ActiveX ;
- ;;; variant based on a safearray. ;
- ;;; No error checking is performed on the parameter -- ;
- ;;; it is assumed to consist of a list of doubles. ;
- ;;;------------------------------------------------------------------- ;
- (defun gp:list->variantArray (ptsList / arraySpace sArray)
- ; allocate space for an array of 2d points stored as doubles
- (setq arraySpace
- (vlax-make-safearray
- vlax-vbdouble ; element type
- (cons 0
- (- (length ptsList) 1)
- ) ; array dimension
- )
- )
- (setq sArray (vlax-safearray-fill arraySpace ptsList))
- ; return array variant
- (vlax-make-variant sArray)
- )
- ;;;--------------------------------------------------------------------;
- ;;; Function: xyzList->ListOfPoints ;
- ;;;--------------------------------------------------------------------;
- ;;; Description: This function extracts and formats 3D point lists ;
- ;;; from one big list of reals, in the form: ;
- ;;; (x y z x y z x y z ...) ;
- ;;; This is the format of the data returned by the ;
- ;;; vla-get-coordinates function when applied to a ;
- ;;; standard polyline object. ;
- ;;;--------------------------------------------------------------------;
- ;;; The return value will be a list in the format: ;
- ;;; ((x y z) (x y z) (x y z) ... ) ;
- ;;;--------------------------------------------------------------------;
- (defun xyzList->ListOfPoints (coordList / ptlist)
- (while coordList
- (setq ptlist (append ptlist
- (list (list (car coordList) (cadr coordList) (caddr coordList)))
- ) ;_ end of append
- coordList (cdddr coordList)
- ) ;_ end of setq
- ) ;_ end of while
- ptlist
- ;;; (setq ptlist ptlist)
- ) ;_ end of defun
- ;;;--------------------------------------------------------------------;
- ;;; Function: xyList->ListOfPoints ;
- ;;;--------------------------------------------------------------------;
- ;;; Description: This function extracts and formats 2D point lists ;
- ;;; from one big list of reals, in the form: ;
- ;;; (x y x y x y ...) ;
- ;;; This is the format of the data returned by the ;
- ;;; vla-get-coordinates function when applied to a ;
- ;;; lightweight polyline object. ;
- ;;;--------------------------------------------------------------------;
- ;;; The return value will be a list in the format: ;
- ;;; ((x y) (x y) (x y) ... ) ;
- ;;;--------------------------------------------------------------------;
- (defun xyList->ListOfPoints (coordList / ptlist)
- (while coordList
- (setq ptlist (append ptlist
- (list (list (car coordList) (cadr coordList)))
- ) ;_ end of append
- coordList (cddr coordList)
- ) ;_ end of setq
- ) ;_ end of while
- ptlist
- ;;; (setq ptlist ptlist)
- ) ;_ end of defun
|