;;; Convert All 3D Polylines to 2D Polylines
;;; Created by peter.. saved from here: http://forums.augi.com/showthread.php?52607-How-to-convert-3D-Polylines-to-2D-Polylines
;;; Slightly modified by Igal Averbuh 2017 (added option for all 3D Polylines)

(defun C:P3D (/ intCount
lstCoordiantes
objDocument
obj2dPolyline
obj3dPolyline
ssSelections
strProperty
)
(if (setq ssSelections (ssget "X" (list (cons 0 "polyline"))))
(vlax-for obj3dPolyline (vla-get-activeselectionset
(setq objDocument (vla-get-activedocument
(vlax-get-acad-object))))
(if (= (vla-get-objectname obj3dPolyline) "AcDb3dPolyline")
(progn
(setq intCount 0
lstCoordinates (mapcar
'(lambda (sngCoordinate)
(if (= (/ (setq intCount (1+ intCount)) 3.0)
(/ intCount 3)
)
nil
sngCoordinate
)
)
(vlax-get obj3dPolyline "coordinates")
)
lstCoordinates (vl-remove nil lstCoordinates)
obj2dPolyline (vla-addlightweightpolyline
(vla-get-block
(vla-get-activelayout objDocument))
(listtosafearray 5 lstCoordinates))
)
(foreach strProperty (list "truecolor" "layer" "linetype" "closed")
(vlax-put obj2dPolyline strProperty (vlax-get obj3dPolyline strProperty))
)
(vla-delete obj3dPolyline)
)
)
)
)
(princ)
)

; This function creates a safearray from a list and the safearray type symbol
; for example: (listtosafearray vlax-vbinteger (list 0) )

(defun ListToSafeArray (symSafeArrayType lstItems / safArray)
(setq safArray (vlax-make-safearray symSafeArrayType (cons 0 (1- (length lstItems)))))
(vlax-safearray-fill safArray lstItems)
)

;vlax-vbInteger (2) Integer
;vlax-vbLong (3) Long integer
;vlax-vbSingle (4) Single-precision floating-point number
;vlax-vbDouble (5) Double-precision floating-point number
;vlax-vbString (8) String
;vlax-vbObject (9) Object
;vlax-vbBoolean (11) Boolean
;vlax-vbVariant (12) Variant

(prin1)
(c:p3d)

Advertisements