(defun c:selectsimilarSE( / dcl_id dclname)
	(SETQ DCL_ID (LOAD_DIALOG (setq dclname (selectsimilar-dcl))))
	(if(< DCL_ID 0)(exit))  
	(if(not(NEW_DIALOG "selectsimilar" DCL_ID))(exit)) 
	(default_set)
	(default_settings)
	(action_tile "selectall" "(selectall)")
	(action_tile "cleartall" "(cleartall)")
	(action_tile "accept" "(ok_set)(done_dialog)")
	(action_tile "cancel" "(done_dialog)")
	(action_tile "help" "(help \"ZWCAD.chm\" \"\")")
	(START_DIALOG)
	(UNLOAD_DIALOG DCL_ID)
	(if dclname
	    (vl-file-delete dclname)
	)
	(princ)
)

(defun selectall()
	(set_tile "color" "1")
	(set_tile "layer" "1")
	(set_tile "linetype" "1")
	(set_tile "linetypescale" "1")
	(set_tile "lineweight" "1")
	(set_tile "plotstyle" "1")
	(set_tile "objectstyle" "1")
	(set_tile "name" "1")
)


(defun cleartall()
	(set_tile "color" "0")
	(set_tile "layer" "0")
	(set_tile "linetype" "0")
	(set_tile "linetypescale" "0")
	(set_tile "lineweight" "0")
	(set_tile "plotstyle" "0")
	(set_tile "objectstyle" "0")
	(set_tile "name" "0")
)

(defun default_set(/ flags)
	(if (getvar "SELECTSIMILARMODE");判断为空时的处理
		(progn
			(setq flags (getvar "SELECTSIMILARMODE"))
			(if (= 0 (logand flags 1))
				(setq r_color 0)
				(setq r_color 1)
			)
			(if (= 0 (logand flags 2))
				(setq r_layer 0)
				(setq r_layer 1)
			)
			(if (= 0 (logand flags 4))
				(setq r_linetype 0)
				(setq r_linetype 1)
			)	
			(if (= 0 (logand flags 8))
				(setq r_linetypescale 0)
				(setq r_linetypescale 1)
			)
			(if (= 0 (logand flags 16))
				(setq r_lineweight 0)
				(setq r_lineweight 1)
			)
			(if (= 0 (logand flags 32))
				(setq r_plotstyle 0)
				(setq r_plotstyle 1)
			)	
			(if (= 0 (logand flags 64))
				(setq r_objectstyle 0)
				(setq r_objectstyle 1)
			)
			(if (= 0 (logand flags 128))
				(setq r_name 0)
				(setq r_name 1)
			)
		)
		(setq r_color 0 r_layer 0 r_linetype 0 r_linetypescale 0 r_lineweight 0 r_plotstyle 0 r_objectstyle 0 r_name 0)
	)	
)


(defun default_settings()
	(set_tile "color" (rtos r_color))
	(set_tile "layer" (rtos r_layer))
	(set_tile "linetype" (rtos r_linetype))
	(set_tile "linetypescale" (rtos r_linetypescale))
	(set_tile "lineweight" (rtos r_lineweight))
	(set_tile "plotstyle" (rtos r_plotstyle))
	(set_tile "objectstyle" (rtos r_objectstyle))
	(set_tile "name" (rtos r_name))
)

(defun ok_set(/ flags)
	(setq flags 0)
	(if (= 1 (setq r_color(atoi(get_tile "color"))))
		(setq flags(+ 1 flags))
	)
	(if (= 1 (setq r_layer(atoi(get_tile "layer")))) 
		(setq flags(+ 2 flags))
	)
	(if (= 1 (setq r_linetype(atoi(get_tile "linetype"))))
		(setq flags(+ 4 flags))
	)
	(if (= 1 (setq r_linetypescale(atoi(get_tile "linetypescale"))))
		(setq flags(+ 8 flags))
	)
	(if (= 1 (setq r_lineweight(atoi(get_tile "lineweight"))))
		(setq flags(+ 16 flags))
	)
	(if (= 1 (setq r_plotstyle(atoi(get_tile "plotstyle"))))
		(setq flags(+ 32 flags))
	)
	(if (= 1 (setq r_objectstyle(atoi(get_tile "objectstyle"))))
		(setq flags(+ 64 flags))
	)
	(if (= 1 (setq r_name(atoi(get_tile "name"))))
		(setq flags(+ 128 flags))
	)
	(setvar "SELECTSIMILARMODE" flags)
)

