AutoLISP: Saving Your New LineType

So, after you have used the previous LISP routine to create your new linetype, you need to save it if you plan on using it in other drawings. Sure, you could just re-use the previous routine in the drawing, but you may just want the new linetype to be available in all of your drawings. In your AutoCAD support folder, you have a .lin file. this is where your linetypes are stored. Just because you made a new linetype in one drawing doesn’t mean that it is stored in this “master” linetype file. You have to do this yourself. Welcome to the world of customizing AutoCAD…

This Lisp routine is awesome. It takes the info for the all the linetypes that have been loaded in your current drawing and prints out a new .lin file where you can easily copy the info from the new linetype and paste t into the “master” linetype file for future use.

To do this:

  • NEW-LIN <enter> to start
  • A message box appears that tells you that a new .lin file has been made.
  • Go to the new file (the default place where you have told AutoCAD to open and save files is where this file will be found). By default, AutoCAD saves files in the “My Documents” folder.
  • Open the “new-acad.lin” file.
  • Copy & Paste the info for your new linetype into the master .lin file…
  • If you have AutoCAD 2011, change the “r” in the linetype to “u.” The “r” is so that you can “reverse” the linetype. The “u” is something that AutoCAD 2011 introduced that keeps the text “UP”.

 

 

 

 

 

 

 

 

 

 


;|

NEW-LIN.LSP -- (c) 2000 Tee Square Graphics

NEW-LIN is a useful AutoLISP routine that extracts parameters for

unknown LineTypes in a drawing, and creates entries in a new LineType

definition file, NEW-ACAD.LIN. After extraction, the LineType definitions

may be moved to ACAD.LIN or any other *.LIN file desired by the user.

This version of NEW-LIN.LSP functions fully with simple LineTypes, and

Complex LineTypes composed of linear elements and Text objects. Because

of difficulty in extracting Shape data from shape definition (*.shx)

files, the user may, for the time being, have to supply the appropriate

name for the Shape represented by {Shape #nnn} in NEW-ACAD.LIN, in cases

where the associated Shape Source File (*.shp) is unavailable.

|;

(defun C:NEW-LIN (/ flag outf ltname tblent tblist i desc alist acode value

rot shpno shxfl shpfl inf dat n shpnm flg txt sty)

(setq flag (findfile "new-acad.lin")

outf (open (if flag flag "new-acad.lin") "w"))

(write-line ";;" outf)

(write-line ";; New LineType descriptions extracted" outf)

(write-line ";; from existing drawing(s) by NEW-LIN.LSP." outf)

(write-line ";;" outf)

(write-line ";; NEW-LIN.LSP (c) 2000 Tee Square Graphics" outf)

(write-line ";;\n" outf)

(setvar "luprec" 8)

(setvar "auprec" 8)

(tblnext "ltype" T)

(while (setq tblent (tblnext "ltype"))

(setq ltname (cdr (assoc 2 tblent))

tblent (tblobjname "ltype" ltname)

tblist (entget tblent)

i 1

desc "A,")

(write-line (strcat "*" (cdr (assoc 2 tblist)) "," (cdr (assoc 3 tblist)))

outf)

(while (< i (length tblist))

(setq alist (nth i tblist)

acode (car alist)

value (cdr alist))

(cond

((= acode 49)

(setq desc (strcat desc (trim (rtos value 2 8)) ",")))

((= acode 74)

(setq flag (if (= (logand value 4) 4) T nil)

rot (if (= (logand value 1) 1) "a" "r")))

((= acode 75)

(setq shpno (itoa value)))

((= acode 340)

(if flag

(progn

(setq shxfl (cdr (assoc 3 (entget value)))

shpfl (strcat (substr shxfl 1 (- (strlen shxfl) 3)) "shp"))

(if (setq inf (findfile shpfl))

(progn

(setq inf (open inf "r"))

(while (setq dat (read-line inf))

(if (wcmatch dat (strcat "`*" shpno "*"))

(progn

(setq n 1)

(repeat 2

(while (/= (substr dat n 1) ",")

(setq n (1+ n)))

(setq n (1+ n)))

(setq shpnm (substr dat n)))))

(close inf)))))

(setq flg flag

txt (if flag

(if shpnm shpnm (strcat "{Shape #" shpno "}"))

(strcat "\"" (cdr (assoc 9 (member alist tblist))) "\""))

sty (if flag

(cdr (assoc 3 (entget value)))

(cdr (assoc 2 (entget value))))

desc (strcat desc "\n[" txt "," sty ",s="

(trim (rtos (cdr (nth (1+ i) tblist)) 2 8)) "," rot "="

(trim (angtos (cdr (nth (+ i 2) tblist)) 0 8)) ",x="

(trim (rtos (cdr (nth (+ i 3) tblist)) 2 8)) ",y="

(trim (rtos (cdr (nth (+ i 4) tblist)) 2 8)) "],\n")

i (+ i 4)))

(T nil))

(setq i (1+ i)))

(write-line (substr desc 1 (1- (strlen desc))) outf)

(write-line " " outf))

(close outf)

(alert (strcat "All loaded LineTypes in the current drawing database have

been\n"

"duplicated in a new LineType definition file, NEW-ACAD.LIN.\n"

"Any complex LineTypes using Shape Definitions for which no\n"

"source file (*.shp) could be found will contain a reference in\n"

"curly braces { }; the user must supply the correct shape name\n"

"before NEW-ACAD.LIN can be used to load these LineTypes."))

(setq new-acad(findfile"new-acad.lin"))

(princ (strcat "\nYour new linetype definition file is located at: "

new-acad))

(princ)

)

(defun trim (x / i)

(setq i (strlen x))

(while (= (substr x i) "0")

(setq i (1- i)

x (substr x 1 i)))

(if (= (substr x i) ".")

(substr x 1 (1- i))

x)

)

(prompt "\nExport Linetypes by Tee Square Graphics, ")

(princ "\nType NEW-LIN to run")

(princ)

;END ROUTINE ----------------------------------------------------------------------

Advertisement

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, Customization, TIPS. Bookmark the permalink.

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 )

Facebook photo

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

Connecting to %s