- 积分
- 11379
- 明经币
- 个
- 注册时间
- 2011-10-13
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 邹锋 于 2021-12-23 15:25 编辑
最近需求要做图标,所以开发个CAD做图标工具,CAD框选转SVG 的源码 ,SVG的好处理可以放很大都不会模糊
代码很简单的
下面是编辑器改颜色用的
2021-12-22
;;示例(HH:rtosr 2.500);"2.5"
(defun HH:rtosr (RealNum / DIMZIN1 SHORTREAL1)
(setq DimZin1 (getvar "DIMZIN"))
(setvar "DIMZIN" 8)
(setq ShortReal1 (rtos RealNum 2 8))
(setvar "DIMZIN" DimZin1)
ShortReal1
)
;;;;by 明经黄贡偳
;;示例1 保留一位小数,四舍五入(HH:rtosr1 2.555 1);"2.6"
(defun HH:rtosr1 (RealNum n / DIMZIN1 SHORTREAL1)
(setq DimZin1 (getvar "DIMZIN"))
(setvar "DIMZIN" 0)
(setq ShortReal1 (rtos RealNum 2 n))
(setvar "DIMZIN" DimZin1)
(setq num (atof shortreal1))
(setq ShortReal2 (HH:rtosr num))
ShortReal2
)
(defun c:cj (/ SS)
(setvar "cmdecho" 0)
(setq xx (ssget))
(vl-cmdf "pedit" "m" xx "" "y" "j" "j" "" 0.1 "")
(princ)
)
;;CAD 做SVG 支持直线,圆 多线段 要串起来 就是实心的,打散就是线条
(defun c:svg()
(setq ffn (getfiled "另存为" "" "svg" 1))
(setq out (open ffn "w"))
(SETQ SS (SSGET))
(write-line "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>" out)
(write-line "<svg width=\"200\" height=\"200\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">" out)
(SETQ i 0)
(repeat (sslength ss)
(setq pline (ssname ss i))
(setq ent (entget pline))
(cond ((= (cdr (assoc 0 ent)) "LWPOLYLINE")
(write-line "<polyline points=\"" out)
(setq str "")
(foreach lst ent
(if (= (car lst) 10)
(progn
(setq point (cdr lst))
(setq xx (HH:rtosr1 (abs (car point))0))
(setq yy (HH:rtosr1 (abs (cadr point))0))
;(setq pts (append pts (list (cdr lst))))
(setq str (strcat str xx " " yy ","))
)
)
)
(setq js (- (strlen str) 1))
(setq s1(substr str 1 js))
(write-line s1 out)
(write-line "\" fill=\"#000000\" stroke=\"none\" stroke-opacity=\"0\" xmlns=\"http://www.w3.org/2000/svg\" />" out)
(print)
)
((= (cdr (assoc 0 ent)) "LINE")
(write-line "<line " out)
(setq p1 (cdr (assoc 10 ent))
p2 (cdr (assoc 11 ent))
xx1 (HH:rtosr1 (abs (car p1))0)
yy1 (HH:rtosr1 (abs (cadr p1))0)
xx2 (HH:rtosr1 (abs (car p2))0)
yy2 (HH:rtosr1 (abs (cadr p2))0)
)
(setq s1 "")
(setq s1(strcat s1 "x1=\"" xx1 "\" y1=\"" yy1 "\" x2=\"" xx2 "\" y2=\"" yy2))
(write-line s1 out)
(write-line "\" style=\"stroke:rgb(255,0,0);stroke-width:2\"/>" out)
(print)
)
((= (cdr (assoc 0 ent)) "CIRCLE")
(write-line "<circle " out)
(setq p1 (cdr (assoc 10 ent))
rad (cdr (assoc 40 ent))
xx1 (HH:rtosr1 (abs (car p1))0)
yy1 (HH:rtosr1 (abs (cadr p1))0)
rr (HH:rtosr1 (abs rad)0)
)
(setq s1 "")
(setq s1(strcat s1 "cx=\"" xx1 "\" cy=\"" yy1 "\" r=\"" rr))
(write-line s1 out)
(write-line "\" style=\"stroke:rgb(255,0,0);stroke-width:2\"/>" out)
(print)
)
((= (cdr (assoc 0 ent)) "TEXT")
(write-line "<text " out)
(setq p1 (cdr (assoc 10 ent))
txt (cdr (assoc 1 ent))
xx1 (HH:rtosr1 (abs (car p1))0)
yy1 (HH:rtosr1 (abs (cadr p1))0)
)
(setq s1 "")
(setq s1(strcat s1 "x=\"" xx1 "\" y=\"" yy1 "\" fill=\"red\">" txt))
(write-line s1 out)
(write-line " </text>" out)
(print)
)
)
; <text x="0" y="15" fill="red">I love SVG</text>
(SETQ I (1+ i))
;(print pts)
(princ)
)
(write-line "</svg>" out)
;(princ "</svg>")
(close out)
(princ )
)
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
评分
-
查看全部评分
|