lsp to load or reload all linetypes from .lin file

lsp to load or reload all linetypes from .lin file

demus72
Collaborator Collaborator
3,086 Views
8 Replies
Message 1 of 9

lsp to load or reload all linetypes from .lin file

demus72
Collaborator
Collaborator

I've done some research but haven't found quite what I'm looking for.

 

The company I work for stores all their linetypes in a custom .lin file. This collection of linetypes is relatively complete but on occasion, we may modify an existing linetype or add a new one. I'm looking for a lisp routine that will load or reload all linetypes from a .lin file. 

 

Thanks

0 Likes
Accepted solutions (2)
3,087 Views
8 Replies
Replies (8)
Message 2 of 9

ronjonp
Advisor
Advisor
Accepted solution

Try this:

 

(defun _loadlt (/ ex v va)
  (setq va (mapcar 'getvar (setq v '(cmdecho expert))))
  (mapcar 'setvar v '(0 5))
  (foreach lt (if (= 0 (getvar 'measurement)) ; <-Imperial
		;; Add your custom files to the list, if not in search path provide the full path
		'("acad.lin")
		;; Metric
		'("acadiso.lin")
	      )
    (and (findfile lt) (command "._-linetype" "_Load" "*" lt ""))
  )
  (mapcar 'setvar v va)
  (princ)
)
(_loadlt)

 

Message 3 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

Try this [untested]:

(defun C:LAL (); = Load All Linetypes
  (command "_.linetype" "_load" "*" "YourLinetypeFileName.lin"); leaves in command
  (while (> (getvar 'cmdactive) 0) (command "")); Enters until finished
); 

The "Enters until finished" would accept the Yes default for reloading any linetype(s) already in the drawing, and the end-the-command final Enter when there are no more of those.

 

Edit the "YourLinetypeFileName" part to suit.  A file path can be included, if you don't have it in a folder that's in your Support File Search Path list.

Kent Cooper, AIA
Message 4 of 9

demus72
Collaborator
Collaborator

Thank you both for your replies and your willingness to offer your lisp coding expertise. Very cool! Both lsp files performed exactly what I was looking for.

 

Thanks again and have a great day!

0 Likes
Message 5 of 9

Sea-Haven
Mentor
Mentor

Another loads individual line types

 

(defun loadLinetype (doc LineTypeName FileName)
  (if (and
        (not (existLinetype doc LineTypeName))
        (vl-catch-all-error-p
          (vl-catch-all-apply
            'vla-load
            (list
              (vla-get-Linetypes doc)
              LineTypeName
              FileName
            )
          )
        )
      )
    nil
    T
  )
)

(defun existLinetype (doc LineTypeName / item loaded)
  (vlax-for item (vla-get-linetypes doc)
    (if (= (strcase (vla-get-name item)) (strcase LineTypeName))
      (setq loaded T)
    )
  )
)

;load missing linetypes
;;; returns: T if loaded else nil
(loadLinetype doc "Fence" "custom.lin")
(loadLinetype doc "Tree" "custom.lin")
(loadLinetype doc "Water_main" "custom.lin")
(loadLinetype doc "Gas_main"  "custom.lin")
0 Likes
Message 6 of 9

R_Tweed
Advisor
Advisor

Is it possible to add multiple .lin files to your routine? 

0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant

@R_Tweed wrote:

Is it possible to add multiple .lin files to your routine? 


Yes.  You could just repeat lines 2 & 3 with a different file name in each copy of line 2.  Or if you have the file names in some kind of format [an AutoLisp list? a spreadsheet file?  a plain text file?], presumably it could be made to step through that information and apply the file names within line 2 without having to spell that out separately for each one.

Kent Cooper, AIA
Message 8 of 9

R_Tweed
Advisor
Advisor

(defun C:LAL (); = Load All Linetypes
(command "_.linetype" "_load" "*" "Av-Site.lin"); leaves in command
(command "_load" "*" "Av-Streets.lin"); leaves in command
(command "_load" "*" "Av-Utilities.lin"); leaves in command
(while (> (getvar 'cmdactive) 0) (command "")); Enters until finished
);

 

Thanks! The above works nicely.

 

0 Likes
Message 9 of 9

Sea-Haven
Mentor
Mentor

Make sure save inside a DWT then no need to do again till next addition.

0 Likes