AutoCAD/LISP Routine for loading linetypes
Expert: Bill DeShawn - 10/20/2008
QuestionQUESTION: I am trying to write a lisp routine for loading linetypes. I can do simple lisp programs but i have ever tried writing something like this. anyway, I am using the command "-linetype" "load" and then putting the names of the linetypes but i am not sure how to tell it where to find the .lin file to load.
or maybe you have an easier way to load linetypes. The reason behind this is because we are using a Terramodel (for surveying)drawing and then converting it to cad and we need an easier way of loading linetypes instead of using format, linetype, load, etc.
Can You help
ANSWER: Here's a routine I wrote for that purpose:
(defun ltlderr (msg)
(if msg (princ msg))
(if fd (setvar "filedia" fd))
(if olderr (setq *error* olderr))
(if cmde (setvar "cmdecho" cmde))
(command "_.undo" "_end")
(princ)
)
(defun c:ltld (/ cmde fd linfil ltname)
(command "_.undo" "_g")
(setq olderr *error* *errro* ltlderr)
(setq cmde (getvar "cmdecho"))
(setvar "cmdecho" 1)
(setq fd (getvar "filedia"))
(setvar "filedia" 0)
(setq ltname (strcase (getstring "\n Linetype Name: ")))
(setq linfil (findfile (strcat ltname ".lin")))
(if linfil
(if (tblsearch "ltype" ltname)
(COMMAND "-LINETYPE" "L" ltname (FINDFILE linfil) "" "")
(COMMAND "-LINETYPE" "L" ltname (FINDFILE linfil) "")
)
(progn
(setvar "filedia" 1)
(initdia)
(COMMAND "-LINETYPE" "L" ltname)
)
)
(while (> (getvar "cmdactive") 0) (command pause))
(setvar "filedia" fd)
(setvar "cmdecho" cmde)
(command "regenall")
(command "_.undo" "_end")
(setq *error* olderr)
(princ)
)
This one was written for linetypes that are found in their very own .LIN file. But if you want, you can have the routine look for your specific .LIN file by changing this line:
(setq linfil (findfile (strcat ltname ".lin")))
to this:
(setq linfil (findfile "myltypes.lin"))
Just remember to substitute "myltypes.lin" with the name of your .LIN file name.
With older Terramodel line types, I found that AutoCAD had trouble loading them. With recent versions, though, I think I had pretty good luck. If you know what the linetype is supposed to look like and you can't load the line type into AutoCAD, you can use MKLTYPE (if EXPRESS TOOLS are loaded) to create new line types.
Keep in touch
Bill DeShawn
http://my.sterling.net/~bdeshawn
---------- FOLLOW-UP ----------
QUESTION: ok. i am doing something wrong. i changed the (setq linfil (findfile (strcat ltname ".lin")))
to this:
(setq linfil (findfile "myltypes.lin")) and entered my .lin file.
when i load it and do the command ltld, it says to enter a linetype name. what am i doing wrong. am i suppose to add each linetype name in the lisp routine as well?
AnswerThe linetype doesn't have to be already loaded in the drawing. But because the .LIN file can define multiple linetypes (like ACAD.LIN), you have to supply the linetype name at the command prompt so AutoCAD will know which linetype information to search for in the .LIN file.
Keep the conversation going until you have success.
Bill DeShawn
http://my.sterling.net/~bdeshawn