Extract data from SS

Extract data from SS

etilley327KA
Advocate Advocate
523 Views
6 Replies
Message 1 of 7

Extract data from SS

etilley327KA
Advocate
Advocate

Im trying to select objects with a certain layer out of a SS. Ive tried a couple different ways with no success, pleas help.

 

(defun c:test (/ A sel i e f)
(setq A (ssget '((8 . "*FOOTPRINT BOUNDARY*,*ANNO-TBLK-NOTE*,AP-BOUNDARY"))))
(repeat (setq i (sslength A))
  (setq e (ssname A (setq i (1- i))))
  (setq f (cons e f)))
(setq sel (ssname f (entget '((8 . "*FOOTPRINT BOUNDARY*")))))
(princ sel)
)
0 Likes
Accepted solutions (1)
524 Views
6 Replies
Replies (6)
Message 2 of 7

hak_vz
Advisor
Advisor
Accepted solution

 

 

(defun c:test (/ A sel i e lname)
	(setq A (ssget '((8 . "*FOOTPRINT BOUNDARY*,*ANNO-TBLK-NOTE*,AP-BOUNDARY"))))
	(cond
		((and A)
			(setq  sel	(ssadd) i -1)
			(while (< (setq i (1+ i)) (sslength A))
				(setq e (ssname A i) lname (cdr (assoc 8 (entget e))))
				(cond 
					((wcmatch "*FOOTPRINT BOUNDARY*" lname)
						(setq sel (ssadd (ssname A i) sel))
					)
				)
			)
		)
	)
	sel
)

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 7

paullimapa
Mentor
Mentor

You are doing fine up to this line

(setq e (ssname A (setq i (1- i))))

Now that you have the entity e you need to get the entity data with

(setq ed (entget e))

Now you can retrieve the assoc 8 layer to check name

(setq lyr (cdr(assoc 8 ed)))

Now you can use a function like wcmatch to do a wild card comparison

(wcmatch lyr "*FOOTPRINT BOUNDARY*)

If this is true then you’ll add this to a new selection set by first initializing it

(setq f (ssadd))

then add e to the f selection set

(setq f (ssadd e f)))

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 7

Kent1Cooper
Consultant
Consultant

@etilley327KA wrote:

Im trying to select objects with a certain layer out of a SS. ....


(setq A (ssget '((8 . "*FOOTPRINT BOUNDARY*,*ANNO-TBLK-NOTE*,AP-BOUNDARY"))))

(sssetfirst nil A); select/highlight the first selection set, so they become the "_Implied" selection for:

(setq TheSetYouWant (ssname "_I" '((8 . "*FOOTPRINT BOUNDARY*"))))

Kent Cooper, AIA
0 Likes
Message 5 of 7

etilley327KA
Advocate
Advocate
Sorry, you lost me on the last part. Once its reselected how does it extract the data?
0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant

@etilley327KA wrote:
Sorry, you lost me on the last part. Once its reselected how does it extract the data?

You can go on to extract data in the usual way.  My suggestion was just for the part I quoted about getting things on certain Layers out of a larger selection set.  The "_I" selection mode in (ssget) is for finding things only within the Implied selection, which means any pre-selected object(s) -- the (sssetfirst) function is pre-selecting the larger set for the purpose.  Only those objects in it that fit the more restrictive filter get put into another selection set [held in the variable I called TheSetYouWant].  Use (ssname) to get an entity name out of that, etc.

Kent Cooper, AIA
Message 7 of 7

paullimapa
Mentor
Mentor

here's another method of separating each matching layer into their own selection set after a combined selection set has been created:

 

 

(if(setq A (ssget '((8 . "*FOOTPRINT BOUNDARY*,*ANNO-TBLK-NOTE*,AP-BOUNDARY"))))
 (progn ; only continue if there are items selected
  (setq f1 (ssadd) f2 (ssadd) f3 (ssadd)) ; initialize 3 separate selection sets
  (foreach ent (mapcar 'cadr (ssnamex A)) ; use mapcar to convert selection set A to a list using cadr function to get 2nd element which is the entity of ssnamex function
  (setq lyr (strcase(cdr(assoc 8(entget ent))))) ; get entities layer name convert to uppercase
   (cond
    ((wcmatch lyr "*FOOTPRINT BOUNDARY*")(ssadd ent f1)) ; add entity to f1 set when layer name matches
    ((wcmatch lyr "*ANNO-TBLK-NOTE*")(ssadd ent f2)) ; add entity to f2 set when layer name matches
    ((equal lyr "AP-BOUNDARY")(ssadd ent f3)) ; add entity to f2 set when layer name equals
   ) ; cond
  ) ; foreach loop through list
 ) ; progn
) ; if A

 

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes