poly line to sp line

poly line to sp line

abrariqbal
Enthusiast Enthusiast
1,459 Views
5 Replies
Message 1 of 6

poly line to sp line

abrariqbal
Enthusiast
Enthusiast

Is there No way to convert a poly line to spline not 2d poly line

 

if not then i need a LSP to convert poly line to spline i need it don't make extra curves and smooting in poly line while converting in spline but i need same same as it was in poly line form......no extra smooting and curves while converting to spline.....just need a LSP to to convert poly line to spline

 

 

thanks in advance

0 Likes
1,460 Views
5 Replies
Replies (5)
Message 2 of 6

marko_ribar
Advisor
Advisor

Here you go...

 

(defun c:lw2spl ( / *error* arc2spl line2spl loop pl e s ss sss )

  (vl-load-com)

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

  (defun arc2spl ( e / make_spline points q1 q2 a pc f pe ps w )

           (setq q1 (vlax-curve-GetStartParam e)
                 q2 (vlax-curve-GetEndParam e)
                 a  (/ (- (vlax-curve-GetEndParam e) (vlax-curve-GetStartParam e)) 3.0) ; a - parameter interval... and angle
                 pc (mapcar                              ; pc - points on contur
                      (function
                        (lambda (p)
                         (vlax-curve-GetPointAtParam e p)
                          )
                        )
                      (list q1 (+ q1 a) (- q2 a) q2)
                    )
                 f  (mapcar                               ; f - first deriv on pc
                      (function
                        (lambda (p)
                          (vlax-curve-GetFirstDeriv e p)
                          )
                        )
                      (list q1 (+ q1 a) (- q2 a) q2)
                    )
                 pe (mapcar                              ; pe - extra control points for spline construction
                      (function
                        (lambda (p1 p2 d1 d2)
                          (inters p1 (mapcar '+ p1 d1)
                                  p2 (mapcar '+ p2 d2)
                                  nil
                                  )
                        )
                      )
                     pc (cdr pc) f (cdr f)
                    )
                 ps  (list (car pc) (car pe) (cadr pc) (cadr pe) (caddr pc) (caddr pe) (cadddr pc)) ; ps - control points for spline
                 w   (list 1.0 (cos (/ a 2)) 1.0 (cos (/ a 2)) 1.0 (cos (/ a 2)) 1.0)  ; weights for spline
           )

    (defun make_spline ( pts )
      (entmakex
        (append
           '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline")
              (70 . 4) (71 . 2) (72 . 10) (73 . 7) (74 . 0)
              (42 . 1.0e-010) (43 . 1.0e-010)
              (40 . 0.0) (40 . 0.0) (40 . 0.0) (40 . 1.0) (40 . 1.0)
              (40 . 2.0) (40 . 2.0) (40 . 3.0) (40 . 3.0) (40 . 3.0))
           pts
        )
      )
    )

    (defun points ( p w )
      (apply 'append (mapcar '(lambda (a b) (list (cons 10 a) (cons 41 b))) p w))
    )

    (entdel e)
    (make_spline (points ps w))

  )

  (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))))) "LWPOLYLINE")) (setq loop nil))
  (while loop
    (setq pl (car (entsel "\nPick LWPOLYLINE to convert it to SPLINE")))
    (if (and pl (eq (cdr (assoc 0 (entget pl))) "LWPOLYLINE")) (setq loop nil))
  )
  (setq e (entlast))
  (command "_.EXPLODE" pl)
  (while (> (getvar 'cmdactive) 0) (command ""))
  (setq ss (ssadd))
  (while (setq e (entnext e))
    (if (eq (cdr (assoc 0 (entget e))) "LINE")
      (progn
        (setq s (line2spl e))
        (ssadd s ss)
      )
    )
    (if (eq (cdr (assoc 0 (entget e))) "ARC")
      (progn
        (setq s (arc2spl e))
        (ssadd s ss)
      )
    )
  )
  (command "_.JOIN" (ssname ss 0) ss)
  (while (> (getvar 'cmdactive) 0) (command ""))
  (*error* nil)
)

HTH, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 6

stevor
Collaborator
Collaborator

See the solutin of  'phanaem. 09-22-2013'

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/3d-polyline-to-polyline-to-spline-wit...

 

And others, via a google search r 2.

S
0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

Use PEDIT and the Spline option on the Polyline, then use SPLINE and its Object option.

Kent Cooper, AIA
0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

Use PEDIT and the Spline option on the Polyline, then use SPLINE and its Object option.


... which can be automated [in kind of minimal terms, and minimally tested]:

 

(defun C:P2S (/ pl); = Polyline [to] Spline
  (setq pl (car (entsel "\nSelect Polyline to convert to Spline: ")))
  (command
    "_.pedit" pl "_spline" ""
    "_.spline" "_object" "_last" ""
    "_.erase" pl ""
  ); command
  (princ)
); defun

Kent Cooper, AIA
0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

....
    "_.spline" "_object" "_last" ""
....

Make that line:

 

....

  "_.spline" "_object" pl ""

....

 

instead.  I was expecting that the result of spline-curving the Polyline would be a different [and therefore a new, and the last] entity than the original Polyline, since if it starts as a LWPolyline, it ends up as a different entity type.  But it occurred to me to check that, and it does retain its original entity name.  That means that the "_last" selection would find something else if that Polyline wasn't the last thing drawn.  But it also means it can [and must, actually] use that same variable for turning it into a Spline.

Kent Cooper, AIA
0 Likes