Author Topic: Load all linetypes in runtime  (Read 2280 times)

0 Members and 1 Guest are viewing this topic.

Nima2018

  • Newt
  • Posts: 30
Load all linetypes in runtime
« on: April 19, 2018, 11:43:52 PM »
Hello dear friends

I'm not professional in Autolisp programming and I am a beginner and  now I want to upload all the linetypes simultaneously in runtime .
Is it possible to use a syntax similar to this?

Code: [Select]
(command "linetype" "load" "all" "acadiso.lin" "")

ASMI has proposed this method in the Cadtutor -> http://www.cadtutor.net/forum/showthread.php?29834-LISP-to-automatically-load-groups-of-linetypes.:
 
Code: [Select]
(defun c:llt()
  (foreach lt '("Center" "Center2" "Centerx2" "Hidden" "Hidden2" "Hiddenx2")
    (if(not(tblsearch "ltype"lt))
      (command "_.-linetype" "_l" lt "acadiso.lin" "")
      ); end if
    ); end foreach
  (princ)
  ); end of c:llt
 

But ,I think listing all the linrtypes in a list is terrible !
If any of the honorable members has done this before, please give advice .

lamarn

  • Swamp Rat
  • Posts: 636
Re: Load all linetypes in runtime
« Reply #1 on: April 20, 2018, 04:15:28 AM »
One simple and very effective way is to use Lee Mac steal command

 (Steal "your_dwg.dwg" '(("Linetypes" ("*DOT")))) ; * for or ALL, etc.

http://www.lee-mac.com/steal.html
Design is something you should do with both hands. My 2d hand , my 3d hand ..

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Load all linetypes in runtime
« Reply #2 on: April 20, 2018, 05:06:56 AM »
Tried (command "-linetype" "load" "*" "acad.lin")problem is how you handle the already exists, the simple way may be to look at the .lin file itself the line type name is always *linetypename so you can do a simple read the .lin file check for linetype exists and if not load it.

Code: [Select]
*BORDER,Border __ __ . __ __ . __ __ . __ __ . __ __ .
A, 12.7, -6.35, 12.7, -6.35, 0, -6.35
*BORDER2,Border (.5x) __.__.__.__.__.__.__.__.__.__.__.
A, 6.35, -3.175, 6.35, -3.175, 0, -3.175
*BORDERX2,Border (2x) ____  ____  .  ____  ____  .  ___
A, 25.4, -12.7, 25.4, -12.7, 0, -12.7

look at asmi code need to change a bit, need a day or 2 to do.
Code: [Select]
(defun c:llt()
; make the list "linetypes" of the linetype name by reading them from the linetype file.

  (foreach lt linetypes
    (if(not(tblsearch "ltype"lt))
      (command "_.-linetype" "_l" lt "acadiso.lin" "")
      ); end if
    ); end foreach
  (princ)
  ); end of c:llt
« Last Edit: April 20, 2018, 05:14:01 AM by BIGAL »
A man who never made a mistake never made anything

MatGrebe

  • Mosquito
  • Posts: 16
Re: Load all linetypes in runtime
« Reply #3 on: April 20, 2018, 05:32:39 AM »
I use this, which handles already defined linetypes as well:

(defun c:ltl ( / cmd_mem x)
   (command "_-linetype" "_l" "*" "ISK.lin")
   (setq cmd_mem (getvar "cmdactive"))
   (setq x -1)
   (while (and (= (getvar "cmdactive") cmd_mem) (< x 150))  (progn
      (command "")
      (setq x (+ 1 x))
   ))
   (princ "\n") (princ x) (princ " Linientypen neu geladen")
   (princ)
)

Mathias

Crank

  • Water Moccasin
  • Posts: 1503
Re: Load all linetypes in runtime
« Reply #4 on: April 21, 2018, 08:55:41 AM »
If you don't care about reloaded linetypes, you can use:
Code: [Select]
(defun c:ll (/ EXP)
(setq EXP (getvar "EXPERT"))
(setvar "EXPERT" 3)
(command-s "-linetype" "l" "Center*,Hidden*" "acadiso.lin" "")
(setvar "EXPERT" EXP)
(princ)
)
Replace "Center*,Hidden*" with "*" for all linetypes.
Vault Professional 2023     +     AEC Collection

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Load all linetypes in runtime
« Reply #5 on: May 02, 2018, 05:11:01 AM »
Using Crank method maybe

Code: [Select]
(command-s "-linetype" "l" "A*,B*,C*,D* and so on" "acadiso.lin" "")
A man who never made a mistake never made anything

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Load all linetypes in runtime
« Reply #6 on: May 02, 2018, 02:32:28 PM »
I've always approached these types of problems with the mindset that it's better to not recreate what's already loaded into the drawing (I had routines to overwrite too but those were few in numbers). I cannibalized a routine I had posted here and came up with the following.

This code should be quick--given it's mostly just plain autolisp logic and loops--so you can remove the command call and load it up at startup -i.e. users may not even notice it runs.

Code - Auto/Visual Lisp: [Select]
  1. (defun build-name-list ( lst )
  2.   ;; given a list of raw dic entries this proced
  3.   ;; will report entity names
  4.          (if (null lst)
  5.            nil
  6.            (cons (cdr (assoc 2 (car lst)))
  7.                 (build-name-list (cdr lst)))) )
  8.  
  9. (defun strParse (aStr delim / strList pos)
  10.   (while
  11.     (setq pos (vl-string-search delim aStr 0))
  12.     ;; Find the postition where the delimiter first shows up.
  13.     (setq strList (cons (substr aStr 1 POS) strList)
  14.     ;; create a list of the fist substring (up untill the delimiter)
  15.           strList (cons (substr aStr (1+ POS) 1) strList)
  16.           aStr (substr aStr (+ pos 2)))
  17.     ;; Skip over the delimiter and grab the rest of the string,
  18.     ;; Set that as the new string
  19.     )
  20.   (reverse (cons aStr strList))
  21.  )
  22.  
  23. (defun process-on-drawing ( process )
  24.   ;; a simple `hook' to run a process
  25. ;;       (if (= (getvar 'DWGTITLED) 1)
  26.         (eval process)
  27. ;;         "Drawing not saved"
  28. ;;          )
  29.         )
  30.  
  31. (defun get-list-from-file ( name / fp lst read-file-into-list )
  32.   ;; general file reader
  33.   ;; given a file name this procedure will read the contents
  34.   ;; into a list
  35.          (defun read-file-into-list ( str file )
  36.            (if str
  37.              (cons
  38.                (if (not
  39.                      (or
  40.                       (= (substr str 1 1) ";")
  41.                       (= (substr str 1 1) " ")))
  42.                  str)
  43.                (read-file-into-list (read-line file) file))))
  44.   (setq fp (open name "R"))
  45.   (setq lst (read-file-into-list (read-line fp) fp))
  46.   (close fp)
  47.  lst
  48. )
  49.  
  50. (defun files-p ( path pattern )
  51.   ;; files-p
  52.   ;;
  53.   ;; Returns a list of all the files in a given path
  54.   ;; with a given search pattern. If a nill pattern
  55.   ;; to search for is not given, defaults to ``*.*''.
  56.   ;;
  57.   ;; Ex:
  58.   ;; (files-p "C:\\" nil)
  59.   ;;
  60.   ;; => returns all files in directory specified.
  61.   ;;
  62.   ;; By: John (7) K
  63.   ;;
  64.   (
  65.    (lambda ( a e )
  66.      (if (null a)
  67.        nil
  68.        (cond
  69.          ((null e)
  70.           (vl-directory-files a "*.*" 1))
  71.          (T(vl-directory-files a e 1)))) )
  72.    path ; a
  73.    pattern ; e
  74.    ) )
  75.  
  76. (defun get-drawing-dictionary-list ( what / x lst)
  77.   ;; retrieve a list of drawing dictionary entries
  78.        (while (setq x (tblnext what (not x)))
  79.           (setq lst (cons x lst))) )
  80.  
  81. (defun remove-uncomon-names ( ls )
  82.   ;; return the items that are not in drawing lt list
  83.   (mapcar
  84.     '(lambda ( x )
  85.        (if
  86.          (not
  87.            (or
  88.              (= x "")
  89.              (null x)
  90.              (member x dwg-ltype-name-list)))
  91.          x))
  92.     ls) )
  93.  
  94. (defun C:LoadLTs ( / dwg-ltype-name-list
  95.                      ltype-file-locations
  96.                      ltype-locations
  97.                      todo-list)
  98.     (setq
  99.          dwg-ltype-name-list
  100.                     (build-name-list
  101.                       (process-on-drawing '(get-drawing-dictionary-list "LTYPE")))
  102.          ;; build a list of litetype names loaded in dwg
  103.  
  104.          ltype-file-locations
  105.                       (apply
  106.                         ;; itterate thru the entire search path to look for .lin files
  107.                         'append
  108.                         (mapcar
  109.                           '(lambda ( x / tmp-str)
  110.                              (setq tmp-str (files-p x "*.lin"))
  111.                              (if (and tmp-str (not (eq ";" x)))
  112.                                (list
  113.                                  (strcat
  114.                                    x
  115.                                    "\\"
  116.                                    (car tmp-str)))))
  117.                           (strparse (getvar "ACADPREFIX") ";") ))
  118.          ltype-locations
  119.           ;; a list of lists for the linetypes and their locations
  120.           ;; ( <path>+<file> ( <ltype> <ltype> ... ))
  121.                       (mapcar
  122.                        '(lambda ( x / f lt-list)
  123.                           (setq
  124.                             lt-list
  125.                              (mapcar
  126.                                 '(lambda ( x )
  127.                                    (if x (substr (car (strparse x ",")) 2)))
  128.                                    (get-list-from-file x)
  129.                                    )
  130.                              )
  131.                           (cons x (list lt-list))
  132.                           )
  133.                        ltype-file-locations
  134.                        )
  135.          todo-list (cons
  136.                      (caar ltype-locations)
  137.                      (list (remove-uncomon-names (car (cdr (car ltype-locations)))))
  138.                      )
  139.           ;; Clean the list of lists for the linetypes and their locations by removing duplicates
  140.           ;; already loaded in drawing.
  141.           ;; ( <path>+<file> ( <ltype> <ltype> ... ))
  142.       )
  143.  
  144.       (mapcar
  145.         '(lambda ( x )
  146.            (if x (command-s "_.linetype" "_load" x (car todo-list) ""))
  147.            )
  148.         (car (cdr todo-list))
  149.        )
  150.  (princ)
  151.  )
  152.  
  153. (C:LoadLTs)
  154.  
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Load all linetypes in runtime
« Reply #7 on: May 02, 2018, 06:12:50 PM »
For what it's worth...

Code - Auto/Visual Lisp: [Select]
  1.  ;;----------------------------------
  2.   (setq lineTypeFile
  3.          (if
  4.            (= 1
  5.               (kdub:lisp-value (vla-getvariable *:activedoc "Measurement")
  6.               )
  7.            )
  8.             (findfile "acadiso.lin")
  9.             (findfile "acad.lin")
  10.          )
  11.   )
  12.   ;;----------------------------------
Code - Auto/Visual Lisp: [Select]
  1. ;;;------------------------------------------------------------------
  2. ;;;------------------------------------------------------------------
  3. ;;;
  4. ;;; lisp-value : Author : Vladimir Nesterovsky 2002
  5. (defun kdub:lisp-value (val)
  6.   (cond
  7.     ((= (type val) 'variant) (kdub:lisp-value (variant-value val)))
  8.     ((= (type val) 'safearray) (mapcar 'kdub:lisp-value (safearray-value val)))
  9.     (t val)
  10.   )
  11. )
  12. ;;;------------------------------------------------------------------
  13. ;;;------------------------------------------------------------------
  14. ;;;
  15.  
  16.  
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.