图层名列表中的元素排序问题,请各位赐教!
列表中的元素排序问题: DWG图中有图层名有如下 "DIE_1_PW" "DIE_2_PW""DIE_PW" "PH_1_PW""PH_PW" "PS_1_PW" "PS_2_PW""PS_PW",怎么写个程序自动获取图层名列表的排序为:("DIE_PW" "DIE_1_PW" "DIE_2_PW" "PS_1_PW" "PS_2_PW" "PS_PW""PH_PW" "PH_1_PW" ) (setq lst '("PS_2_PW" "DDD-1" "DIE_1_PW" "PS_PW""PH_PW" "DIE_PW" "PH_1_PW" "DIE_2_PW"
"DDD-34" "PS_1_PW"
)
)
(setq lst< '("DIE" "PS" "PH"))
(foreach abc lst
(or (vl-position
t
(mapcar
'(lambda (x) (wcmatch abc (strcat x "*")))
lst<
)
)
(setq lst2 (cons abc lst2))
)
)
(append
(apply
'append
(mapcar
'(lambda (a / l)
(if (setq l (vl-remove-if-not
'(lambda (b) (wcmatch b (strcat a "*")))
lst
)
)
(vl-sort l
'(lambda (c d / an)
(setq an (+ (strlen a) 2))
(< (atoi (substr c an 1)) (atoi (substr d an 1)))
)
)
)
)
lst<
)
)
(reverse lst2)
)
(setq lst '("PS_2_PW" "DIE_1_PW" "PS_PW" "PH_PW" "DIE_PW" "PH_1_PW" "DIE_2_PW" "PS_1_PW"))
(setq lst< '("DIE" "PS" "PH"))
(apply
'append
(mapcar
'(lambda(a / l)
(if(setq l(vl-remove-if-not '(lambda(b)(wcmatch b(strcat a "*")))lst))
(vl-sort l
'(lambda(c d / an)
(setq an(+(strlen a)2))
(<(atoi(substr c an 1))(atoi(substr d an 1)))
)
)
)
)
lst<
)
) "DIE_PW" "DIE_1_PW" "DIE_2_PW"
"PS_1_PW" "PS_2_PW" "PS_PW"
"PH_PW" "PH_1_PW"
还有更多图层吗?
若只此好办...
针对你所讲的这种情况和规律。
(setq lst '("DIE_1_PW" "DIE_2_PW" "DIE_PW" "PH_1_PW""PH_PW" "PS_1_PW" "PS_2_PW""PS_PW"))
(setq lst0 (mapcar '(lambda (x)
(if (not (wcmatch x "*__*"))
(progn
(setq p (vl-string-position (ascii "_") x))
(strcat (substr x 1 p) "_0_" (substr x (+ 2 p)))
)
x
))
lst
))
(mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst0 '<))
Command: (mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst0 '<))
("DIE_PW" "DIE_1_PW" "DIE_2_PW" "PH_PW" "PH_1_PW" "PS_PW" "PS_1_PW" "PS_2_PW")
察觉与诉求的排列不合 如果图名名称都是死的,何必读取排序,直接按照自己需要的顺序定义一个变量就行了。 Bao_lai 发表于 2024-9-22 21:51
针对你所讲的这种情况和规律。
感谢回应,试后的结果还差点,ph开头的图层名能不能给我排到PS开的图层名后面去吧,("DIE_PW" "DIE_1_PW" "DIE_2_PW" "PS_1_PW" "PS_2_PW" "PS_PW""PH_PW" "PH_1_PW" ) caoyongjun 发表于 2024-9-24 20:50
感谢回应,试后的结果还差点,ph开头的图层名能不能给我排到PS开的图层名后面去吧,("DIE_PW" "DIE_1_PW ...
感觉你这个没有很大的规律,如果图层不多,建议按楼上,定义一变量表,按这个变量表来排序。
或者你再扩大一些数据或者说明,大家帮你找一下规律和方法。 Bao_lai 发表于 2024-9-24 22:13
感觉你这个没有很大的规律,如果图层不多,建议按楼上,定义一变量表,按这个变量表来排序。
或者你再扩 ...
现在只要把ph开头的图层名排在PS开头的图层名后面就行了。 xtjd 发表于 2024-9-26 07:58
(setq lst '("PS_2_PW" "DIE_1_PW" "PS_PW" "PH_PW" "DIE_PW" "PH_1_PW" "DIE_2_PW" "PS_1_PW"))
(setq ls ...
非常感谢!
页:
[1]
2