Jump to content

List Box with Filter (Attributes values)


jr.roberto.santos

Recommended Posts

List Box with Filter | Lee Mac Programming (lee-mac.com)

http://www.lee-mac.com/filtlistbox.html

 

 

Dear
I would like a help to list the values of the attributes.

Is that possible?

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Example: DWG with...:

Block1:

AttributeX

Value: Item 1

AttributeX

Value: Item 2

AttributeX

Value: Item 3

.

.

.

 

Select an Item:

Item 1

Item 2

Item 3

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

 

Best Regards

 

image.png.084fe82a52f464ae852dd18c869b6de5.png

Link to comment
Share on other sites

This will make a list of the attributes in a block. You can use this list in the Lee-mac code.

 

(setq obj (vlax-ename->vla-object (car  (entsel "Pick blk"))))
(setq atts (vlax-invoke obj 'Getattributes))
(setq lst '())
(foreach att atts
(setq lst (cons (vla-get-textstring att) lst))
)

 

  • Like 2
Link to comment
Share on other sites

On 5/27/2022 at 5:21 PM, BIGAL said:

This will make a list of the attributes in a block. You can use this list in the Lee-mac code.

 

(setq obj (vlax-ename->vla-object (car  (entsel "Pick blk"))))
(setq atts (vlax-invoke obj 'Getattributes))
(setq lst '())
(foreach att atts
(setq lst (cons (vla-get-textstring att) lst))
)

 

Dear @BIGAL Thanks for the return.

 

I used the @Lee Mac sample code.

Works well for the layers but I'd like to list the attributes.

 

 

;;;;;;;;

(defun c:test ( / def lst )
    (while (setq def (tblnext "layer" (not def)))
        (setq lst (cons (cdr (assoc 2 def)) lst))
    )
    (LM:filtlistbox "Select a Layer" (acad_strlsort lst) t)
)

;;;;;

 

 

Best regards.

 

Link to comment
Share on other sites

32 minutes ago, jr.roberto.santos said:

Dear @BIGAL Thanks for the return.

 

I used the @Lee Mac sample code.

Works well for the layers but I'd like to list the attributes.

 

 

;;;;;;;;

(defun c:test ( / def lst )
    (while (setq def (tblnext "layer" (not def)))
        (setq lst (cons (cdr (assoc 2 def)) lst))
    )
    (LM:filtlistbox "Select a Layer" (acad_strlsort lst) t)
)

;;;;;

 

 

Best regards.

 

 

 

BIGAL has already given you the answer. did you try it?

 

(defun c:test ( / lst atts obj )
  (setq obj (vlax-ename->vla-object (car  (entsel "Pick blk"))))
  (setq atts (vlax-invoke obj 'Getattributes))
  (setq lst '())
  (foreach att atts
    (setq lst (cons (vla-get-textstring att) lst))
  )
  (LM:filtlistbox "Select a Layer" (acad_strlsort lst) t)
)

;; Filtered List Box  -  Lee Mac
;; Displays a list box interface from which the user may select one or more items.
;; Includes an edit box filter to enable the user to filter the displayed list of items.
;; msg - [str] List box dialog title
;; lst - [lst] List of strings to display in the list box
;; mtp - [bol] T=Allow multiple items; nil=Single item selection
;; Returns: [lst] List of selected items, else nil

(defun LM:filtlistbox ( msg lst mtp / _addlist dch dcl des rtn sel tmp )

    (defun _addlist ( key lst )
        (start_list key)
        (foreach x lst (add_list x))
        (end_list)
        lst
    )

    (if
        (and
            (setq dcl (vl-filename-mktemp nil nil ".dcl"))
            (setq des (open dcl "w"))
            (write-line
                (strcat
                    "filtlistbox : dialog { label = \"" msg "\"; spacer;"
                    ": list_box { key = \"lst\"; width = 50; fixed_width = true; height = 15; fixed_height = true; allow_accept = true; "
                    "multiple_select = " (if mtp "true" "false") "; }"
                    ": edit_box { key = \"flt\"; width = 50; fixed_width = true; label = \"Filter:\"; }"
                    "spacer; ok_cancel; }"
                )
                des
            )
            (not (close des))
            (< 0 (setq dch (load_dialog dcl)))
            (new_dialog "filtlistbox" dch)
        )
        (progn
            (_addlist "lst" (setq tmp lst))
            (set_tile "lst" (setq rtn "0"))
            (set_tile "flt" "*")
            (action_tile "lst" "(setq rtn $value)")
            (action_tile "flt"
                (vl-prin1-to-string
                   '(progn
                        (setq flt (strcat "*" (strcase $value) "*")
                              sel (mapcar '(lambda ( n ) (nth n tmp)) (read (strcat "(" rtn ")")))
                        )
                        (_addlist "lst" (setq tmp (vl-remove-if-not '(lambda ( x ) (wcmatch (strcase x) flt)) lst)))
                        (set_tile "lst"
                            (setq rtn
                                (vl-string-trim "()"
                                    (vl-princ-to-string
                                        (cond
                                            (   (vl-sort (vl-remove nil (mapcar '(lambda ( x ) (vl-position x tmp)) sel)) '<))
                                            (  '(0)   )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
            (setq rtn
                (if (= 1 (start_dialog))
                    (mapcar '(lambda ( x ) (nth x tmp)) (read (strcat "(" rtn ")")))
                )
            )
        )
    )
    (if (< 0 dch)
        (setq dch (unload_dialog dch))
    )
    (if (and (= 'str (type dcl)) (findfile dcl))
        (vl-file-delete dcl)
    )
    rtn
)

 

Link to comment
Share on other sites

 

@BIGAL

Yes you had already responded using the "Pick blk" for a single block.

In this example, I'm trying to select all blocks and filter only the non-duplicate "MFG" attribute.

 

Please find the attached file.

 

Best regards.

 

image.thumb.png.26f1d407c482a6f9c7c0740f3fd325af.png

SAMPLE.dwg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...