RvdW Posted August 14, 2021 Posted August 14, 2021 (edited) Hello, Preface: For our clients we make Autocad drawing that should only have lwpolylines without elevation. We work in external databases like GeoStruct and get all kind of Autocad drawing from colleagues and other companies. To make sure the as-build drawing for our client only has lwpolylines without elevation I have created a lisp routine that should cover all thinkable scenarios. But there is one part that I'm not happy about. Problem: By exporting data from the database to Autocad some lines/polylines get a bit screwed up. Instead of normal coordinate I get a exceptional combinations of Normal values and Coordinate values. Here an example of a lwpolyline. The true coordinates should be: (this polyline only has 2 points) - coordinates ("185306.584696" "433051.227972" "185310.277748" "433051.868141") with a Normal value of 0.0 0.0 1.0 and elevation = 0 But this is what I get: - coordinates ("-256547.616793" "0.000000" "-256551.364919" "0.000000"), with a Normal value of ("-0.170797" "0.985306" "0.000000") and elevation 395038.247133. What I do now in my routine is to Explode the polyline, change the Z values to 0 and then Pedit it back to a polyline. This works but I find this way a bit crude. Is there a better way to do this. For example get (recalculating) the correct XY coordinates using the Normal value or to "reset" the Normal value back to (0.0 0.0 1.0) and doing so restoring the XY coordinates? I have attached a drawing with one of these polylines. As you can see, the place where the line is, is actually correct. But if you look at the coordinates with VLA you see it says something different. I've put the commands below for ease; (vlax-safearray->list (vlax-variant-value (vla-get-Coordinates (vlax-ename->vla-object (car (entsel)))))) (vlax-safearray->list (vlax-variant-value (vla-get-Normal (vlax-ename->vla-object (car (entsel)))))) Polyline_isue.dwg Edited August 14, 2021 by RvdW Quote
devitg Posted August 16, 2021 Posted August 16, 2021 On 8/14/2021 at 5:19 AM, RvdW said: What about to use the VLAX (setq st-pt (vlax-curve-getStartPoint obj)) (185307.0 433051.0 0.0) (setq en-pt (vlax-curve-getEndPoint obj)) (185310.0 433052.0 0.0) to make a new lwpoly Quote
mhupp Posted August 16, 2021 Posted August 16, 2021 (edited) (setvar 'plinetype 2) ; convents all 2D polylines to optimized polylines -Edit that is weird. using ;;----------------------------------------------------------------------;; ;; Change All Elevations to 0 (defun C:ELV () (setvar 'cmdecho 0) (vl-cmdf "_.View" "S" "1") (vl-cmdf "_.View" "O" "TOP") (vl-cmdf "_.Change" "All" "" "P" "E" 0 "") (vl-cmdf "_.View" "R" "1") (setvar 'cmdecho 1) (princ) ) get this error 1 entities not parallel to UCS. its a line how is that possible???? That polyline isn't at 0 elevation. But if you explode it into a line both start and end points are. 185306.584695854, 433051.227972386, 0.0 185310.277747855, 433051.868141384, 0.0 Edited August 16, 2021 by mhupp Quote
mhupp Posted August 16, 2021 Posted August 16, 2021 On 8/14/2021 at 4:19 AM, RvdW said: What I do now in my routine is to Explode the polyline, change the Z values to 0 and then Pedit it back to a polyline. It seems after you explode everything its already at 0 elevation. Quote
BIGAL Posted August 17, 2021 Posted August 17, 2021 if you entget it has data attached that is as far as I got. (102 . "{ACAD_REACTORS") (330 . <Entity name: 3e31e2b0>) (330 . <Entity name: 3e31e3f0>) (102 . "}") a plain pline does not. Quote
RvdW Posted August 17, 2021 Author Posted August 17, 2021 13 hours ago, devitg said: What about to use the VLAX (setq st-pt (vlax-curve-getStartPoint obj)) (185307.0 433051.0 0.0) (setq en-pt (vlax-curve-getEndPoint obj)) (185310.0 433052.0 0.0) to make a new lwpoly Hi Devitg, This does give the right coordinates. I can not find a command with vlax that gives all the coordinates, but I don't think they are in the dxf either. I have another example here with 3 vertex points. Strangely enough the line is straight and the vertex points can only be changes along the line, it's like the line has been flipped to it's side. Anyway I don't think it's a garantie the lines will always be straight, though I am beginning to wonder. Any other idea how to get all 3 coordinate points? Autocad seems to know the correct coordinates. When you look at the Properties Tab and go through Vertex points it shows the coordinates exactly where you see them. Drawing1-b.dxf Quote
devitg Posted August 17, 2021 Posted August 17, 2021 Please find attached . I can get the vertex, but they seem to be for a 3dpolyline as they have the xyz Quote ((194383.0 504591.0 0.0) (194380.0 504593.0 2.0) (194378.0 504595.0 0.0)) I made it as a 3dpoly get-vertex-make new poly.lsp Polyline_isue-by vlax-curve 3 vertex.dwg Quote
RvdW Posted August 18, 2021 Author Posted August 18, 2021 (edited) Hi devitg, VLAX-CURVE-GETENDPARAM and VLAX-CURVE-GETPOINTATPARAM is what I needed. My routine is now finished, until some other exception comes forth. Here is my routine to convert all lines ( 3dpolyline, heavy polyline, lwpolylines, spline, arc, line) to standard polylines with no elevation. Thanks for the help. ;;;****************convert all lines to lwpolylines with an elevation of 0***************** ;;; Design by Roel van der Werff (RvdW) ;;; ;;; made with inspiration of Lee Mac's routine LM:intersections ;;; And with the help of Gabo CALOS DE VIT (devitg) for the vlax-curve commands ;;; ;;; add (setq all->lw0 1) before running the routine for princ text instead of an alert textbox (defun c:all->lw0 ( / ) (vl-load-com) (setq errorlst nil) ;; convert all "lines" and "arc's" to lwpolyline with elevation 0 (RvdW:lines_to_pl0) (if (/= line_conv nil) (setq amount line_conv) (setq amount 0) ) ;; convert all 3dpolylines, heavy polylines and splines to lwpolylines with elevation 0 (cond ((/= (setq lst_lines (ssget "A" '( (-4 . "<OR") (-4 . "<AND") (0 . "LWPOLYLINE") (-4 . "<>") (38 . 0) (-4 . "AND>") (0 . "SPLINE,POLYLINE") (-4 . "OR>") ) ) ; ssget ) ; setq lst_lines nil) (setq amount (+ amount (sslength lst_lines))) (repeat (setq #_lst_line (sslength lst_lines)) (setq obj_line (ssname lst_lines (setq #_lst_line (- #_lst_line 1)))) (RvdW:conv_to_pl obj_line); (setq obj obj_line) ) ; repeat ) ; cons lst_lines ) ; cons ;; check and adjust "Thickness" of lwpolylines to 0 (cond ((/= (setq lst_lines (ssget "A" '((0 . "LWPOLYLINE") (-4 . "<>") (39 . 0)))) nil) (repeat (setq #_lst_line (sslength lst_lines)) (vla-put-thickness (vlax-ename->vla-object (ssname lst_lines (setq #_lst_line (- #_lst_line 1)))) 0.0) ) ) ) ;; alerts and messages (if (/= all->lw0_silent 1) (alert (strcat "-->> "(rtos amount 2 0)" lijn(en) aangepast.\n-->> "(rtos line_del 2 0)" lijn(en) met een lengte van 0 verdwijderd")) (princ (strcat "\n-->> "(rtos amount 2 0)" lijn(en) aangepast. "(rtos line_del 2 0)" lijn(en) met een lengte van 0 verdwijderd"))) (if (/= errorlst nil) (alert (strcat "Oeps, het lijkt erop dat ik " (rtos (sslength errorlst) 2 0) " lijn(en) niet heb kunnen omzetten." "\nDe probleem lijnen staan in de lijst ERRORLST")) ) ) ; defun ;;;***********************end convert all lines to lwpolylines at 0************************ ;;;************************Lines and arc's to 0 -> lwpolyline****************************** ;;;convert lines with z value and arc's to lwpolylines with elevation 0 (defun RvdW:lines_to_pl0 ( / ) (setq line_del 0) (cond ((/= (setq line_list (ssget "_A" '((0 . "line,arc")))) nil) ;; check if XY-start & XY-end are the same (repeat (setq #_line_list (sslength line_list)) (setq obj_l (ssname line_list (setq n_line_list (setq #_line_list (- #_line_list 1))))) (cond ((and (= (car (vlax-safearray->list (vlax-variant-value (vla-get-startpoint (vlax-ename->vla-object obj_l))))) (car (vlax-safearray->list (vlax-variant-value (vla-get-endpoint (vlax-ename->vla-object obj_l)))))) (= (cadr (vlax-safearray->list (vlax-variant-value (vla-get-endpoint (vlax-ename->vla-object obj_l))))) (cadr (vlax-safearray->list (vlax-variant-value (vla-get-startpoint (vlax-ename->vla-object obj_l)))))) );and XY (ssdel obj_l line_list) (vla-delete (vlax-ename->vla-object obj_l)) (setq line_del (+ line_del 1)); for the end message );cond - length 0 );cond );repeat ;; check to see if the line needs to be recreated (setq line_conv (sslength line_list)); for the end message (repeat (setq #_line_list (sslength line_list)) (setq obj_l (ssname line_list (setq n_line_list (setq #_line_list (- #_line_list 1))))) (cond ((or (/= (nth 2 (vlax-get (vlax-ename->vla-object obj_l) 'Startpoint)) 0) (/= (nth 2 (vlax-get (vlax-ename->vla-object obj_l) 'Endpoint)) 0) (= (vlax-get (vlax-ename->vla-object obj_l) 'ObjectName) "AcDbArc") ) ;; create new line if the original one does not pass the checklist (entmakex (list (cons 0 "LINE") (cons 8 (vlax-get (vlax-ename->vla-object obj_l) 'Layer)) (cons 10 (list (nth 0 (vlax-safearray->list (vlax-variant-value (vla-get-startpoint (vlax-ename->vla-object obj_l))))) (nth 1 (vlax-safearray->list (vlax-variant-value (vla-get-startpoint (vlax-ename->vla-object obj_l))))) 0.0)) (cons 11 (list (nth 0 (vlax-safearray->list (vlax-variant-value (vla-get-endpoint (vlax-ename->vla-object obj_l))))) (nth 1 (vlax-safearray->list (vlax-variant-value (vla-get-endpoint (vlax-ename->vla-object obj_l))))) 0.0)) );list );entmakes (ssdel obj_l line_list) (vla-delete (vlax-ename->vla-object obj_l)) );cond - line check );cond );repeat (vl-cmdf "pedit" "m" (ssget "a" ' ((0 . "LINE"))) "" "Y" "join" "" "") );line,arc );cond );defun ;*******************************end Lines to 0 -> Pline************************************ ;;;***************************convert non lines to lwpolyline****************************** ;;; ;;; checkes the type op polyline ro spline and creates an new lwpolyline with elevation 0 ;;; ;;; start RvdW:conv_to_pl with ssname object (defun RvdW:conv_to_pl ( obj / ) (setq rtn nil new_obj nil) ;; separating 3d polyline, heavy polyline and spline from polyline with elevation value (cond ((or (= (vla-get-objectname (vlax-ename->vla-object obj)) "AcDb3dPolyline") (= (vla-get-objectname (vlax-ename->vla-object obj)) "AcDb2dPolyline") (= (vla-get-objectname (vlax-ename->vla-object obj)) "AcDbSpline")) ;; separating 3d polyline and heavy polyline from spline to get the correct 3d coördinations (cond ((or (= (vla-get-objectname (vlax-ename->vla-object obj)) "AcDb3dPolyline") (= (vla-get-objectname (vlax-ename->vla-object obj)) "AcDb2dPolyline")) (setq lst (vlax-safearray->list (vlax-variant-value (vla-get-Coordinates (vlax-ename->vla-object obj)))))) ((= (vla-get-objectname (vlax-ename->vla-object obj)) "AcDbSpline") ;; making sure the splinemethod is 0 (if (= (vla-get-SplineMethod (vlax-ename->vla-object obj)) 1) (vla-put-SplineMethod (vlax-ename->vla-object obj) 0) ) (setq lst (vlax-safearray->list (vlax-variant-value (vla-get-FitPoints (vlax-ename->vla-object obj))))))) ;; creating 2d coördination list (repeat (/ (length lst) 3) (setq rtn (cons (list (car lst) (cadr lst)) rtn) lst (cdddr lst) ) ) ; repeat rtn ) ; cond 2d, 3d or spline ;; the object is a lwpolyline with elevation value ((= (vla-get-objectname (vlax-ename->vla-object obj)) "AcDbPolyline") ;; condition added for lwpolylines woth Normal Value other then 0.0 0.0 1.0 (cond ((equal (vlax-safearray->list (vlax-variant-value (vla-get-normal (vlax-ename->vla-object obj)))) '(0.0 0.0 -1.0)) ;; creating new 2d coördinate list with positive x value (setq lst (vlax-safearray->list (vlax-variant-value (vla-get-Coordinates (vlax-ename->vla-object obj))))) (repeat (/ (length lst) 2) (setq rtn (cons (list (* (car lst) -1) (cadr lst)) rtn) lst (cddr lst) ) );repeat );cond lwpolyline with negative x ((equal (vlax-safearray->list (vlax-variant-value (vla-get-normal (vlax-ename->vla-object obj)))) '(0.0 0.0 1.0)) ;; creating 2d coördinate list (setq lst (vlax-safearray->list (vlax-variant-value (vla-get-Coordinates (vlax-ename->vla-object obj))))) (repeat (/ (length lst) 2) (setq rtn (cons (list (car lst) (cadr lst)) rtn) lst (cddr lst) ) );repeat );cond lwpolyline with positive x value (T ;; creating 2d coördinate list for polyline with non 0.0 0.0 x value ;; with the help of Gabo CALOS DE VIT (repeat (setq #_vertex (fix (+ (VLAX-CURVE-GETENDPARAM OBJ) 1))) (setq #_vertex (- #_vertex 1)) (SETQ rtn (CONS (list (car (VLAX-CURVE-GETPOINTATPARAM OBJ #_vertex)) (cadr (VLAX-CURVE-GETPOINTATPARAM OBJ #_vertex)) ) rtn)); setq rtn );repeat - create vertex list );; Added for incorrect exporded lwpolylines with rare Normal value. ) ) ; cond lwpolyline ) ; cond ;; creating new lwpolyline without elevation value (cond ((/= rtn nil) (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 8 (vla-get-layer (vlax-ename->vla-object obj))) (cons 370 (vla-get-lineweight (vlax-ename->vla-object obj))) (cons 6 (vla-get-linetype (vlax-ename->vla-object obj))) (cons 62 (vla-get-color (vlax-ename->vla-object obj))) (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length rtn)) (if (= (vla-get-Closed (vlax-ename->vla-object obj)) :vlax-true) (cons 70 1) (cons 70 0) ) ; cond cons 70 ) ; list (mapcar (function (lambda (p) (cons 10 p))) rtn) ) ; append ) ; entmakex ;; cleaning up old line (vla-erase (vlax-ename->vla-object obj)) ); cond making new lwpolyline ;; creating list of objects that did not pass any condition ((= rtn nil) (if (= errorlst nil) (progn (setq errorlst (SSADD)) (ssadd obj errorlst)) (ssadd obj errorlst));(setq errorlst nil) ); cond errorlst ) ; cond ) ; defun (princ "\n Module all->lw0 by RvdW is loaded. version: 18-8-2021") (princ) ;;;**************end convert all lines to lwpolylines with an elevation of 0*************** RvdW's all to lwpoly.LSP Edited August 18, 2021 by RvdW Quote
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.