(defun selectsimilarSSGet( / rc ss)
  (setq ss nil) ;局部变量本不需要初始化，但是
  (while (null ss)
    (setq rc (ssgetKW (zcet_GetResStr "IDS_SIM_MSG1" "\nSelect objects or [SEttings]: ") 
                      (strcat (zcet_GetResStr "IDS_SIM_MSG_KW1" "SEttings") " _SEttings")
                      nil
             )
    )
    (if (= (type rc) 'STR)
      (c:selectsimilarSE)
      (if rc 
        (setq ss rc)
        (quit)
      )
    )
  )
  
  ss
)
(defun c:selectsimilar(/ bname T_F_layeron T_F_freeze VLA_OBJ_visible VLA_OBJ_NAME VLA_OBJ_LAYER VLA_ACT_DOC LAYERNAME type_all and_pl_value block_ent ent sub_dim_type  sub_pl_type filter_all sub_lst_image sub_lst_table sub_lst_plot  sub_in_type sss i sub_lst_mleader filter_lst o_type o_color o_linetype o_linetypescale o_lineweight entname objname stylename imagefile lst c len flag obj_type plotstylename )
	(vl-load-com)
	(zcet_SilentInit)	
	(setq emdb (getvar "cmdecho"))
	(setvar "cmdecho" 0)
	(if (= 0 (getvar "PICKFIRST"))
		(progn    ;如果pickfirst设置为零的时候，选选择对象后执行命令时，需将选择集清空并将对象的选中状态去掉后再提示用户选择对象或设置
			(if (/= nil (setq sss (cadr (ssgetfirst))))
				(progn
					(setq sss nil)
					(cadr (sssetfirst nil sss))
					(setq sss (selectsimilarSSGet))
				)
				(setq sss (selectsimilarSSGet))
			)
		)
		(progn  ;如果pickfirst设置为1的时候，如果没有先选中对象而直接执行命令的话，需提示用户选择对象或设置，如果先选中对象再执行命令的话，直接选择类似的对象
			(if (null (setq sss (cadr (ssgetfirst))))
				(setq sss (selectsimilarSSGet))
			)
		)
	)
	
	(setq i 0)
	
	(default_set)
	(setq filter_all nil)  ;局部变量本不需要初始化，但是
	(while (< i (sslength sss))
		;(setq filter_lst (list(cons 0(setq o_type (cdr(assoc 0(entget(ssname sss i))))))))
		(setq ent (entget(ssname sss i)))
		(setq o_type (cdr(assoc 0 ent)))
		
		;***v.003****
		(setq type_all (append type_all (list o_type)))
				
		(setq filter_lst (list(cons 0 o_type)))
		
		(setq filter_lst(append filter_lst (list (assoc 410 ent)))) ;添加所在空间筛选
		
		;************由于，转角，对齐，角度，直径，半径，三点角度及坐标的0都是同样的**************
		;*********************故需要用70来进行区分**************************
		(if (= o_type "DIMENSION")
			;*********将picfirst选择集中的标注对象的70的值与7进行and运算后得到相应的标注类型*******
			;***********************0);转角标注***********************
			;***********************1);对齐标注***********************
			;***********************2);角度标注***********************
			;***********************3);直径标注***********************
			;***********************4);半径标注***********************
			;***********************5);三点角度标注***********************
			;***********************6);坐标标注***********************
			;*******将picfirst选择集中的标注对象的70的值逐一取出来后与and运算后的值保存成一个子表*******
			(setq sub_dim_type (append sub_dim_type (list (logand (cdr(assoc 70 ent)) 7))))
		)
				
		;************由于三维多线段，二维多线段，多边形网格及多面网格的0都是同样的**************
		;*********************故需要用70来进行区分**************************
		(if (= o_type "POLYLINE")
			;*********将picfirst选择集中的标注对象的70的值与88进行and运算后得到相应的标注类型*******
			;***********************0);二维多线段***********************
			;***********************8);三维多线段**********************
			;***********************16);多边形网格***********************
			;***********************64);多面网格***********************
			;*******将picfirst选择集中的标注对象的70的值逐一取出来后与88进行and运算后的值保存成一个子表*******
			(setq sub_pl_type (append sub_pl_type (list (logand (cdr(assoc 70 ent)) 88))))
		)
		
		;************由于块，外部参照及minsert块的0都是同样的**************
		;*********************故需要进一步区分**************************
		;******如果70的值为非0则表示该对象为多重插入******
		;******如果70的值为0则表示该对象为普通块或为外部参照******
		;******这时还需用block来进一步区分******
		;******即用(tblsearch "block" (cdr (assoc 2 (entget (car(entsel))))))后再查看70的值******
		
		(if (= o_type "INSERT")
			(if (/= (cdr(assoc 70 ent)) 0)
				(setq sub_in_type (append sub_in_type (list "Minsert")));如果70的值不为0则表明是多重插入，在子表中加入“Minsert”标记
				(progn
					(setq block_ent (tblsearch "block" (cdr (assoc 2 ent))));如果70的值为0则表明是外部参照或块，进一步取值命名块的值
					(if (= 4 (logand (cdr(assoc 70 block_ent)) 4));如果命名块70的值为4与4and运算后还为4的话，说明该对象为外部参照
						(setq sub_in_type (append sub_in_type (list "Xref")));在子表中加入“Xref”标记
						(setq sub_in_type (append sub_in_type (list "Block")));不为4的话，说明是块，加入“Block”标记
					)	
				)
			)
		)
		
		
		(if (= 1 r_color) 
			(progn
				(if(/= nil(setq o_color(assoc 62(entget(ssname sss i)))))
					(setq filter_lst(append filter_lst (list(cons 62 (cdr o_color)))))
					(setq filter_lst(append filter_lst (list (cons 62 256))))
				)
			)
		)
		(if (= 1 r_layer) 
			(setq filter_lst(append filter_lst (list(cons 8(cdr(assoc 8(entget(ssname sss i))))))))
		)
		(if (= 1 r_linetype) 
			(progn
				(if(/= nil(setq o_linetype(assoc 6(entget(ssname sss i)))))
					(setq filter_lst(append filter_lst (list(cons 6 (cdr o_linetype)))))
					(setq filter_lst(append filter_lst (list (cons 6 "BYLAYER"))))
				)
			)
		)
		(if (= 1 r_linetypescale) 
			(progn
				(if(/= nil(setq o_linetypescale(assoc 48(entget(ssname sss i)))))
					(setq filter_lst(append filter_lst (list(cons 48 (cdr o_linetypescale)))))
					(setq filter_lst(append filter_lst (list (cons 48 1))))
				)
			)
		)
		(if (= 1 r_lineweight) 
			(progn
				(if(/= nil(setq o_lineweight(assoc 370(entget(ssname sss i)))))
						(setq filter_lst(append filter_lst (list(cons 370 (cdr o_lineweight)))))
						(setq filter_lst(append filter_lst (list (cons 370 -1))))
				)
			)
		)
		
		;***************打印样式的特殊处理****************
		(if (= 1 r_plotstyle) 
			(progn
				(if (= (getvar "DEFLPLSTYLE") "Normal");;该图纸为命名相关打印样式
					(progn				
						(setq entname (ssname sss i))
						(setq objname(vlax-ename->vla-object entname))
						(setq plotstylename(vlax-get-property objname 'PlotStyleName))
						(setq sub_lst_plot(append sub_lst_plot (list plotstylename)))
					)
				)
			)
		)
		;***********************结束**************************
		
		(if (= 1 r_objectstyle) 
			(progn
				(if (or (= o_type "MTEXT")(= o_type "TEXT"))
					(setq filter_lst(append filter_lst (list(cons 7(cdr(assoc 7(entget(ssname sss i))))))))
				)
				(if (= o_type "DIMENSION")
					(setq filter_lst(append filter_lst (list(cons 3(cdr(assoc 3(entget(ssname sss i))))))))
				)
				(if (= o_type "MLINE")
					(setq filter_lst(append filter_lst (list(cons 2(cdr(assoc 2(entget(ssname sss i))))))))
				)
				;***************表样式的特殊处理****************
				(if (= o_type "ACAD_TABLE") 
					(progn
						(setq entname (ssname sss i))
						(setq objname(vlax-ename->vla-object entname))
						(setq stylename(vlax-get-property objname 'stylename))
						(setq sub_lst_table(append sub_lst_table (list stylename)))
					)
				)	
				
				;***********************结束**************************
				
				;***************多引线样式的特殊处理****************
				(if (= o_type "MULTILEADER") 
					(progn
						(setq entname (ssname sss i))
						(setq objname(vlax-ename->vla-object entname))
						(setq stylename(vlax-get-property objname 'stylename))
						(setq sub_lst_mleader(append sub_lst_mleader (list stylename)))
					)
				)	
				;***********ZWCAD2017 支持多引线*****************
				;************************结束*************************
			)
		)
		(if (= 1 r_name) 
			(progn
				(if (= o_type "INSERT")
				;*************V.007*****************
					(progn
						;(setq filter_lst(append filter_lst (list(cons 2(cdr(assoc 2(entget(ssname sss i))))))))
						(setq bname (cdr(assoc 2(entget(ssname sss i)))))
						;判断如果是无名块的话，因为星号是通配符，所以要作为块名进行过滤选择时需要在星号前面加一撇（数字1键前面的那个键）
						(if (= (substr bname 1 1) "*")
							(setq filter_lst(append filter_lst (list(cons 2 (strcat "`" bname)))))
							(setq filter_lst(append filter_lst (list(cons 2 bname))))
						)
					)	
				;*************V.007*****************
				)
				
				;*****************光栅图名称的特殊处理**************
				(if (= o_type "IMAGE")
					(progn
							(setq entname (ssname sss i))
							(setq objname(vlax-ename->vla-object entname))
							(setq imagefile(vlax-get-property objname 'imagefile))
							(setq imagefile(vl-filename-base  imagefile))
							(setq sub_lst_image(append sub_lst_image (list imagefile)))
					)
				)	
				;*****************************************************
			)
		)
		(setq i(+ i 1))
		(setq filter_all(append filter_all (list (cons -4 "<and"))))
		(setq filter_all(append filter_all filter_lst))
		(setq filter_all(append filter_all (list (cons -4 "and>"))))
		
	);while
	(setq filter_all(append (list (cons -4 "<or")) filter_all))
	(setq filter_all(append filter_all (list (cons -4 "or>"))))
	(setq lst (ssget"_X" filter_all))
	
	;;**************************特殊处理开始********************************
	(setq c 0)
	(setq len( sslength lst))
	(while (< c len)
		(setq entname (ssname lst c) flag t)
		(setq ent_lst (entget entname))
		(setq obj_type (cdr(assoc 0 ent_lst)))
		
		;*************v.003*************
		;***(setq filter_all '((0 . "DIMENSION"))) ***
		;***(setq lst (ssget"_X" filter_all)) ***
		;***(cadr (sssetfirst nil lst)) ***
		;***由于这样会连同(0 . "ARC_DIMENSION")和(0 . "LARGE_RADIAL_DIMENSION")的对象一起选上***
		;**故还需判断选择集里所选到的对象中如果有这两种对象的话*****
		;***还需看pickfirs中所选的对象里是否有该对象******
		;***如果没有的话还需做如下剔除处理****
		(if (= obj_type "ARC_DIMENSION")
			(if (= nil (member obj_type type_all))
				(progn
					  (ssdel entname lst)
					  (setq len (1- len) flag nil)
				)
			)
		)
		(if (= obj_type "LARGE_RADIAL_DIMENSION")
			(if (= nil (member obj_type type_all))
				(progn
					  (ssdel entname lst)
					  (setq len (1- len) flag nil)
				)
			)
		)
		
		
		;***************当sub_dim_type不为空时的出处理**************************
		;********后面的选择集lst中也选择对象的表中标注对象的70的值与7进行and运算得到相应的值*****
		(if (and sub_dim_type (= obj_type "DIMENSION"))
			(progn
				;*****将选择集lst表中的标注对象的70的值与7进行and运算*******
				(setq and_dim_value (logand (cdr(assoc 70 ent_lst)) 7))
				;****如得到的值不存在于sub_dim_type子表中则将该对象删除掉******
				(if (= nil(member and_dim_value sub_dim_type))
				    (progn
					  (ssdel entname lst)
					  (setq len (1- len) flag nil)
					)
				)
				
			)
		)
		
		;***************当sub_pl_type不为空时的出处理**************************
		;********后面的选择集lst中也选择对象的表中标注对象的70的值与88进行and运算得到相应的值*****
		(if (and sub_pl_type (= obj_type "POLYLINE"))
			(progn
				;*****将选择集lst表中的标注对象的70的值与88进行and运算*******
				(setq and_pl_value (logand (cdr(assoc 70 ent_lst)) 88))
				;****如得到的值不存在于sub_dim_type子表中则将该对象删除掉******
				(if (= nil(member and_pl_value sub_pl_type))
				    (progn
					  (ssdel entname lst)
					  (setq len (1- len) flag nil)
					)
				)
				
			)
		)
		
		
		(if (and sub_in_type (= obj_type "INSERT"))
			(if (/= 0 (cdr(assoc 70 ent_lst)))
				(progn
					(if (= nil(member "Minsert" sub_in_type));70的值不为0表明是多重插入对象，所以如果“Minsert”不在子表中的话，需将该对象删除
						(progn
						  (ssdel entname lst)
						  (setq len (1- len) flag nil)
						)
					)
				)
				(progn
					(if (= 4 (logand (cdr(assoc 70 (tblsearch "block" (cdr (assoc 2 ent_lst))))) 4))
						(progn
							(if (= nil(member "Xref" sub_in_type))
								(progn
								  (ssdel entname lst)
								  (setq len (1- len) flag nil)
								)
							)
						)
						(progn
							(if (= nil(member "Block" sub_in_type))
								(progn
								  (ssdel entname lst)
								  (setq len (1- len) flag nil)
								)
							)
						)
					)
				)
			)
		)
		
		
		;******************当sub_lst_plot不为空时的处理***********************
		(if sub_lst_plot
			(progn
				(setq objname(vlax-ename->vla-object entname))
				(setq plotstylename(vlax-get-property objname 'PlotStyleName))
				(if (= nil(member plotstylename sub_lst_plot))
				    (progn
					  (ssdel entname lst)
					  (setq len (1- len) flag nil)
					)
				)
			)
		)		
		
		;******************当sub_lst_table不为空时的处理***********************
		(if (and sub_lst_table (= obj_type "ACAD_TABLE"))
			(progn
				(setq objname(vlax-ename->vla-object entname))
				(setq stylename(vlax-get-property objname 'stylename))
				(if (= nil(member stylename sub_lst_table))
				    (progn
					  (ssdel entname lst)
					  (setq len (1- len) flag nil)
					)
				)
			)
		)
		
		;******************当sub_lst_mleader不为空时的处理***********************
		(if (and sub_lst_mleader (= obj_type "MULTILEADER"))
			(progn
				(setq objname(vlax-ename->vla-object entname))
				(setq stylename(vlax-get-property objname 'stylename))
				(if (= nil(member stylename sub_lst_mleader))
				    (progn
					  (ssdel entname lst)
					  (setq len (1- len) flag nil)
					)
				)
			)
		)
		;***********ZWCAD2017 支持多引线*****************
		;******************当sub_lst_image不为空时的处理***********************
		(if (and sub_lst_image (= obj_type "IMAGE"))
			(progn
				(setq objname(vlax-ename->vla-object entname))
				(setq imagefile(vlax-get-property objname 'imagefile))
				(setq imagefile(vl-filename-base  imagefile))
				(if (= nil(member imagefile sub_lst_image))
					(progn
						(ssdel entname lst)
						(setq len (1- len) flag nil)
					)
				)
			)
		)
		;***********如果对象所在的图层是关闭或者冻结的状态时，将该对象从选择集中去除*****************
		(setq T_F_layeron nil T_F_freeze nil VLA_OBJ_visible nil)
		(setq VLA_OBJ_NAME (vlax-ename->vla-object entname))
		(setq VLA_OBJ_LAYER (vla-get-layer VLA_OBJ_NAME))
		(setq VLA_ACT_DOC (vla-get-ActiveDocument (vlax-get-Acad-Object)))
		(setq LAYERNAME (vla-Item (vla-get-Layers VLA_ACT_DOC) VLA_OBJ_LAYER))
		(setq T_F_layeron (vla-get-LayerOn LAYERNAME))
		(setq T_F_freeze (vla-get-Freeze LAYERNAME))
		
		(if (or (= T_F_freeze :vlax-true) (= T_F_layeron :vlax-false))
			(progn
				(ssdel entname lst)
				(setq len (1- len) flag nil)
			)
		)
		;***********如果对象是隐藏或隔离的，则将该对象从选择集中去除*****************
		(setq VLA_OBJ_visible (vla-get-Visible VLA_OBJ_NAME))
		(if (= VLA_OBJ_visible :vlax-false)
			(progn
				(ssdel entname lst)
				(setq len (1- len) flag nil)
			)
		)
				
		(if flag
		  (setq c (+ c 1))
		)

	)
	;;**************************特殊处理结束********************************
	
	(cadr (sssetfirst nil lst))
	(setvar "cmdecho" emdb)
	(zcet_SilentUnInit)
	(princ)
)

(princ)