Filter list of objects based on their xdata

Filter list of objects based on their xdata

lminnema
Explorer Explorer
207 Views
5 Replies
Message 1 of 6

Filter list of objects based on their xdata

lminnema
Explorer
Explorer

I need a function that I can supply with a list of vla objects and a specific number stored in xdata group 1070,  and it will return a list of just the vla objects with that specific number stored. For example a list of 5 objects: who have numbers 1, 3, 2, 3, and 5 stored to them respectively, I would say specInstnce is 3, it would return a list containing just objects 2 and 4. I have also supplied the function that I am using that takes an object's ename or vla-object and returns the value that is stored in 1070. 

(defun getxdata (obj)
  (cond 
    ((= 'VLA-object (type obj))
     (cdr 
       (assoc 1070 
              (cdr 
                (car 
                  (cdr 
                    (assoc -3 
                           (entget (vlax-vla-object->ename obj) (list oneline:app))
                    )
                  )
                )
              )
       )
     )
    )
    ((= 'ENAME (type obj))
     (cdr (assoc 1070 (cdr (car (cdr (assoc -3 (entget obj (list oneline:app))))))))
    )
  )
)

(defun getspecificowners (vlaObjects specInstnce)
 (mapcar '(lambda (x) (if (= (getxdata x) specInstnce))) vlaObjects)
)

 The first function here works fine, but it is probably not very well written. The second function here does not work at all and I don't think I'm anywhere close with the code currently written. 

 

Thanks in advance.

0 Likes
Accepted solutions (1)
208 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

@lminnema wrote:

.... 

....
(defun getspecificowners (vlaObjects specInstnce)
 (mapcar '(lambda (x) (if (= (getxdata x) specInstnce))) vlaObjects)
)

.... The second function here does not work at all ....


There's no "then expression" for that (if) function.  I think you need:

.... (if (= (getxdata x) specInstnce) [what-to-do-if-it-matches])) ....

Presumably what-to-do would be to put it into another list of qualifying ones only, for whatever you need to do with them.  Or maybe if it doesn't match, remove it from the vlaObjects list if you don't need to retain the complete list but only the qualifying ones.

Kent Cooper, AIA
Message 3 of 6

BlackBox_
Advisor
Advisor
Accepted solution

@lminnema *IF* I understood Kent's apt post correctly, something like this may help:

 

(defun getspecificowners (vlaObjects specInstnce / matchingObjects)
  (mapcar
    (function
      (lambda (x)
        (if (= (getxdata x) specInstnce)
          (setq matchingObjects (cons x matchingObjects))
          )
        )
    )
    vlaObjects
  )
  matchingObjects
)

 

Note: You didn't post a sample drawing, so untested. 

"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 4 of 6

komondormrex
Mentor
Mentor

check the following function. outputs list of objects with '(1070 . specific_number) xdata group or nil.

(defun filter_specific_xdata_object (object_list specific_number oneline:app / target_object)
	(vl-remove nil
	  	   (mapcar '(lambda (object) (if (vl-some '(lambda (xdata_group) (equal (cons 1070 specific_number) xdata_group))
					         	(cdadr (assoc -3 (entget (vlax-vla-object->ename (setq target_object object)) (list oneline:app))))
				                 )
				                 target_object
				  	     )
		            )
		            object_list
	           )
	)
)

object_list - list of vla objects to be checked

specific_number - integer in xdata 1070 group

oneline:app - xd application name

 

Message 5 of 6

lminnema
Explorer
Explorer

Thanks for the help, it took me a while to get the rest of the program working, but this was a major help.

0 Likes
Message 6 of 6

BlackBox_
Advisor
Advisor

@lminnema wrote:

Thanks for the help, it took me a while to get the rest of the program working, but this was a major help.


@Kent1Cooper gave the idea, I just helped. 🍺

 

Cheers

"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes