;; tratta da : http://forums.augi.com/showthread.php?45963-2d-Polyline-to-3d-Polyline ;This function loads the extended AutoLISP ;;functions provided with Visual LISP. ;;The Visual LISP extensions implement ActiveX ;;and AutoCAD reactor support through AutoLISP, ;;and also provide ActiveX utility and data ;;conversion functions, dictionary handling functions, ;;and curve measurement functions. (vl-load-com) ;;do not removed this function call ;;command to test the lwpTo3d function ;; will error if you do not select a LwPolyLine ;;can be removed ;;Enter testlwpto3d on the command line (defun c:lw-to-3d () (setq myp (vlax-ename->vla-object (car (entsel "\nSelect A LwPolyLine")) ) ;_ end of vlax-ename->vla-object ) ;_ end of setq (lwpto3d myp) ) ;_ end of defun ;;John W Anstaett 09/03/2006 ;;draw a 3dPolyline using the vector of a LWPOLYLINE ;;vbalwp is a vba object = to the LwPolyLine ;;Return a vba Object = to the new 3DPolyLine ;;Drawed in the same space as the LwPolyLine ;;The layer line type and other vaule are the same as the LwPolyLine ;;All z vaule of the 3DPoly are = to the Elevation of the LwPolyline (defun lwpTo3d (vbalwp / c1 c2 pts pts3d mydoc myowner my3d ut i lwc) (setq c1 (vlax-variant-value (vla-get-Coordinates vbalwp) ;get the coordinates of the ) ;LwPolyLine as a safearray ) ;_ end of setq (setq c1 (vlax-safearray-get-u-bound c1 1)) ;get number of coordinates (setq c1 (/ (- c1 1) 2)) ;set c1 to one less then the number of vectors (setq c2 (- (* (+ c1 1) 3) 1)) ;set c2 to the number of coordinates in 3DPoly ;;make a safearray to use with the add3DPoly (setq pts (vlax-make-safearray vlax-vbDouble (cons 0 c2) ) ;_ end of vlax-make-safearray ) ;_ end of setq ;;Make a Safearray to use as 3dPoly coordinte (setq pts3d (vlax-make-safearray vlax-vbDouble (cons 0 2) ) ;_ end of vlax-make-safearray ) ;_ end of setq ;;get the autocad document that the LwPolyline is in (setq myDoc (vla-get-Document vbalwp) ) ;_ end of setq (setq myowner (vla-ObjectIdToObject ;get the owner of the Lwpolyline myDoc ;This will be a block modeSpace or paperSpace (vla-get-ownerid vbalwp) ) ;_ end of vla-ObjectIdToObject ) ;_ end of setq (setq my3d (vla-Add3DPoly myowner pts) ;add the 3DPoly ) ;_ end of setq ;;get Autocad Utility to Translate the Coordinates ;;I do this so I do not need to covent the VBA Safearray to list ;; to use the lisp trans function (setq ut (vla-get-Utility mydoc) ) ;_ end of setq (setq i 0) ;;copy the Coordinate of LwPolyLine to the 3dpoly (repeat (+ c1 1) (setq lwc (vlax-variant-value (vla-get-Coordinate vbalwp i) ;Get LwPolyLine Coordinate ) ;_ end of vlax-variant-value ) ;_ end of setq (vlax-safearray-put-element pts3d 0 (vlax-safearray-get-element lwc 0) ;set x ) ;_ end of vlax-safearray-put-element (vlax-safearray-put-element pts3d 1 (vlax-safearray-get-element lwc 1) ;sete y ) ;_ end of vlax-safearray-put-element (vlax-safearray-put-element pts3d 2 (vla-get-Elevation vbalwp) ;set z = Elevation ) ;_ end of vlax-safearray-put-element ;;;Translate Coordinates form LwPolyLine ocs to world ;;use vlax-variant-value so pts3d is return as a safearray (setq pts3d (vlax-variant-value (vla-TranslateCoordinates ut pts3d acOCS acWorld 0 (vla-get-Normal vbalwp) ) ;_ end of vla-TranslateCoordinates ) ;_ end of vlax-variant-value ) ;_ end of setq (vla-put-coordinate my3d i pts3d) ;set the 3dPoly coordinate (setq i (+ i 1)) ) ;_ end of repeat ;;match the 3Dpoly to the LwPolyLine (vla-put-layer my3d (vla-get-layer vbalwp)) ;Set Layer (vla-put-Closed my3d (vla-get-Closed vbalwp)) ;Set Closed (vla-put-Color my3d (vla-get-Color vbalwp)) ;Set Color (vla-put-Linetype my3d (vla-get-Linetype vbalwp)) ;Set Linetype (vla-put-LinetypeScale my3d (vla-get-LinetypeScale vbalwp)) ;Set LinetypeScale (vla-put-Lineweight my3d (vla-get-Lineweight vbalwp)) ;set Lineweight (vla-put-Visible my3d (vla-get-visible vbalwp)) ;set Visible (vla-Update my3d) ;UpDate the 3DPoly (vlax-release-object mydoc) (vlax-release-object myowner) (vlax-release-object ut) (vlax-release-object vbalwp) (setq my3d my3d) ;return the 3DPoly ) ;_ end of defun