home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Share Gallery 1
/
share_gal_1.zip
/
share_gal_1
/
GR
/
GR505.ZIP
/
LSP.EXE
/
TR2PL.LSP
< prev
next >
Wrap
Lisp/Scheme
|
1989-09-06
|
4KB
|
75 lines
;tr2pl.lsp - by c.l.smith, stardot lsp, houston, tx.
;routine to replace traces with plines. you can convert all layers, or only
;one at a time, keeping the original trace widths or replacing all with fixed
;width of your choice.
;global variables: ndx = holds tentative position in selection set
; ss = selection set of traces to be processed
;note that some undocumented acad variables are used in this routine.
(defun aval (a l / ) ;returns value from association list
(cdr (assoc a l)))
(defun convrt ( / pl1 pl2 clist) ;the meat of it
(setq pl1 (entget (ssname ss ndx)) ;get first segment
pl2 (if (> ndx 0) (entget (ssname ss (- ndx 1))) nil) ;get next segment
ndx (- ndx 1)) ;increment the index
(command "layer" "s" (aval 8 pl1) "") ;set layer (redundant for 1 layer)
(setq clist ;start command list to draw
(list "pline" ;a pline from 1st point
(midpnt (aval 10 pl1) (aval 11 pl1))
"w" ;set the width
(if fixwid fixwid (distance (aval 10 pl1) (aval 11 pl1)))
"" ;no tapered pee lines, ok?
(midpnt (aval 12 pl1) (aval 13 pl1)))) ;to 2nd point
(while (and pl2 (apply 'and ;check next segment for continuation. if
(mapcar 'equal ;ends are equal then add next point to
(list (aval 12 pl1) (aval 13 pl1)) ;command list and
(list (aval 10 pl2) (aval 11 pl2))))) ;test next segment
(write-line "Match found!") ;oterwise exit & draw
(setq clist (append clist (list (midpnt (aval 12 pl2) (aval 13 pl2))))
pl1 pl2
pl2 (if (> ndx 0) (entget (ssname ss (- ndx 1))) nil)
ndx (- ndx 1)))
(setq clist (append clist '("")))
(apply 'command clist))
(defun delall (s / len n) ;passed a selection set, entity-deletes it
(setq len (sslength s)
n 0)
(while (< n len)
(entdel (ssname s n))
(setq n (+ 1 n))))
(defun getall ( e l / ) ;returns selection set of all entities of type "e"
(ssget "x" ;on the layer "l"
(if (= l "*") (list (cons 0 (strcase e)))
(list (cons 0 (strcase e)) (cons 8 l)))))
(defun midpnt (p1 p2 / ) ;returns midpoint between p1 and p2
(polar p1 (angle p1 p2) (/ (distance p1 p2) 2.0)))
(defun c:tr2pl ( / savars layr ) ;traces to plines command
(setvar "useri1" (getvar "highlight")) ;store variables
(setvar "useri2" (getvar "blipmode"))
(setvar "highlight" 0) ;adjust as desired
(setvar "blipmode" 0)
(setq layr "doodah")
(setq layr (getstring "\nLayer name to convert, * for all: "))
(initget 1 "Y N")
(setq fixwid
(if (= (getkword "\nUse original width (Y/N)? ") "N")
(getreal "Width for all plines: ") nil)
ss (getall "trace" layr))
(if ss (progn
(setq ndx (- (sslength ss) 1))
(write-line (strcat (itoa (sslength ss)) " traces to process."))
(while (>= ndx 0)
(write-line (strcat "Processing " (itoa ndx)))
(convrt))
(delall ss)
(redraw))
(prompt "Couldn't find a trace"))
(setvar "highlight" (getvar "userr1" ))
(setvar "blipmode" (getvar "userr2" ))
'done (princ))