Author Topic: Create selection set based on picked field attributes  (Read 3411 times)

0 Members and 1 Guest are viewing this topic.

jpcadconsulting

  • Newt
  • Posts: 56
Create selection set based on picked field attributes
« on: August 11, 2015, 02:10:43 PM »
Hi gang,

I'm trying to write a routine that allows me to pick on an attribute (field) in a block, and create a selection set of all other blocks of that name that have the same value in that field.  Make sense?

In other words I want to click on the "Species" attribute of a block called "Tree1" and I want AutoCAD to select all other "Tree1" blocks that have a similar value for "Species"

The FIND command does not seem to work because (I think) the value of the "species" attribute is a field driven by a lookup table.  I believe this problem is compounded by the fact that these are dynamic blocks and once a parameter is changed, they take on a unique name...

Thanks in advance for any help.

-JP

Technology will save us all! *eyeroll*

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Create selection set based on picked field attributes
« Reply #1 on: August 11, 2015, 03:22:39 PM »
Give this a go.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ s e l sd ss nm)
  2.   ;; Tharwat 11.08.2015 ;;
  3.   (if (and (setq s (nentsel "\nPick on Attribute in a block :"))
  4.            (eq (cdr (assoc 0 (setq e (entget (car s))))) "ATTRIB")
  5.            (eq (cdr (assoc 0 (setq l (entget (cdr (assoc 330 e))))))
  6.                "INSERT"
  7.            )
  8.            (setq sd (ssadd)
  9.                  s  (strcase (cdr (assoc 1 e)))
  10.            )
  11.            (setq ss
  12.                   (ssget
  13.                     "_X"
  14.                     (list
  15.                       '(0 . "INSERT")
  16.                       (cons 410 (getvar 'CTAB))
  17.                       (cons
  18.                         2
  19.                         (strcat "`*U*,"
  20.                                 (setq
  21.                                   nm (vla-get-effectivename
  22.                                        (vlax-ename->vla-object (cdr (assoc -1 l)))
  23.                                      )
  24.                                 )
  25.                         )
  26.                       )
  27.                       '(66 . 1)
  28.                     )
  29.                   )
  30.            )
  31.       )
  32.     ((lambda (i / sn o)
  33.        (while (setq sn (ssname ss (setq i (1+ i))))
  34.          (if
  35.            (and (eq nm
  36.                     (vla-get-effectivename
  37.                       (setq o (vlax-ename->vla-object sn))
  38.                     )
  39.                 )
  40.                 (vl-some
  41.                   '(lambda (x) (eq s (strcase (vla-get-textstring x))))
  42.                   (vlax-invoke o 'getAttributes)
  43.                 )
  44.            )
  45.             (ssadd sn sd)
  46.          )
  47.        )
  48.      )
  49.       -1
  50.     )
  51.   )
  52.   (sssetfirst nil sd)
  53.   (princ)
  54.  
« Last Edit: August 12, 2015, 02:45:14 PM by Tharwat »

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Create selection set based on picked field attributes
« Reply #2 on: August 11, 2015, 11:02:54 PM »
Not sure but QSelect might work for you?
Hi gang,

I'm trying to write a routine that allows me to pick on an attribute (field) in a block, and create a selection set of all other blocks of that name that have the same value in that field.  Make sense?

In other words I want to click on the "Species" attribute of a block called "Tree1" and I want AutoCAD to select all other "Tree1" blocks that have a similar value for "Species"

The FIND command does not seem to work because (I think) the value of the "species" attribute is a field driven by a lookup table.  I believe this problem is compounded by the fact that these are dynamic blocks and once a parameter is changed, they take on a unique name...

Thanks in advance for any help.

-JP

jpcadconsulting

  • Newt
  • Posts: 56
Re: Create selection set based on picked field attributes
« Reply #3 on: August 12, 2015, 02:10:57 PM »
Thanks Tharwat, but it does not seem to do anything.

Loads fine, runs fine, not throwing errors, but no result...

Thoughts?
Technology will save us all! *eyeroll*

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Create selection set based on picked field attributes
« Reply #4 on: August 12, 2015, 02:19:14 PM »
I tested the codes after posting them and it did work , anyway can you upload a sample drawing consists of the blocks that you wan to run the program on ?

jpcadconsulting

  • Newt
  • Posts: 56
Re: Create selection set based on picked field attributes
« Reply #5 on: August 12, 2015, 02:24:18 PM »
I will, and it does work fine on blocks with regular attributes.

The tree blocks in the drawing are dynamic.

So I think it grabs the block's unique name (which is something like *U58 and not "tree")

I think the code needs something like:

Code: [Select]
(vla-get-Effectivename)
But I would not know how to implement...

Thanks so much for your help.
Technology will save us all! *eyeroll*

jpcadconsulting

  • Newt
  • Posts: 56
Re: Create selection set based on picked field attributes
« Reply #6 on: August 12, 2015, 02:44:13 PM »
So I added the following lines at the end of the code so it woudl report the variable values.

Code: [Select]
(princ s)
(princ e)
(princ l)
(princ sd)
(princ ss
)

And it does report the following:

JAPANESE WHITE PINE((-1 . <Entity name: 7ffffb816e0>) (0 . ATTRIB) (5 . 944E) (102 . {ACAD_XDICTIONARY) (360 . <Entity name: 7ffffb816f0>) (102 . }) (330 . <Entity name: 7ffffb81610>) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (62 . 2) (100 . AcDbText) (10 3108.78 2977.12 0.0) (40 . 3.125) (1 . JAPANESE WHITE PINE) (50 . 0.0019959) (41 . 1.0) (51 . 0.0) (7 . Standard) (71 . 0) (72 . 1) (11 3136.2 2980.3 0.0) (210 0.0 0.0 1.0) (100 . AcDbAttribute) (280 . 0) (2 . CNAME) (70 . 1) (73 . 0) (74 . 3) (280 . 1))((-1 . <Entity name: 7ffffb81610>) (0 . INSERT) (5 . 9441) (102 . {ACAD_XDICTIONARY) (360 . <Entity name: 7ffffb81620>) (102 . }) (330 . <Entity name: 7ffffbac9f0>) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . L-PLNT-TREE-CONIF) (100 . AcDbBlockReference) (66 . 1) (2 . *U3) (10 3136.18 2985.94 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0019959) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))<Selection set: 1eb>nilnil

So it looks like it sees the blocks with similar attributes, but it's not selecting them as it does with the test blocks.

Hope this helps.
Technology will save us all! *eyeroll*

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Create selection set based on picked field attributes
« Reply #7 on: August 12, 2015, 02:47:23 PM »
I am sorry , I forgot to include the dynamic , anyway I updated the codes above so try it and let me know.

jpcadconsulting

  • Newt
  • Posts: 56
Re: Create selection set based on picked field attributes
« Reply #8 on: August 12, 2015, 02:52:47 PM »
Don't apologize!  ;-)  It works great and it's going to help a great deal!

Thanks so much!!!

-JP
Technology will save us all! *eyeroll*

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Create selection set based on picked field attributes
« Reply #9 on: August 12, 2015, 02:55:23 PM »
Don't apologize!  ;-)  It works great and it's going to help a great deal!

Thanks so much!!!

-JP

Nice, you are most welcome.  :-)

jpcadconsulting

  • Newt
  • Posts: 56
Re: Create selection set based on picked field attributes
« Reply #10 on: August 18, 2015, 12:41:58 PM »
I have to tell you Tharwat,

Users at this office are writing epic songs about your LISP abilities and singing them around campfires!!! ;-)

Super useful tool.  Thanks again!
Technology will save us all! *eyeroll*

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Create selection set based on picked field attributes
« Reply #11 on: August 18, 2015, 12:59:58 PM »
Harvesting attributes & using these useful functions, one could make a fairly versatile filtering routine  :)


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Create selection set based on picked field attributes
« Reply #12 on: August 18, 2015, 01:05:57 PM »
I have to tell you Tharwat,

Users at this office are writing epic songs about your LISP abilities and singing them around campfires!!! ;-)

Super useful tool.  Thanks again!

 :-)

Thank you jpcadconsulting , for sure that gives me the honor.

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Create selection set based on picked field attributes
« Reply #13 on: August 18, 2015, 01:06:43 PM »
Harvesting attributes & using these useful functions, one could make a fairly versatile filtering routine  :)

FWIW, below are some optimisations for those functions spawned from a PM discussion with MP a couple of 4(!) years ago (which subsequently lead to this thread demonstrating a generic form of the same technique).

Code - Auto/Visual Lisp: [Select]
  1. (defun _GetVlaAtoms ( )
  2.     (eval
  3.         (list 'defun '_GetVlaAtoms '( )
  4.             (list 'quote
  5.                 (vl-sort
  6.                     (vl-remove-if-not
  7.                         (function
  8.                             (lambda ( sym )
  9.                                 (wcmatch (vl-symbol-name sym) "vla`-*")
  10.                             )
  11.                         )
  12.                         (atoms-family 0)
  13.                     )
  14.                     (function
  15.                         (lambda ( a b )
  16.                             (<
  17.                                 (vl-symbol-name a)
  18.                                 (vl-symbol-name b)
  19.                             )
  20.                         )
  21.                     )
  22.                 )
  23.             )
  24.         )
  25.     )
  26.     (_GetVlaAtoms)
  27. )
  28.  
  29. (defun _GetVlaProperties ( )
  30.     (eval
  31.         (list 'defun '_GetVlaProperties '( )
  32.             (list 'quote
  33.                 (mapcar
  34.                     (function
  35.                         (lambda ( sym )
  36.                             (substr (vl-symbol-name sym) 9)
  37.                         )
  38.                     )
  39.                     (vl-remove-if-not
  40.                         (function
  41.                             (lambda ( sym )
  42.                                 (wcmatch (strcase (vl-symbol-name sym)) "VLA`-GET`-*")
  43.                             )
  44.                         )
  45.                         (_GetVlaAtoms)
  46.                     )
  47.                 )
  48.             )
  49.         )
  50.     )
  51.     (_GetVlaProperties)
  52. )
  53.  
  54. (defun _GetVlaMethods ( )
  55.     (eval
  56.         (list 'defun '_GetVlaMethods '( )
  57.             (list 'quote
  58.                 (mapcar
  59.                     (function
  60.                         (lambda ( sym )
  61.                             (substr (vl-symbol-name sym) 5)
  62.                         )
  63.                     )
  64.                     (vl-remove-if
  65.                         (function
  66.                             (lambda ( sym )
  67.                                 (wcmatch (strcase (vl-symbol-name sym)) "VLA`-GET`-*,VLA`-PUT`-*")
  68.                             )
  69.                         )
  70.                         (_GetVlaAtoms)
  71.                     )
  72.                 )
  73.             )
  74.         )
  75.     )
  76.     (_GetVlaMethods)
  77. )
  78.  

