(vl-load-com)
(defun Insertblk-xx (blkname pt x y z r / blkfile objnew) ;_blkname:块名-字符串；pt：点坐标
  ;注意，这个函数和其他同名 函数有区别，这个 函数没有范围检测
  (if (and (listp pt)
	   (= 'STR (type blkname))
	   (apply 'and
		  (mapcar '(lambda (e)
			     (numberp e)
			   )
			  (append pt (list x y z r))
		  )
	   )
      )
    (progn
      (vl-load-com)      
      (IF(NOT(setq blkfile (ZX:getpath-XX
			     (strcat blkname ".dwg"))));这里的查找函数不需要msg
      (setq blkfile (findfile (strcat blkname ".dwg"))))      
      (if blkfile
	(PROGN	  
	  (IF(AND blkfile X Y Z R)	    
	(setq objnew
	       (vla-InsertBlock
		 (vlax-get-property (vla-get-activedocument (vlax-get-acad-object)) (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace))
		 (vlax-3d-point pt)
		 (FINDFILE blkfile)
		 x
		 y
		 z
		 r
	       )
	)(ALERT "变量缺少值"))
	)
 ;	(princ (strcat "没有找到\"" blkname "\"模块"))
	(progn	  
	  (alert
	    (strcat
	      "没有找到\""
	      blkname
	      "\"模块\n\n请确认你的文件都在cad可以找到的路径下:"
	      "“"
	      (strcat (getvar "mydocumentsprefix")
		      "\\中线CAD用户配置"
	      )
	      "”"
	      "\n\n                                        或者是可以正确请求的服务器"
	      "  里面"

	    )
	  )
	  (exit)
	)
      )
    )
  )
  (if objnew
    (vlax-vla-object->ename objnew)
    nil
  )
)
(defun ZX:mlnfile->data	(filename / zc data f)
					;ZX:mlnfile->data 多线样式文件转数据表
  (if filename
    (progn
      (setq f (open filename "r"))
      (while (and (setq zc (read-line f))
		  (/= "0")
		  (setq zc (strcase (VL-STRING-TRIM " " zc)))
	     )
	(cond
	  ((= "MLSTYLE" zc)
	   (setq data (cons (cons 100 "AcDbMlineStyle")
			    (cons (cons 0 "MLINESTYLE") data)
					;这里必须加上这个祖玛，否则会创建失败
		      )
	   )
	  )
	  ((= "2" zc)
	   (setq
	     data (cons
		    (cons 2
			  (strcase (VL-STRING-TRIM " " (read-line f)))
		    )
		    data
		  )
	   )
	  )
	  ((= "70" zc)
	   (setq data
		  (cons
		    (cons 70 (read (VL-STRING-TRIM " " (read-line f))))
		    data
		  )
	   )
	  )
	  ((= "3" zc)
	   (setq
	     data (cons
		    (cons 3
			  (strcase (VL-STRING-TRIM " " (read-line f)))
		    )
		    data
		  )
	   )
	  )
	  ((= "62" zc)
	   (setq data
		  (cons
		    (cons 62 (read (VL-STRING-TRIM " " (read-line f))))
		    data
		  )
	   )
	  )
	  ((= "51" zc)
	   (setq data
		  (cons
		    (cons 51
			  (* pi
			     (/	(read (VL-STRING-TRIM " " (read-line f)))
				180.
			     )
			  )
		    )
		    data
		  )
	   )
	  )
	  ((= "52" zc)
	   (setq data
		  (cons
		    (cons 52
			  (* pi
			     (/	(read (VL-STRING-TRIM " " (read-line f)))
				180.
			     )
			  )
		    )
		    data
		  )
	   )
	  )
	  ((= "71" zc)
	   (setq data
		  (cons
		    (cons 71 (read (VL-STRING-TRIM " " (read-line f))))
		    data
		  )
	   )
	  )
	  ((= "49" zc)
	   (setq data
		  (cons
		    (cons 49 (read (VL-STRING-TRIM " " (read-line f))))
		    data
		  )
	   )
	  )
	  ((= "6" zc)
	   (setq
	     data (cons
		    (cons 6
			  (strcase (VL-STRING-TRIM " " (read-line f)))
		    )
		    data
		  )
	   )
	  )
	)
      )
      (close f)
    )
    (print "ZX:mlnfile->data  遇到空值")
  )
  (if data
    (reverse data)
    nil
  )
)




