马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
How to load a .MLN file using LISPBy Augusto Goncalves
There isn't a ready-to-use API function that loads a .MLN file in Lisp, VBA and ARX. Normally you can do this only by using the MLSTYLE dialog.
Of course, it's possible to create the dictionary entry of a multiline style definition programmatically with either API. The following code shows how to read the .MLN file in Lisp and how to create the MLINESTYLE objects defined in it.- (defun c:LoadMlStyles (/ mlFileName)
- (setq mlFileName (getstring "\nEnter MLN file name: "))
- (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
- )
You can load a .MLN file from the AutoCAD command line by using the LOADMLSTYLES command. This command asks for the MLN file name. If you want to call this function from Lisp, you can use the (LOADMLN) function. There you can specify the MLN file name.
Once you've loaded a .MLN file, you can set the AutoCAD variable CMLSTYLE to one of the loaded styles, so the next created MLINE will use the style.
|