P.S. Nice work Ron :)
« Last Edit: August 18, 2015, 01:09:45 PM by Lee Mac »

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Create selection set based on picked field attributes
« Reply #14 on: August 18, 2015, 01:57:20 PM »
Harvesting attributes & using these useful functions, one could make a fairly versatile filtering routine  :)

FWIW, below are some optimisations for those functions spawned from a PM discussion with MP a couple of 4(!) years ago (which subsequently lead to this thread demonstrating a generic form of the same technique).

Code - Auto/Visual Lisp: [Select]
  1. (defun _GetVlaAtoms ( )
  2.     (eval
  3.         (list 'defun '_GetVlaAtoms '( )
  4.             (list 'quote
  5.                 (vl-sort
  6.                     (vl-remove-if-not
  7.                         (function
  8.                             (lambda ( sym )
  9.                                 (wcmatch (vl-symbol-name sym) "vla`-*")
  10.                             )
  11.                         )
  12.                         (atoms-family 0)
  13.                     )
  14.                     (function
  15.                         (lambda ( a b )
  16.                             (<
  17.                                 (vl-symbol-name a)
  18.                                 (vl-symbol-name b)
  19.                             )
  20.                         )
  21.                     )
  22.                 )
  23.             )
  24.         )
  25.     )
  26.     (_GetVlaAtoms)
  27. )
  28.  
  29. (defun _GetVlaProperties ( )
  30.     (eval
  31.         (list 'defun '_GetVlaProperties '( )
  32.             (list 'quote
  33.                 (mapcar
  34.                     (function
  35.                         (lambda ( sym )
  36.                             (substr (vl-symbol-name sym) 9)
  37.                         )
  38.                     )
  39.                     (vl-remove-if-not
  40.                         (function
  41.                             (lambda ( sym )
  42.                                 (wcmatch (strcase (vl-symbol-name sym)) "VLA`-GET`-*")
  43.                             )
  44.                         )
  45.                         (_GetVlaAtoms)
  46.                     )
  47.                 )
  48.             )
  49.         )
  50.     )
  51.     (_GetVlaProperties)
  52. )
  53.  
  54. (defun _GetVlaMethods ( )
  55.     (eval
  56.         (list 'defun '_GetVlaMethods '( )
  57.             (list 'quote
  58.                 (mapcar
  59.                     (function
  60.                         (lambda ( sym )
  61.                             (substr (vl-symbol-name sym) 5)
  62.                         )
  63.                     )
  64.                     (vl-remove-if
  65.                         (function
  66.                             (lambda ( sym )
  67.                                 (wcmatch (strcase (vl-symbol-name sym)) "VLA`-GET`-*,VLA`-PUT`-*")
  68.                             )
  69.                         )
  70.                         (_GetVlaAtoms)
  71.                     )
  72.                 )
  73.             )
  74.         )
  75.     )
  76.     (_GetVlaMethods)
  77. )
  78.  

P.S. Nice work Ron :)
Thanks!  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC