;;; Based on http://adndevblog.typepad.com/autocad/2012/12/how-to-load-a-mln-file-using-lisp.html
;;; Modified by Igal Averbuh 2015 (added dialog option for selecting MLN file and selecting Mline Style for drawing)

(defun c:MLN (/ mlFileName)
; (setq mlFileName (getstring "\nEnter MLN file name: "))
(setq mlFileName (getfiled "Select MLN file to Load" (getvar 'dwgprefix) "mln" 0))
(if (/= nil mlFileName)
(LoadMln mlFileName)
)
(princ)
)

(defun LoadMln (mlnFile / f mlineDict same newStyle xName)
(setq mlnFile (findfile mlnFile))
(setq f (open mlnFile "r"))
;;(setq f (open mlnFile "r"))
(if (= NIL f)
(princ "\nInvalid MLN file.\n")
(progn
;; Get the MLINESTLYE dictionary.
(setq mlineDict (dictsearch
(namedobjdict) "ACAD_MLINESTYLE"))
;; Create the beginning of an MLINESTYLE object.
(setq same (list (cons 0 "MLINESTYLE")
;;(cons 102 "{ACAD_REACTORS")
;;(cons 330 (cdr (assoc -1 mlineDict)))
;;(cons 102 "}")
;;(cons 330 (cdr (assoc -1 mlineDict)))
(cons 100 "AcDbMlineStyle")
)
)
;;
;; Read the data of the MLINESTYLE
;;
(while (/= nil (setq mlStyle (ReadObject f)))
;; Create the complete MLINESTYLE object.
(setq newStyle (append same mlStyle)
xName (entmakex newStyle)
)
;; Append it to the MLINESTYLE dictionary.
(dictadd (cdr (assoc -1 mlineDict))
(cdr (assoc 2 newStyle))
xName
)
)
)
)
(close f)
(princ)
)

(defun ReadObject (f / ObjectList firstLine code value)
(setq ObjectList nil)
;; Skip the 'MLSTYLE'.
(setq firstLine (read-line f))
(if (/= nil firstLine)
(progn
(while (/= 0 (setq code (atoi (read-line f))))
(setq value (vl-string-trim " " (read-line f)))
(if (or (= code 2)
(= code 3)
(= code 6)
)
(setq ObjectList (append ObjectList
(list (cons code value))))
)
(if (or (= code 70)
(= code 62)
(= code 71)
)
(setq ObjectList (append ObjectList
(list (cons code (atoi value)))))
)
(if (or (= code 51)
(= code 52)
)
;; Code 51 and 52 must be converted into degrees.
(setq ObjectList
(append ObjectList
(list (cons code
(angtof value 0)))))
)
(if (= code 49)
(setq ObjectList
(append ObjectList
(list (cons code (atof value)))))
)
)
)
)
ObjectList
)

(c:mln)
(command "_mlstyle")

Advertisements