AutoLisp编程笔记——选择集方法集锦

(setq ss (ssget '((0 . "insert"))))	;提交交互选择

;加"X"不提示直接选择,选择图形文件中GCD层上的块对象
(setq ss (ssget "X" '((0 . "insert") (8 . "GCD"))))	
;选择图形文件中块名含GC的块对象(CASS地形点)
(setq ss (ssget "X" '((0 . "insert") (2 . "GC*"))))

;把在“BTL”层中颜色为1的全部直线收入a中
(setq a (ssget "X" '((0 . "LINE") (8 . "BTL") (62 .1))))

;把指定层中的所有对象放入选择集ss中
(setq layer (getstring "请输入层名:"))
(setq ss (ssget "X" (list (cons 8 layer))))

;全选
(setq all (ssget "X"))

;将所有半径大于等于2的圆选中
(ssget "X" '((0 . "CIRCLE") (-4 . ">=") (40 . 2.0)))

;把半径100的圆、颜色为110在BASE层上的直线选中
(setq ss
	(ssget "X"  
		'(
			(-4 . "<OR")
				(-4 . "<AND")(0 . "CIRLE")(40 . 100.0)(-4 . "AND>")
				(-4 . "<AND")(0 . "LINE")(8 . "BASE")(62 . 110)(-4 . "AND>")
			(-4 . "OR>")
		)
	)
)
;"<OR"、"OR>"以"<AND"、"AND>"在条件两头标记。

(setq ss (ssget ":S" '((0 . "LINE"))))	;只选取一次直线(省约回车) 
(setq ss (ssget "X" '((0 . "LINE"))))	;自动选取直线,包含冻结的直线 
(setq ss (ssget "A" '((0 . "LINE"))))	;自动选取直线,不包含冻结的直线 
(setq ss (ssget '((1 . "*[0-9]*"))))	;只选取含数字的文本 
(setq ss (ssget '((1 . "*#*"))))	;只选取含数字的文本 
(setq ss (ssget '((0 . "TEXT") (1 . "~*[~`--9]*")))) ;只选取数字文本 
(setq ss (ssget '((0 . "TEXT") (-4 . ")(1 . "*[0-9]*")(-4 . "NOT>"))) ;只选择不是数字的文字 

(setq ss (ssget '((0 . "TEXT")(1 . "~*#*"))));只选择不是数字的文字 
(setq ss (ssget '((0 . "TEXT")(1 . "#,1#,2#,3#,4#,50"))));选取1—50的数字文本 
(SETQ SS (SSGET '((0 . "*text")(1 . "*(*,*)*,*(*,**)**"))));选取含括号的文本 
(setq ss (ssget '((1 . "*[a-A-z-Z]*"))));只选取字母 
(setq ss (ssget '((0 . "~insert")))) ;选取不含块的对象 
(SETQ ss (ssget (list '(0 . "CIRCLE")(cons 40 RR))));按半径的大小选取圆 
(setq ss (ssget ":E:S" '((0 . "line"))));选取拾取框内的直线,选取不到就结束 
(setq ss (ssget ":E" '((0 . "LINE"))));选取拾取框内的直线,选取不到就不结束,直到按右键 
(setq ss (ssget ":N" '((0 . "LINE"))));只有通过窗口、窗交点拾取 
(setq ss (ssget ":D" '((0 . "LINE"))));会累加选取的直线,同一条直线,选取两次个数就会乘以2,3次则3..... 
(setq ss (ssget ":L" '((0 . "LINE"))));提示有几个在锁定图上,选取没有的锁定的直线 
(setq ss (ssget "P" '((0 . "LINE"))));上次的选择集 
(setq ss (ssget '((0 . "line")(8 . "~0"))));选取0层以外的线 
(setq ss (ssget '((0 . "line")(8 . "~*[a-A-z-Z]*"))));选取图层名不含字母以外的线 
(setq ss (ssget '((0."CIRCLE") (-3 ("APPNAME")))));选取带扩展数据的实体(圆) 
;得到矩形p1 p2点框内的文字,包含在框内的被选取相交的不选取,屏幕外的选取不到,WP点集 
(setq ss(ssget "w" pt1 pt3 '((0 . "*text")))) 
;得到矩形p1 p2点框内的文字,包含在框内的及和框相交的被选取,屏幕外的选取不到,CP点集 
(setq ss(ssget "c" pt1 pt3 '((0 . "*text")))) 
;线相交的线删除(屏幕外的选取不到郁闷所以要用zoom "ob") 
(defun c:XX( / pt ptl ss) 
 (setq ptl nil) 
 (while (setq pt (getpoint)) 
 (setq ptl (cons pt ptl)) 
 ) 
(setq ss (ssget "f" ptl '((0 . "line")))) 
 (KX-E SS) 
) 
;选取图层表("CENTER" "DIM" "COOL" "CORE" -------N个图层)内的线 
(setq la '("CENTER" "DIM" "COOL" "CORE") 
ss (ssget (list '(0 . "LINE") (cons 8 (apply 'strcat (mapcar '(lambda (x) (strcat x ",")) la))))) 
) 
;选取经过某点的实体 
(setq pt (getpoint)) 
(setq ss (ssget "C" pt pt)) 
;选取不含数字的文本 
(setq ss (ssget ' 
 ((-4 . ") 
 (0 . "*TEXT") 
 (-4 . ") 
 (1 . "*[0-9]*") 
 (-4 . "NOT>") 
 (-4 . "AND>") 
 ) 
 ) 
) 
;只选取不含字母的文本 
(setq ss (ssget ' 
 ((-4 . ") 
 (0 . "*TEXT") 
 (-4 . ") 
 (1 . "*[a-A-z-Z]*") 
 (-4 . "NOT>") 
 (-4 . "AND>") 
 ) 
 ) 
) 
;------------------------------------------------------------------------------------------------------------ 
;"图层1" "图层2""图层n中的文本,图层1为层名 
(SETQ SS (ssget "x" 
 (list 
'(0 . "TEXT") 
 (cons 8 "图层[1-n]") 
 ) 
 ) 
) 
;------------------------------------------------------------------------------------------------------------ 
;选取0层以外的线 
 (setq ss 
 (ssget ' 
 ((-4 . ") 
 (0 . "line") 
 (-4 . ") 
 (8 . "0") 
 (-4 . "NOT>") 
 (-4 . "AND>") 
 ) 
 ) 
 ) 
;------------------------------------------------------------------------------------------------------------ 
;按颜色号选取对象 
(setq col (KX-Int 7 "" "颜色号" col 1)) 
(setq SS (ssget 
 (list 
'(-4 . ") 
 (cons 62 COL) 
'(-4 . "OR>") 
 ) 
 ) 
) 
;----------------------------------------------------------------------------------------------------------- 
;选取含KX的文本 
(setq XT (strcat "*" "KX" "*"));KX为文字内容 
(ssget (list 
'(0 . "text") 
 (cons 1 XT) 
 ) 
) 
;----------------------------------------------------------------------------------------------------------- 
;判断选取某个区域有没有直线 
(setq SS (ssget "c" 
 (polar '(0 0) (* 0.25 pi) 0.5);坐标点 
 (polar '(0 0) (* 1.25 pi) 0.5);坐标点 
'((0 . "LINE")) 
 ) 
) 
;----------------------------------------------------------------------------------------------------------- 
;选取颜色不是随层的圆、直线 
(setq SS (ssget "X" 
'((0 . "CIRCLE,LINE") 
 (-4 . "/=")(62 . 256);-4 62"面不可以加AND OR 
 ) 
 ) 
) 
;------------------------------------------------------------------------------------------------------------ 
;选取颜色1和2的对象(OR)的用法 
(setq ss (ssget '((-4 . ") 
 (62 . 2) 
 (62 . 1) 
 (-4 . "or>") 
 ) 
 ) 
) 
;-------------------------------------------------------------------------------------------------------------- 
;选取半径大于20小于100的圆 
(setq ss (ssget ' 
 ((-4 . ") 
 (0 . "circle") 
 (-4 . ">")(40 . 20);大于20 
 (-4 . "<")(40 . 100);小于100 
 (-4 . "and>") 
 ) 
 ) 
) 
;-------------------------------------------------------------------------------------------------------------- 
;只选取"文字(包括多行文字)、尺寸、带属性的块 
(setq ss (SSGET ' 
 ((-4 . ") 
 (0 . "*TEXT,DIMENSION") 
 (-4 . ") 
 (0 . "INSERT") 
 (66 . 1) 
 (-4 . "AND>") 
 (-4 . "OR>") 
 ) 
 ) 
) 
;-------------------------------------------------------------------------------------------------------------- 
;屏幕外的窗口模式选取 
(setq rec_p1 '(0 0)) ;窗口左下角点 
(setq rec_p2 '(1000 1000)) ;窗口右上角点 
(setq filter_list 
 (list 
'(0 . "insert") 
'(-4 . ") 
'(-4 . ">,>,*") (cons 10 rec_p1) 
'(-4 . "<,<,*") (cons 10 rec_p2) 
'(-4 . "and>") 
 ) 
) 
(ssget "x" filter_list) 
;-------------------------------------------------------------------------------------------------------------- 
;-------------------------------------------------------------------------------------------------------------- 
;一次产生n个不同选取集 
(if (setq ss (ssget)) (setq ss1 (ssget "_p" '((0 . "*TEXT")))));从选择集中分解出文字 
;空回车得出不同结果的选取集 
(if (setq ss (ssget)) 
 (setq ss (ssget "_p" flt)) 
 (setq ss (ssget "_x" flt)) 
) 
;-------------------------------------------------------------------------------------------------------------- 
;;;坐标范围选择,有点类似(ssget "c" p1 p2 filter),但本函数在屏幕外的也可选择 
;;;测试 (tt (getpoint) (getpoint) '((0 . "insert"))) 
(defun tt (p1 p2 filter / minX minY maxX maxY) 
(setq minX (min (car p1) (car p2)) 
minY (min (cadr p1) (cadr p2)) 
maxX (max (car p1) (car p2)) 
maxY (max (cadr p1) (cadr p2)) 
) 
(if filter 
 (ssget "x" 
 (append (list '(-4 . ") 
'(-4 . ">=,>=,*") 
 (list 10 minX minY 0) 
'(-4 . "<=,<=,*") 
 (list 10 maxX maxY 0) 
 ) 
 (append filter '((-4 . "and>"))) 
 ) 
 ) 
 (ssget "X" 
 (list '(-4 . ") 
'(-4 . ">=,>=,*") 
 (list 10 minX minY 0) 
'(-4 . "<=,<=,*") 
 (list 10 maxX maxY 0) 
'(-4 . "and>") 

相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页