AutoLISP: Polyline to Spline

Here is a routine that allows you to turn a “Fit Curve” Polyline into a Spline.

The key to remember with this routine is that the PolyLine has to be a “fit curve” otherwise, the routine will not work. Click HERE to learn how to make a “fit curve.”

Here’s how the routine works:

  • PL2SP <enter> to start
  • Select Polyline(s) (with Fit Curve)
  • <enter> when finished selecting
(I do not remember where I got this routine or who made it)

; Converts Polylines into Splines.

; Only works if the Polylines have been modified to a "fit-curve"

(defun pl_sel ( / orig_selset pl_selset count)

(prompt "\nSelect Polylines: ")

(setq

orig_selset (ssget)

pl_selset (ssadd)

count -1

)

(repeat (sslength orig_selset)

(setq count (1+ count))

(if (= (cdr (assoc 0 (entget (ssname orig_selset count)))) "POLYLINE")

(ssadd (ssname orig_selset count) pl_selset)

)

)

pl_selset

)

(defun vertex ( sset / count ent_sup act_ent spl_list)

(setq count 0)

(repeat (sslength sset)

(setq

ent_sup (ssname sset count)

act_ent (entnext ent_sup)

count (1+ count)

spl_list nil

)

(while (/= (cdr (assoc 0 (entget act_ent ))) "SEQEND")

(if

(or

(= (cdr (assoc 70 (entget act_ent))) 0)

(= (cdr (assoc 70 (entget act_ent))) 16)

)

(setq

spl_list

(cons (cons 11 (cdr (assoc 10 (entget act_ent)))) spl_list)

)

)

(setq

act_ent (entnext act_ent)

)

)

(setq spl_list (reverse spl_list))

(foreach

cod

(list

(assoc 8 (entget ent_sup))

(cons 74 (length spl_list))

(cons 71 3)

(cons 100 "AcDbSpline")

(cons 100 "AcDbEntity")

(cons 0 "SPLINE")

)

(setq spl_list (cons cod spl_list))

)

(entmake spl_list)

(entdel ent_sup)

)

)

;;Command line function

(defun c:pl2sp ( / oce)

(setq oce (getvar "cmdecho"))

(setvar "cmdecho" 0)

(vertex (pl_sel))

(redraw)

(setvar "cmdecho" oce)

(princ)

)

;;----------------END PROGRAM-----------------------

Advertisements

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, Modifying, Polylines, TIPS. Bookmark the permalink.

2 Responses to AutoLISP: Polyline to Spline

  1. Pingback: Spline to Polyline «

  2. asd says:

    for 2014 autocad

    1. pedit and select pline and spline
    2. spline and object and select pline

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s