Author Topic: Converting 3d polylines to 2d polylines  (Read 6112 times)

0 Members and 1 Guest are viewing this topic.

Mike H

  • Guest
Converting 3d polylines to 2d polylines
« on: February 23, 2007, 10:57:49 AM »
Hello All,

Is it possible to convert a 3d polyline to a 2d polyline in acad 2004????

Josh Nieman

  • Guest
Re: Converting 3d polylines to 2d polylines
« Reply #1 on: February 23, 2007, 11:12:03 AM »
Hello All,

Is it possible to convert a 3d polyline to a 2d polyline in acad 2004????

Do you have "flatten" in the express tools?

If not, about the only thing I know to do is explode it, then set "begin Z" and "end Z" for all lines resulting to zero, or whatever elevation.  then join them into a 2dpolyline.

Guest

  • Guest
Re: Converting 3d polylines to 2d polylines
« Reply #2 on: February 23, 2007, 11:19:17 AM »
Give this a shot...

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

(defun 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 . 8)
(-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: ")

reyas1123

  • Newt
  • Posts: 50
Re: Converting 3d polylines to 2d polylines
« Reply #3 on: January 30, 2017, 05:26:34 AM »
hi,
can somebody solve this error
I tried to run this lisp but i got this error


; error: bad argument type: VLA-OBJECT nil

thanks
rey

ChrisCarlson

  • Guest
Re: Converting 3d polylines to 2d polylines
« Reply #4 on: February 01, 2017, 08:31:50 AM »
My guess is that you have another lisp routine interfering, were you able to find out which line the routine is breaking on?

Running the routine here works as expected.