Tamas Kosa
Tamas Kosa

Reputation: 352

Change 3d polyline to spline in Autocad with lisp

I have a working lisp which creates spline from 3d polylines. My problem is I cant make it work to select multiple 3d polylines or entire layer, and also a lisp changes the result layer to the default layer. It should kept on the original one. Here is my working lisp:

(defun c:3p2spl ( / *error* line2spl loop pl e s ss sss )

  (vl-load-com)

  (defun *error* ( msg )
    (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
  )

  (defun line2spl ( e / sp ep d )

    (setq sp (cdr (assoc 10 (entget e)))
          ep (cdr (assoc 11 (entget e)))
          d (distance sp ep)
    )

    (entdel e)

    (entmakex
      (list
        '(0 . "SPLINE") '(100 . "AcDbEntity") '(100 . "AcDbSpline") '(210 0.0 0.0 1.0) '(71 . 1) '(73 . 2)
        '(42 . 1.0e-010) '(43 . 1.0e-010) '(40 . 0.0) '(40 . 0.0) (cons 40 d) (cons 40 d) (cons 10 sp) (cons 10 ep)
      )
    )

  )

  (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))  
  (setq loop T)
  (setq sss (ssget "_I"))
  (if (and sss (eq (cdr (assoc 0 (entget (setq pl (ssname sss 0))))) "POLYLINE") (< 7 (cdr (assoc 70 (entget pl))) 14)) (setq loop nil))
  (while loop
    (setq pl (car (entsel "\nPick 3DPOLYLINE to convert it to SPLINE")))
    (if (and (eq (cdr (assoc 0 (entget pl))) "POLYLINE") (< 7 (cdr (assoc 70 (entget pl))) 14)) (setq loop nil))
  )
  (setq e (entlast))
  (command "_.explode" pl "")
  (setq ss (ssadd))
  (while (setq e (entnext e))
    (if (eq (cdr (assoc 0 (entget e))) "LINE")
      (progn
        (setq s (line2spl e))
        (ssadd s ss)
      )
    )
  )
  (command "_.join" (ssname ss 0) ss "")
  (*error* nil)
  (princ)
)

if I change the ssget "_I" to ssget "_:E" I can select multiple lines however it will change to spline only the first one.

Upvotes: 0

Views: 1233

Answers (1)

CAD Developer
CAD Developer

Reputation: 1697

I didn't test this code, only read, so maybe I'm wrong, but I thing the problem is because:

...
(setq pl (ssname sss 0))
...
(command "_.explode" pl "")

You explode only first entity. I think

(command "_.explode" pl "")

should be used inside loop by all sss items.

Upvotes: 2

Related Questions