TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: drumbald on December 29, 2005, 01:34:55 PM

Title: Loading a custom linetype with lsp
Post by: drumbald on December 29, 2005, 01:34:55 PM





I have a linetype Ln.lin its in C:\l-type\

I want to load it with the following lisp file

Right now it will only load from the acad.lsp file

(defun C:LTLD ()
    (setvar "CMDECHO" 0)
    (foreach X '("hidden" "dashed" "batting" "center" "border" "dot"
"tracks" "phantom")
        (LTLOAD X)
    )
    (setvar "CMDECHO" 1)
    (princ)
)

(defun LTLOAD ( ltname )
    (if (not (tblsearch "ltype" ltname))
        (vl-cmdf "-linetype" "l" ltname "" "")
    )
  (setvar "CMDECHO" 1)
  (princ)
)
Title: Re: Loading a custom linetype with lsp
Post by: Jeff_M on December 29, 2005, 02:18:04 PM
Try something like this that specifies the file to load from:
Code: [Select]
(defun C:LTLD ()
    (setvar "CMDECHO" 0)
  ;;adjust path/filename as needed
    (foreach X '(("hidden" . "acad.lin") ("dashed" . "acad.lin") ("batting" . "acad.lin")
("center" . "acad.lin") ("border" . "acad.lin") ("dot" . "acad.lin")
("tracks" . "C:\\l-type\\Ln.lin") ("phantom" . "C:\\l-type\\Ln.lin"))
        (LTLOAD X)
    )
    (setvar "CMDECHO" 1)
    (princ)
)

(defun LTLOAD ( ltname )
    (if (not (tblsearch "ltype" (car ltname)))
        (vl-cmdf "-linetype" "l" (car ltname) (cdr ltname) "")
    )
)
Title: Re: Loading a custom linetype with lsp
Post by: CAB on December 29, 2005, 04:30:40 PM
Jeff
I like that method. Here is taking it one step further.
Code: [Select]
(defun c:ltld (/ lt_data ltypes fname ltname usercmd)
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (vl-load-com)
  (setq ltypes (vla-get-linetypes
                 (vla-get-activedocument
                   (vlax-get-acad-object)
                 )
               )
  )
  ;; load the linetypes
  (foreach lt_data '(("hidden" . "acad.lin")
                     ("dashed" . "acad.lin")
                     ("batting" . "acad.lin")
                     ("center" . "acad.lin")
                     ("border" . "acad.lin")
                     ("dot" . "acad.lin")
                     ("tracks" . "C:\\l-type\\Ln.lin")
                     ("phantom" . "C:\\l-type\\Ln.lin")
                     ("xyz" . "cab.lin")
                    )
    (setq ltname (car lt_data)
          fname  (cdr lt_data)
    )
    (cond
      ((tblsearch "ltype" ltname)
       (prompt (strcat "\nLinetype " ltname " already loaded."))
      )
      ((not (findfile fname))
       (prompt (strcat "\nCan not find file " fname))
      )
      (t
       (setq err (vl-catch-all-apply 'vla-load (list ltypes ltname fname)))
       (cond
         ((vl-catch-all-error-p err)
          (prompt (strcat "\n" (vl-catch-all-error-message err) " " ltname " from file " fname))
         )
         ((vla-item ltypes ltname)
          (prompt (strcat "\nLinetype " ltname " loaded from file " fname "."))
         )
         (t
          (prompt (strcat "\nError Linetype " ltname " not loaded, file " fname "."))
         )
       )
      )
    )
  )
  (setvar "CMDECHO" usercmd)
  (princ)
)
Title: Re: Loading a custom linetype with lsp
Post by: Jeff_M on December 29, 2005, 05:52:47 PM
Thanks Alan. I was going to do something similar to what you did but didn't have time. I would like to know why you would need to fine a file though......possibly for misbehaving?
Quote
(prompt (strcat "\nCan not fine file " fname))
:-)
Title: Re: Loading a custom linetype with lsp
Post by: CAB on December 29, 2005, 06:05:13 PM
spelling error, again :-o
I think its a typo, e key next to d key and no proof reader. :-)
Thanks for the catch.
Title: Re: Loading a custom linetype with lsp
Post by: Kerry on December 29, 2005, 08:51:41 PM
Just came across this quote, and thought of you .. well me too actually ..
Quote
My spelling is wobbly. It's good spelling but it wobbles and the letters get in the wrong places.
...  Winnie the Pooh 
Title: Re: Loading a custom linetype with lsp
Post by: CAB on December 29, 2005, 10:38:34 PM
 :-) :-) :-)
Title: Re: Loading a custom linetype with lsp
Post by: GDF on December 30, 2005, 09:35:03 AM
Here is my feable approach. I first did it to play around with dcl, really don't use it that much.
Sorry I went down that dark path and the LNU dialog based routine is not a standalone version.

Gary