roksolid Posted January 12, 2021 Share Posted January 12, 2021 I'm trying to convert hundreds of polylines to 3D polylines while keeping x,y and elevation data. I've found a lisp on another forum to do this but it only seems to work on a single polyline and does not work on multiple polylines. I would highly appreciate if someone can help me add or modify the code so that it will run on all selected polylines. Thanks in advance. ;;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:testlwpto3d () (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 Quote Link to comment Share on other sites More sharing options...
Jonathan Handojo Posted January 13, 2021 Share Posted January 13, 2021 Assuming that the 'lwto3d' function works properly: (defun c:mlwpto3d ( / i ss) (if (setq ss (ssget '((0 . "LWPOLYLINE")))) (repeat (setq i (sslength ss)) (lwto3d (vlax-ename->vla-object (ssname ss (setq i (1- i))))) ) ) ) Quote Link to comment Share on other sites More sharing options...
roksolid Posted January 14, 2021 Author Share Posted January 14, 2021 19 hours ago, Jonathan Handojo said: Assuming that the 'lwto3d' function works properly: (defun c:mlwpto3d ( / i ss) (if (setq ss (ssget '((0 . "LWPOLYLINE")))) (repeat (setq i (sslength ss)) (lwto3d (vlax-ename->vla-object (ssname ss (setq i (1- i))))) ) ) ) Really appreciate your input but it would be really helpful if you can show me where to add this code because to be honest I have no clue when it comes to lisp code except for running it. Thank you. Quote Link to comment Share on other sites More sharing options...
Jonathan Handojo Posted January 14, 2021 Share Posted January 14, 2021 It would certainly help if you understand how programming in AutoLISP works. For this one, you can place it at the beginning or at the very end of the LISP routine that you've got. (More specifically, somewhere that is outside of all the 'defun'.) Quote Link to comment Share on other sites More sharing options...
roksolid Posted January 16, 2021 Author Share Posted January 16, 2021 On 1/14/2021 at 11:55 PM, Jonathan Handojo said: It would certainly help if you understand how programming in AutoLISP works. For this one, you can place it at the beginning or at the very end of the LISP routine that you've got. (More specifically, somewhere that is outside of all the 'defun'.) Yes it would. I just started with autocad. No where near ready to learn Lisp programming. Still trying to figure out autocad. Appreciate your input. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.