目前可以自动绘制断路器、接触器、互感器等。

(defun c:epx(/ data cat direc num dist mDirec point chart)
    (setq data nil)
    (while (not data)
        (setq cat (strcase (getstring (strcat "输入要绘制的元器件" (getDataName (getDataList)) "\n"))))
        (setq data (caddr (assoc cat (getDataList))))
    )
    (setq direc (strcase (getstring "输入进线端方向,左(L),上(T),右(R),下(B)(默认为L)\n")))
    (if (= direc "")
        (setq direc "L")
    )
    (setq num (getint "输入要绘制的数量\n"))
    (setq dist (getint "输入偏移距离\n"))
    (setq mDirec (strcase (getstring "输入偏移方向,左(L),上(T),右(R),下(B)(默认为L)\n")))
    (if (= mDirec "")
        (setq mDirec "L")
    )
    (setq point (getpoint "指定基点\n"))
    (roleDataEx data point direc)
    ;(paint (roleDataEx data point direc))
)


(defun c:ep(/ dataList data cat direc point k)
    (init);初始化全局变量
    (setq dataList (cdr (assoc "dataList" epGb)))
    (setq k (cdr (assoc "scale" epGb)))
    (setq data nil)
    (while (not data)
        (setq cat (strcase (getstring (strcat "输入要绘制的元器件" (getDataName dataList) "\n"))))
        (setq data (caddr (assoc cat dataList)))
    )
    (setq direc (strcase (getstring "输入进线端方向,左(L),上(T),右(R),下(B)(默认为L)\n")))
    (if (= direc "")
        (setq direc "L")
    )
    (setq point (getpoint "指定基点\n"))
    ;(roleDataEx data point direc k)
    (paint (roleDataEx data point direc k))
)

;输入单行文本
(defun c:ept( / point fontHeight val)
    (init)
    (setq val (getstring "输入文本内容\n"))
    (setq point (getpoint "指定基点\n"))
    (setq fontHeight (cdr (assoc "fontHeight" epGb)))
    (write point fontHeight val)
)

;缩放比例变量设置
(defun c:epsc( / k tmp)
    (init)
    (setq tmp (assoc "scale" epGb))
    (setq k 0)
    (while (<= k 0)
        (setq k (getreal (strcat "输入缩放比例(现在为" (rtos (cdr tmp)) ")\n")))
        (setq epGb (hSet "scale" k epGb))
        (if (<= k 0)(princ "比例值必须是大于0的数\n"))
    )
    (princ "修改成功\n")
    (princ)
)



;设置哈希表中的值
(defun hSet(key val hList / tmp result)
    (setq result nil)
    (while (setq tmp(car hList))
        (if (= (car tmp) key)
            (setq tmp (cons key val))
        )
        (setq result (cons tmp result))
        (setq hList (cdr hList))
    )
    (setq result (reverse result))
)


;写入单行文本
(defun write(point fontHeight val)
    (command "text" point fontHeight 0 val)

)


;基础绘制
(defun paint(data / tmp)
    (while (setq tmp (car data))
        (cond
            ((= "line" (car tmp))
                (command "line" (cadr tmp) (caddr tmp) "")
            )
            ((= "circle" (car tmp))
                (command "circle" (cadr tmp) (caddr tmp))
            )
            ((= "arc" (car tmp))
                (command "arc" "c" (cadr tmp) (caddr tmp) (nth 3 tmp))
            )
        )
        (setq data (cdr data))
    )
)


;将子表中点元素绕点point旋转0度、270度、180度或90度,返回旋转后列表
;L,T,R,B分别表示0度、270度、180度、90度,即左上右下
(defun roleDataEx(data point direc k / newData)
    (cond
        ((= direc "L")
            (setq newData (roleData data point "0" k))
        )
        ((= direc "T")
            (setq newData (roleData data point "270" k))
        )
        ((= direc "R")
            (setq newData (roleData data point "180" k))
        )
        ((= direc "B")
            (setq newData (roleData data point "90" k))
        )
    )
)


