How to convert 3D Polylines to 2D Polylines
I converted an Arcview Shapefile to DXF and the resulting drawing has a bunch of 3D Polylines. I need to convert these to 2D Polylines. I was exploding and then joining them together but it is taking to much time. Is there a faster or easier way to do this? There are over 100,000 3D polylines I have to do this to.
RE: How to convert 3D Polylines to 2D Polylines
Quote:
Originally Posted by boesiii
I converted an Arcview Shapefile to DXF and the resulting drawing has a bunch of 3D Polylines. I need to convert these to 2D Polylines. I was exploding and then joining them together but it is taking to much time. Is there a faster or easier way to do this? There are over 100,000 3D polylines I have to do this to.
If you just want to flatten the 3D polylines to a certain elevation and you don't care if they are still technically 3D polylines, then just use the ET "flatten" command. It will leave the entities as 3D polylines, but each vertex will be set to 0.00
If you really want to convert the 3D polyline to a 2D polyline, then ToolPac has a function to do this. The resulting entities are POLYLINE entities, but can easily be converted to LWPOLYLINE entities if desired by using the ._CONVERTPOLY command.
If you don't have ToolPac, then you can use WMFOUT and WMFIN. After you bring the entities back with WMFIN, you can use ._PEDIT to join them all back up in one swoop....
RE: How to convert 3D Polylines to 2D Polylines
Try this but very quick and dirty
Tested 1 time only on A2005
Works too slowly, approx. 2000 polylines in 8 minutes
Code:
(defun C:X3P (/ *error* adoc obj_lst ss tmp_ss)
(alert "Works slowly, converted \n
2000 polylines in 8 minutes")
(or (vl-load-com))
(defun *error* (msg)
(princ msg)
(vla-endundomark
(vla-get-activedocument
(vlax-get-acad-object)))
(princ)
)
(defun delobject (obj)
(vl-catch-all-apply
(function (lambda()
(vla-delete obj)))))
(or adoc
(setq adoc (vla-get-activedocument
(vlax-get-acad-object))))
(vla-endundomark
adoc)
(vla-startundomark
adoc)
(setvar "peditaccept" 1)
(setvar "delobj" 1)
(setq ss (ssget "_X" (list (cons 0 "POLYLINE")
(cons 100 "AcDb3dPolyline"))))
(vlax-for a (vla-get-activeselectionset adoc)
(setq obj_lst (vlax-invoke a 'Explode))
(setq tmp_ss (ssadd))
(foreach itm obj_lst
(ssadd (vlax-vla-object->ename itm) tmp_ss))
(command "._pedit" "_m" tmp_ss "" "_j" 0.000 "")
(delobject a)
(setq tmp_ss nil)
)
(*error* nil)
(princ)
)
~'J'~
RE: How to convert 3D Polylines to 2D Polylines
Quote:
Originally Posted by Opie
Why not just explode the polyline; flatten the "Previous" selection set; Pedit one of the entities; then use the Join option of the Pedit command to join the Previous selection set? Why use WMFOUT / WMFIN?
You are right. No need to export/import.
You can even save one more step. No need to ._PEDIT "one" of the entities first. You can just use ._PEDIT, window the entire selection, then use the _Join option.
In the case of other complex entities (MLINE, SPLINE, TEXT, etc.) that you may want to "explode" or "flatten", then the WMFIN/OUT trick will work.
Thanks for the catch!
RE: How to convert 3D Polylines to 2D Polylines
The main problem is when I explode 20,000 3D polylines, Autocad converts them to over 200,000 smaller lines and then that creates a huge drawing file and takes forever to join them to polylines. I just don't want to watch and wait for it to finish, but that maybe my only option.
I guess I will a little over each lunch break.
RE: How to convert 3D Polylines to 2D Polylines
Quote:
Originally Posted by Lions60
Here is just a real simple code to change all your 3d polylines into 2d Polylines. If your prefer you can get rid of the alert. It is just there to let you know what the program is doing.
Lions60, this will not work. See comments below.
Code:
(defun 3dp () ;Missing the "C:".
Yes, it will still run as (3dp), but many people won't know this.
(alert "Converting 3dPolyLines to 2DPolyLines")
(setq ss (ssget "X" '((0 . "POLYLINE")))) ;This selects all POLYLINE entities, not just 3D.
(command "explode" ss) ;This will not work. You would have to walk the selection set
and explode each one.
(setq ss (ssget "X" '((0 . "LINE"))))
(command "pedit" ss "y" "j"ss"""") ;This will fail also, because the
resulting LINE entities are still 3D.
You also fail to account for the setting of PEDITACCEPT.
Lastly, you would need the "_M" (multiple option) in there.
)
A better lisp solution would be to walk each 3D Polyline entity, scoop up the coordinates, erase it, then remake a 2D polyline in its place at the desired elevation.
RE: How to convert 3D Polylines to 2D Polylines