Community
Civil 3D Forum
Welcome to Autodesk’s Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Convert Multiple 3D Polylines to 2D with original layers and linetypes

4 REPLIES 4
Reply
Message 1 of 5
roberte
5181 Views, 4 Replies

Convert Multiple 3D Polylines to 2D with original layers and linetypes

Have been struggling to find a LISP that will convert 3D polylines to 2D polylines (with only X and Y vertex) while retaining the original layers and linetypes selected in the 3D polyline.

 

Many forums refer to using the flatten command to convert them to 2D however this just means the 3D polyline is a zero depth. I managed to find a LISP that will convert 3d polines to 2d after the flatten command is used so that all the polylines with not have a Z vertex. The routine works by esentially drawing over the 3D polyline with a 2D polyline and then deleting the 3D polyline. 

 

;;CADALYST 09/03 AutoLISP Solutions
;;; PLINE-3D-2D.LSP - a program to convert
;;; 3D polylines to 2D
;;; Program by Tony Hotchkiss

(defun C:pline-3d-2d ()
  (vl-load-com)
  (setq *thisdrawing* (vla-get-activedocument
   (vlax-get-acad-object)
        ) ;_ end of vla-get-activedocument
 *modelspace*  (vla-get-ModelSpace *thisdrawing*)
  ) ;_ end of setq
  (setq 3d-pl-list
  (get-3D-pline)
  ) ;_ end of setq
  (if 3d-pl-list
    (progn
      (setq vert-array-list (make-list 3d-pl-list))
      (setq n (- 1))
      (repeat (length vert-array-list)
 (setq vert-array (nth (setq n (1+ n)) vert-array-list))
 (setq lyr (vlax-get-property (nth n 3d-pl-list) 'Layer))
 (setq obj (vla-AddPolyline *modelspace* vert-array))
 (vlax-put-property obj 'Layer lyr)
      ) ;_ end of repeat
      (foreach obj 3d-pl-list (vla-delete obj))
    ) ;_ end of progn
  ) ;_ end of if
) ;_ end of pline-3d-2d

(defun get-3D-pline ()
  (setq pl3dobj-list nil
 obj      nil
 3d      "AcDb3dPolyline"
  ) ;_ end of setq
  (setq selsets (vla-get-selectionsets *thisdrawing*))
  (setq ss1 (vlax-make-variant "ss1"))
  (if (= (vla-get-count selsets) 0)
    (setq ssobj (vla-add selsets ss1))
  ) ;_ end of if
  (vla-clear ssobj)
  (setq Filterdata (vlax-make-variant "POLYLINE"))
  (setq no-ent 1)
  (while no-ent
    (vla-Selectonscreen ssobj)
    (if (> (vla-get-count ssobj) 0)
      (progn
 (setq no-ent nil)
 (setq i (- 1))
 (repeat (vla-get-count ssobj)
   (setq
     obj (vla-item ssobj
     (vlax-make-variant (setq i (1+ i)))
  ) ;_ end of vla-item
   ) ;_ end of setq
   (cond
     ((= (vlax-get-property obj "ObjectName") 3d)
      (setq pl3dobj-list
      (append pl3dobj-list (list obj))
      ) ;_ end of setq
     )
   ) ;_ end-of cond
 ) ;_ end of repeat
      ) ;_ end of progn
      (prompt "\nNo entities selected, try again.")
    ) ;_ end of if
    (if (and (= nil no-ent) (= nil pl3dobj-list))
      (progn
 (setq no-ent 1)
 (prompt "\nNo 3D-polylines selected.")
 (quit)
      ) ;_ end of progn
    ) ;_ end of if
  ) ;_ end of while 
  (vla-delete (vla-item selsets 0))
  pl3dobj-list
) ;_ end of get-3D-pline


(defun get-3D-pline-old ()
  (setq no-ent 1)
  (setq filter '((-4 . "<AND")
   (0 . "POLYLINE")
   (70 . 😎
   (-4 . "AND>")
  )
  ) ;_ end of setq
  (while no-ent
    (setq ss        (ssget filter)
   k        (- 1)
   pl3dobj-list nil
   obj        nil
   3d        "AcDb3dPolyline"
    ) ;_ end-of setq
    (if ss
      (progn
 (setq no-ent nil)
 (repeat (sslength ss)
   (setq ent (ssname ss (setq k (1+ k)))
  obj (vlax-ename->vla-object ent)
   ) ;_ end-of setq
   (cond
     ((= (vlax-get-property obj "ObjectName") 3d)
      (setq pl3dobj-list
      (append pl3dobj-list (list obj))
      ) ;_ end of setq
     )
   ) ;_ end-of cond
 ) ;_ end-of repeat
      ) ;_ end-of progn
      (prompt "\nNo 3D-polylines selected, try again.")
    ) ;_ end-of if
  ) ;_ end-of while
  pl3dobj-list
) ;_ end of get-3D-pline-old

(defun make-list (p-list)
  (setq i (- 1)
 vlist nil
 calist nil
  ) ;_ end of setq
  (repeat (length p-list)
    (setq obj  (nth (setq i (1+ i)) p-list)
   coords (vlax-get-property obj "coordinates")
   ca  (vlax-variant-value coords)
    ) ;_ end-of setq
    (setq calist (append calist (list ca)))
  ) ;_ end-of repeat
) ;_ end-of make-list

(defun c:pl32 ()
  (pline-3d-2d)
  (princ)
) ;_ end of pl32

(prompt "Enter PL32 to start: ")

 

However if you run the LISP it will redraw over all the lines in whichever layer you have selected in the layer manager. For example if you had layer 0 selected in the layer manager and then selected multiple 3D polylines selected with say 3 different layers and run it though the routine then all the polylines would become 2D polylines in layer 0.

 

Does anyone know how to update this script so that when it draws each of the 2D polylines they will retain the layer properties of each of the 3D polylines as this will save me having to select one layer at a time to convert the all the 3D polylines to 2D.

 

Thanks

4 REPLIES 4
Message 2 of 5
Jay_B
in reply to: roberte

Have you tried using the built in _AeccConvert3dPolys command which converts 3d polys to 2d polys?

C3D 2018.1
C3D 2016 SP4

Win 7 Professional 64 Bit
Message 3 of 5
roberte
in reply to: Jay_B

Forgot to mention I am using Autocad 2012, not Civils 3D so I do not have that function available

Message 4 of 5
Jay_B
in reply to: roberte

In that case, try this method:

 

Make a copy of the file if you wish to preserve the 3d poly's etc.

 

1. Explode all of the 3d polylines you wish to convert.

2. Run the FLATTEN command on all resulting lines.

3. Run PEDIT command > choose "Multiple" option > Join them (it will join all at once as separate plines).

 

Done.

C3D 2018.1
C3D 2016 SP4

Win 7 Professional 64 Bit
Message 5 of 5
roberte
in reply to: Jay_B

I tried what you suggested but couldn't getb it to work. so i tried to select multiple lines and run the script to see what happens and found out that the problem was that it reset the layers colour to default. So the problem occured because in the drawing I was using someone had set the default layers colours to white so i thought it was changing to whichever layer i had selected but in fact it had only reverted to default colour

 

So the problem was with the drawing not the routine.

 

Thanks for your help

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report