;将子表中点元素和整数进行缩放,再将点元素转为绝对坐标,并绕点point旋转ang角度,返回旋转后列表
; data实例:(setq data '(("line" (33 30)(33 60)) ("line" (43 50)(34 20))))
(defun roleData(data point ang k / tmp newTmp newData)
    (setq newData nil)
    (while (setq tmp (car data))
        (setq newTmp nil)
        (while (car tmp)
            (cond
                ((= (type (car tmp)) 'STR);如果是字符串
                    (setq newTmp(cons (car tmp) newTmp))
                )
                ((listp (car tmp));如果是列表
                    (setq newTmp(cons (role point (tanslateAbs point (scPoint (car tmp) k)) ang) newTmp))
                )
                ((numberp (car tmp));如果是实数
                    (setq newTmp(cons (* (car tmp) k) newTmp))
                )
            )
            (setq tmp (cdr tmp))
        )
        (setq newData (cons (reverse newTmp) newData))
        (setq data (cdr data))
    )
    (setq newData (reverse newData))
)


;求得点point1绕点point0旋转ang度后的点坐标
(defun role(point0 point1 ang / x0 y0 x1 y1 x2 y2 point2)
    (setq x0 (car point0))
    (setq y0 (cadr point0))
    (setq x1 (car point1))
    (setq y1 (cadr point1))
    (setq ang (angtof ang));角度字符串换算弧度浮点数实数
    (setq x2 (+ (- (* (- x1 x0) (cos ang)) (* (- y1 y0) (sin ang))) x0))
    (setq y2 (+ (+ (* (- y1 y0) (cos ang)) (* (- x1 x0) (sin ang))) y0))
    (setq point2 (list x2 y2))
)

;point0为基点绝对坐标,将point1转为绝对坐标
(defun tanslateAbs(point0 point1 / x0 y0 x1 y1 point2)
    (setq x0 (car point0))
    (setq y0 (cadr point0))
    (setq x1 (car point1))
    (setq y1 (cadr point1))
    (setq point2 (list (+ x0 x1) (+ y0 y1)))

)


;k倍缩放点坐标point
(defun scPoint(point k / x y )
    (setq x (car point))
    (setq y (cadr point))
    (setq point (list (* x k) (* y k)))

)

;返回元器件代号和名称字符串,用逗号分割不同元器件
(defun getDataName(dataList / tmp result)
    (setq result "")
    (while (setq tmp (car dataList))
        (setq result (strcat result "," (cadr tmp) "(" (car tmp) ")"))
    (setq dataList (cdr dataList))
    )
    (setq result result)
)


;初始化全局变量
(defun init(/ dataList)
    (if (not epGb)
        (progn
        (setq dataList (getDataList))
        (setq epGb (list
            (cons "dataList" dataList)
            (cons "scale" 2)
            (cons "fontHeight" 30)
        ))
        (command "style" "ep" "simsun.ttc" 30 1 0 "N" "N");新增或修改样式
        (princ)
        )    
    )
)


(defun getDataList(/ dataList)
    (setq dataList '(
        ("QF" "断路器" (
            ("line" (0 -25) (70 0))
            ("line" (-7.33 7.33) (7.33 -7.33))
            ("line" (-7.33 -7.33) (7.33 7.33))
        ))
        ("QS" "隔离开关"(
            ("line" (0 -25) (70 0)) 
            ("line" (0 10) (0 -10)) 
        ))
        ("QS1" "负荷开关"(
            ("line" (0 -25) (70 0)) 
            ("line" (0 10) (0 -10))
            ("circle" (6 0) 6)
        ))
        ("KM" "接触器"(
            ("line" (0 -25) (70 0)) 
            ("arc" (0 0) (-7 0)(7 0)) 
        ))
        ("NO" "常开点"(
            ("line" (0 -25) (70 0)) 
        ))
        ("NC" "常闭点"(
            ("line" (0 25) (70 0))
            ("line" (0 0) (0 25))
        ))
        ("TA" "互感器"(
            ("circle" (0 0) 15)
            ("line" (0 15) (0 24))
            ("line" (-2.47 21.47) (2.47 16.53))
            ("line" (-2.47 23.47) (2.47 18.53))
        ))
        ("ZTA" "三相互感器"(
            ("circle" (0 0) 15)
            ("circle" (0 -39) 15)
            ("circle" (0 39) 15)
            ("line" (0 15) (0 24))
            ("line" (0 -15) (0 -24))
            ("line" (0 54) (0 63))
            ("line" (-2.47 21.47) (2.47 16.53))
            ("line" (-2.47 23.47) (2.47 18.53))
            ("line" (-2.47 -15.53) (2.47 -20.47))
            ("line" (-2.47 -17.53) (2.47 -22.47))
            ("line" (-2.47 60.47) (2.47 55.53))
            ("line" (-24 39) (24 39))
            ("line" (-24 -39) (24 -39))
        ))
    ))
)