You are here:

AutoCAD/LISP Routine for loading linetypes

Advertisement


Question
QUESTION: 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?


Answer
The 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

AutoCAD

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bill DeShawn

Expertise

I can address all 2-D questions and some 3-D questions. I do programming in AutoLISP if it doesn`t involve solid modeling. I can also address menu customization issues and can help you find answers to questions I can`t answer by taking your question directly to Autodesk via their newsgroups.

Experience

I used to do electronic and mechanical design for a flat panel monitor manufacturer, and now I do architectural drafting for an architect. I did and do AutoLISP and menu customization and take pride in making my lisp routines to do the work exactly the way the client likes them done.

Publications
I had a routine published in CADENCE magazine (no longer in publication and taken over by CADALYST). Some of my routines are published on my website at http://my.sterling.net/~bdeshawn

©2012 About.com, a part of The New York Times Company. All rights reserved.