(defun ZX:addmlstyle (data / mldata flag newen dxx name)
					;多线样式添加到图形函数
  (if data
    (progn
      (setq mldata
	     (entget
	       (cdr
		 (assoc -1 (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))
	       )
	     )
      )
      (setq name (cdr (assoc 2 data)))
      (foreach a mldata
	(if (= 3 (car a))
	  (if (= (strcase name) (strcase (cdr a)))
	    (setq flag t)
	  )
	)
      )
      (if (not flag)
	(progn
	  (and (setq
		 dxx (vl-remove
		       nil
		       (mapcar
			 '(lambda (a)
			    (if	(= (car a) 6)
			      (strcase (cdr a))
			    )
			  )
			 (vl-remove-if
			   '(lambda (b)
			      (member (cdr b) (list "BYLAYER" "BYBLOCK"))
			    )
			   data
			 )
		       )
		     )
	       )			;读取出多线里面的单线型
	       (mapcar 'ZX:jzxx dxx)
	  )
	  (setq newen (entmakex data))
	  (if newen
	    (entmod
	      (append mldata (list (cons 3 name) (cons 350 Newen)))
	    )
	  )
	)
	(alert "样式已经存在")
      )
    )
    (print "ZX:addmlstyle  遇到空值")
  )
)


 ;|
					;用法示例及解释，多线样式表：
(setq data0 '((0 . "MLINESTYLE")
	     (100 . "AcDbMlineStyle")
	     (2 . "bianzhi") ;_ 多线样式名
	     (70 . 96)

	 ;     70 标志（按位编码）：
         ;     1 =填充
         ;     2 = 显示斜接
         ;     16 = 开始矩形结束（直线）封口
         ;     32 = 开始内弧封口
         ;     64 = 开始圆（外弧）封口
         ;     256 = 结束矩形（直线）封口
         ;     512 = 结束内弧封口
         ;     1024 = 结束圆（外弧）封口

	     (3 . "") ;_ 样式说明（字符串，最多为 255 个字符）
	     (62 . 0) ;_ 填充颜色（整数，默认值 = 256）
	     (51 . 1.5708) ;_ 起点角度（实数，默认值为 90 度）
	     (52 . 1.5708) ;_端点角度（实数，默认值为 90 度
	     (71 . 2)
	     　　　　　　　　　　 ;_ 元素数
	     (49 . 0.5) ;_ 元素偏移（实数，无默认值）。可以存在多个条目；每个元素一个条目
	     (62 . 256) ;_ 元素颜色（整数，默认值 = 0）。可以存在多个条目；每个元素一个条目
	     (6 . "pvc") ;_ 元素线型（字符串，默认值 = 随层）。可以存在多个条目；每个元素一个条目
	     (49 . -0.5) ;_ 元素偏移（实数，无默认值）。可以存在多个条目；每个元素一个条目
	     (62 . 256) ;_ 元素颜色（整数，默认值 = 0）。可以存在多个条目；每个元素一个条目
	     (6 . "pvc") ;_ 元素线型（字符串，默认值 = 随层）。可以存在多个条目；每个元素一个条目
	    )
)
|;



