很讨厌看到这种需要先支付才能浏览的贴子!
这种2D polyline 转 3D polyline 的贴子多的是 ,没必要这么神秘
随便贴几个吧
Convert 3D Polylines To 2D Polylines
Convert 2-D polyline(s) (pline) to 3-D polyline(s) (3dpoly)
- ;###############################################################################
- ;
- ; poly2to3.lsp
- ;
- ; Convert 2-D polyline(s) (pline) to 3-D polyline(s) (3dpoly) using
- ; user-specified z-value for 3-D polyline. Creates new 3-D polyline and
- ; erases old 2-D polyline.
- ;
- ; User is prompted for:
- ; 1) the z-value to assign to the 3-D polyline(s)
- ; 2) the selection set
- ;
- ; NOTE: this may not properly handle all possible combination of attributes.
- ;
- ; Please feel free to direct any comments, criticisms, and/or suggestions to
- ; me at one of the below listed locations.
- ;
- ; by: Michael J. Read Compuserve: 71571,2073
- ; Read Engineering
- ; 1714 Ben Crenshaw Way
- ; Austin, TX 78746
- ; (512)327-9776
- ;
- ; January 5, 1990
- ;
- ;############################# Revision History ##############################
- ; mjr 900105 - V1.00 - initial release
- ; mjr 911026 - V1.10 - cleaned up, added selection set capability, attribute
- ; handling
- ; mjr 911031 - V1.20 - added capability of assigning a user-specified z-value
- ; for each vertex. User is given choice of 3D z-value as
- ; 1) global z-value, 2) manually supplying z-value for each
- ; vertex of each polyline, or 3) assigning existing 2D
- ; z-value.
- ;###############################################################################
- (princ "\n\n Lisp by: Michael J. Read - READ ENGINEERING - (512)327-9776\tLoading...")
- (defun header(/ verd vern) ; display header info
- (setq vern 1.20)
- (setq verd "01-Nov-91")
- (princ "\n READ ENGINEERING: ")
- (princ (strcat "poly2to3 (V" (rtos vern 2 2) " " verd ") - change 2D polyline(s) to 3D\n"))
- )
- (defun cls()
- (repeat 24 (princ
- " \n"))
- )
- ; return the value associated with a particular entity field
- (defun fld (num list)
- (cdr (assoc num list))
- )
- ; save specified mode settings
- (defun MODES (a)
- (setq MLST '())
- (repeat (length a)
- (setq MLST (append MLST (list (list (car a) (getvar (car a))))))
- (setq a (cdr a)))
- )
- ; restore saved mode settings
- (defun MODER ()
- (repeat (length MLST)
- (setvar (caar MLST) (cadar MLST))
- (setq MLST (cdr MLST))
- )
- )
- (defun explain()
- (textscr)
- (princ "\n\n")
- (princ
- "Constructs a 3D polyline using 3dpoly with exactly the same vertices as the\n")
- (princ
- "selected 2D polyline. The 2D polyline is then deleted leaving only the 3D\n")
- (princ "polyline.\n\n")
- (princ
- "Options available for assigning the z-value to the new 3D polyline(s) are:\n\n")
- (princ " 1 - user-specified global z-value for all 3D polylines\n")
- (princ " 2 - user-specified z-value for each vertex of each 3D polyline\n")
- (princ " 3 - existing 2D polyline z-value assigned to the 3D polyline\n\n")
- )
- ; main routine
- ; convert 2-d polyline to 3-d polyline
- ;
- (defun c:poly2to3(/ e1 ec ed emax en et el f1 f2 nent nver ss1 x y xyz zopt zval)
- (cls) ; clear the text screen
- (header) ; display header info
- (modes '("BLIPMODE" "CMDECHO" )) ; save modes
- (setvar "cmdecho" 0) ; turn off command echo
- (setvar "blipmode" 0) ; turn off blips
- (explain) ; explain what program does and options
- (initget 1 "1 2 3")
- (setq zopt (getkword "Enter option for assigning z-value to 3D polyline (1, 2 or 3): "))
- (if (equal zopt "1") ; global z-value option
- (progn
- (initget (+ 1 4))
- (setq zval (getreal "\nEnter global z-value: ")) ; get z-value
- );end progn
- );end if
- (graphscr)
- (princ "\nSelect 2-D polyline(s) to convert to 3-D polylines(s)...\n")
- (if (setq ss1 (ssget)) ; ask the user to build a selection set
- ; if the set isn't empty
- ; build selection set of polylines only
- ; by deleting all of the non-polylines in the set
- (progn
- (setq nent 0
- emax (sslength ss1))
- (prompt (strcat "\n" (itoa emax) " entitie(s) selected.\n"))
- (while (< nent emax)
- (setq en (ssname ss1 nent)
- ed (entget en))
- (if (/= "POLYLINE" (fld 0 ed))
- (progn
- (ssdel en ss1)
- (setq nent (1- nent)
- emax (1- emax))
- )
- )
- (setq nent (1+ nent))
- ); end while
- (setq nent 0
- emax (sslength ss1)) ; number of polylines
- (prompt (strcat (itoa emax) " polyline(s) found.\n"))
- ; loop through polylines
- ; add 3-D 3dpoly vertex for each 2-D vertex
-
- (if (> emax 0)
- (progn
- (setq nent 0
- emax (sslength ss1)) ; number of polylines
- (while (< nent emax)
- (setq en (ssname ss1 nent))
- (setq e1 en
- ed (entget en)
- nver 0
- ec (fld 62 ed)
- et (fld 0 ed)
- f1 (fld 70 ed)
- )
- (if (= et "POLYLINE" )
- (princ (strcat "Converting pline to 3dpoly <using "
- (cond ((equal zopt "1") (strcat
- "GLOBAL z-value: "
- (rtos zval 2 2)))
- ((equal zopt "2") "VERTEX z-value")
- ((equal zopt "3") "2D z-value")
- )
- ">...\n")
- )
- );end if
- (while (and (setq en (entnext en))
- (setq ed (entget en))
- (/= "SEQEND" (fld 0 ed)))
- (setq xyz (fld 10 ed)
- x (car xyz)
- y (cadr xyz)
- z (caddr xyz)
- el (fld 8 ed)
- et (fld 0 ed)
- f2 (fld 70 ed)
- )
- ; (princ (strcat "### f1=" (itoa f1) ", f2=" (itoa f2) "\n"))
- ;
- ; add 3dpoly vertex for each ACTUAL 2-D vertex
- ; ignore spline or curve fit vertices
- (if (cond
- ((and (= et "VERTEX") (= 0 f2)) 1)
- ((and (= et "VERTEX") (= 2 (logand f1 2)) (= 0 f2)) 1)
- ((and (= et "VERTEX") (= 4 (logand f1 4)) (= 16 f2)) 1)
- (t nil)
- )
- (progn
- (redraw en 3) ; highlight segment
- (cond ((equal zopt "2") ; vertex z-value option
- (initget (+ 1 4))
- (setq zval (getreal "Enter vertex z-value: "))
- )
- ((equal zopt "3") ; 2D z-value option
- (setq zval z) ; assign 2D z-value
- )
- );end cond
- (setq nver (+ nver 1))
- (if (= 1 nver) (command "3dpoly")) ; start 3dpoly
- (command (list x y zval)) ; add vertex
- );end progn
- );end if
- (redraw en 4) ; de-highlight segment
- ); end while entnext
- (setq nent (1+ nent))
- (redraw e1 1)
- (if (> nver 0) ; if we had any valid vertices
- (progn
- (command "") ; end 3dpoly
- ;
- ; assign attributes of old polyline to new polyline
- ;
- (if (= (logand 1 f1) 1) (command "pedit" "last" "c" ""))
- (if (= (logand 2 f1) 2) (command "pedit" "last" "s" ""))
- (if (= (logand 4 f1) 4) (command "pedit" "last" "s" ""))
- (entdel e1) ; delete old polyline
- (command "change" "last" "" "prop" "layer" el "") ;change layer
- (if (not (null ec))
- (command "change" "last" "" "prop" "color" ec "");change color
- )
- (princ (strcat " added 3dpoly with " (itoa nver)
- " vertices \n"))
- );end progn
- ;else
- (princ "Can't change polyline!\n")
- );end if nver
- );end while entity
- );end progn
- );end if emax > 0
- );end progn
- );end if ss1
- (moder) ; reset modes
- (princ)
- ) ;end of poly2to3
- (header) ; display header info
- (princ)
|