(defun ZX:Mlinestyle-Get (Name / mlsty-DICT MLSty)
					;查找当前图纸中指定的多线
  (if name
    (if	(setq mlsty-DICT (dictsearch (Namedobjdict) "ACAD_MLINESTYLE"))
      (while
	(and mlsty-DICT
	     (not (setq	MLSty
			 (if (and (assoc 3 mlsty-DICT)
				  (= (strcase (cdr (assoc 3 mlsty-DICT)))
				     (strcase Name)
				  )
			     )
			   (list
			     (strcase Name)
			     (cdr
			       (cadr (member (assoc 3 mlsty-DICT) mlsty-DICT))
			     )
			   )
			 )
		  )
	     )
	)
	 (setq mlsty-DICT (cdr (member (assoc 3 mlsty-DICT) mlsty-DICT)))
      )
    )
    (print "ZX:Mlinestyle-Get  遇到空值")
  )
  MLSty
)
(defun ZX:getpath-XX (wj / LinPath)
					;查找文件
  (if wj
    (or	(and zx-czwj
	     (setq LinPath (zx-czwj
			     wj
			     ""
			   )
	     )
	)				;调用中线CAD通用查找函数zx-czwj
	(and chazhaowenjian
	     (setq LinPath (chazhaowenjian
			     wj
			     ""
			   )
	     )
	)				;调用中线CAD通用查找函数chazhaowenjian
					;以下为保险起见而添加的查找方式
	(setq
	  LinPath (findfile
		    (strcat (getvar "mydocumentsprefix")
			    "\\"
			    "中线CAD用户配置"
			    "\\"
			    wj
		    )
		  )
	)				;强制用户配置文件查找
	(setq LinPath (findfile
			(strcat	(getenv "systemdrive")
				"\\"
				"Changli_harness_software"
				"\\"
				wj
			)
		      )
	)				;强制中线CAD运行目录查找
	(setq LinPath (findfile wj)	;cad的所有环境，包括用户的电脑桌面查找
	)
    )
    (print "ZX:getpath-XX  遇到空值")
  )
  LinPath
)
(defun ZX:jzxx (xxm / LinPath)
					;这里的线型是加载单线型  
  (if xxm
    (if	(tblobjname "LTYPE" xxm)
      (tblobjname "LTYPE" xxm)
      (progn
	(setq linpath (ZX:getpath-XX "zx.lin"))
					;加载由中线官方提供的线型定义
	(if
	  (not
	    (vl-catch-all-error-p
	      (vl-catch-all-apply
		'vla-load
		(list (vla-get-Linetypes
			(vla-get-ActiveDocument (vlax-get-acad-object))
		      )
		      xxm
		      (findfile LinPath)
		)
	      )
	    )
	  )
	   (tblobjname "LTYPE" xxm)
	)
	(IF (NOT (tblobjname "LTYPE" xxm))
	  (PROGN
	    (setq linpath (FINDFILE "ACAD.lin"))
					;最后在cad自己的线型定义文件里面查找
	    (if
	      (not
		(vl-catch-all-error-p
		  (vl-catch-all-apply
		    'vla-load
		    (list
		      (vla-get-Linetypes
			(vla-get-ActiveDocument (vlax-get-acad-object))
		      )
		      xxm
		      (findfile LinPath)
		    )
		  )
		)
	      )
	       (tblobjname "LTYPE" xxm)
	    )
	  )
	)
	(IF (NOT (tblobjname "LTYPE" xxm)) ;依然不成功就提示用户
	  (ALERT
	    (STRCAT
	      "加载线型 " xxm
	      " 失败！\n\n请优先检查 “中线CAD用户配置” 这个文件里面中 zx.lin 里面是否有： "
	      xxm "线型定义\n\n\n\n官方协助电话：400-800-2007")
	  )
	)
      )
    )
    (print "ZX:jzxx  遇到空值")
  )
)




(defun ZX:jzdxys (ysm / mlnpath data jzzt)
					;加载指定的多线样式
					;调用本函数的地方最好在调用前备份以下变量cmlstyle的值，调用完毕后恢复此变量
  (if ysm
    (progn
      (if (and (vl-filename-extension ysm)
	       (= (strcase (vl-filename-extension ysm)) ".MLN")
	  )
	(setq ysm (vl-filename-base ysm))
      )					;如果传入参数里面有后缀，这里修正一下
      (if (not (ZX:Mlinestyle-Get ysm))
					;假如当前图纸不存在ysm
	(progn
	  (if
	    (setq mlnpath (ZX:getpath-XX (strcat ysm ".MLN")))
	     (progn
	       (setq data (ZX:mlnfile->data mlnpath))
					;将读取到的mln转换为点表
	       (AND data (setq jzzt (ZX:addmlstyle data)))
					;加载多线并返回加载状态
	       (and jzzt (setvar "cmlstyle" ysm)) ;置为最前端
	     )
	     (alert
	       (strcat
		 "加载多线样式  "
		 ysm
		 "  失败!\n\n请优先检查  “中线CAD用户配置” 文件夹中是否有： "
		 ysm
		 ".mln  这个文件\n\n\n\n官方协助电话：400-800-2007"
		)
	     )
	  )
	)
	(setvar "cmlstyle" ysm)		;如果存在就直接置为最前端
      )
    )
    (print "ZX:jzdxys  遇到空值")
  )
  (if jzzt
    t
    nil
  )
)
(defun bljz ()
  (if (= (getvar 'CVIEWDETAILSTYLE) "Imperial24") ;假如是英制图纸
    (progn (setvar 'MEASUREMENT 0) (setvar 'cmlscale 1))
    (progn (setvar 'MEASUREMENT 1) (setvar 'cmlscale 20))
  )
  (SETVAR 'LTSCALE 2)			;设定全局比例因子
  (setvar 'CMLJUST 1)			;居中
  (setvar 'CELTSCALE 1)			;设置当前线型比例
  (setvar 'CMLJUST 1)
;;;;;;;;;居中
  (SETVAR "DIMLFAC" 1)			;测量比例
)

;;;(ZX:jzdxys "bjcd")