Author Topic: Default check box in the autolisp dialog box..  (Read 1468 times)

0 Members and 1 Guest are viewing this topic.

ohmygoodboy

  • Mosquito
  • Posts: 5
Default check box in the autolisp dialog box..
« on: July 21, 2022, 03:21:52 AM »
Hi, everyone
Good to see you.
Thank you for this beautiful lesson (Please refer to the link below for related data)
But there's a function I want to add.

If I use lisp, basically the check box is unchecked, but I want all the check boxes to be checked.
Could you set the check box to SELECT ALL based on the dialog box that appears when using the lisp?
or It may be more complicated, but can it be checked at the last value?

Please take good care of me and stay healthy!
I wish you all the best in what you do
I really appreciate it.
Thank you

LISP LINK
http://www.theswamp.org/index.php?topic=7113.0;all
« Last Edit: July 21, 2022, 03:34:12 AM by ohmygoodboy »

ribarm

  • Gator
  • Posts: 3258
  • Marko Ribar, architect
Re: Default check box in the autolisp dialog box..
« Reply #1 on: July 21, 2022, 07:35:23 AM »
Tell us what issue do you have while trying to figure out solution to your problem...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ohmygoodboy

  • Mosquito
  • Posts: 5
Re: Default check box in the autolisp dialog box..
« Reply #2 on: July 21, 2022, 06:55:02 PM »
Thank you for your answer.

What I want is that when I run LISP on the link above,
I want the DIALOG box's CHECKBOX to be basically CHECK.
Previously, the CHECK box is UNCHECKED.

LISP LINK
http://www.theswamp.org/index.php?topic=7113.0;all

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
« Last Edit: July 21, 2022, 08:33:46 PM by kdub »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Default check box in the autolisp dialog box..
« Reply #4 on: July 21, 2022, 08:38:53 PM »
You need to use a set_tile Key

For toggles its 0 or 1

Code - Auto/Visual Lisp: [Select]
  1.  (setq dcl_id (load_dialog fname))
  2.   (if (not (new_dialog "ddgetxxxx" dcl_id))
  3.     (exit)
  4.   )
  5. (set_tile "t2" "1")


EDIT (John): Added code tags.
« Last Edit: July 22, 2022, 10:07:26 AM by JohnK »
A man who never made a mistake never made anything

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Default check box in the autolisp dialog box..
« Reply #5 on: July 21, 2022, 08:51:15 PM »
Hi BIGAL,

I read the goal to have the toggles  ON when the lisp loads the dialog . . . but I've been wrong before, so . . .  :|
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

ohmygoodboy

  • Mosquito
  • Posts: 5
Re: Default check box in the autolisp dialog box..
« Reply #6 on: July 21, 2022, 09:05:29 PM »
Thank you for kindly answer.
But I can't apply your advice

here is original code
where apply I the toggle or the title key?
I'm sorry and thank you.


Code - Auto/Visual Lisp: [Select]
  1. ;;;---------------------------------------------------------------------;;;
  2. ;;;  MatchAtts.lsp                                                      ;;;
  3. ;;;  Created by Will DeLoach                                            ;;;
  4. ;;;  Copyright 2005                                                     ;;;
  5. ;;;                                                                     ;;;
  6. ;;;FUNCTION                                                             ;;;
  7. ;;;Creates a variable sized dialog box with attribute tagstrings from the;;
  8. ;;;the Source Attribute.  The user selects the values they want to match;;;
  9. ;;;and then selects blocks withe same name as the source block and the  ;;;
  10. ;;;selected attributes will be changed to match the source attribute.   ;;;
  11. ;;;                                                                     ;;;
  12. ;;;USAGE                                                                ;;;
  13. ;;;(load "matchatts)                                                    ;;;
  14. ;;;matchatts                                                            ;;;
  15. ;;;                                                                     ;;;
  16. ;;;PLATFORMS                                                            ;;;
  17. ;;;Tested on 2006; but could work for earlier versions.                 ;;;
  18. ;;;                                                                     ;;;
  19. ;;;VERSION                                                              ;;;
  20. ;;; 1.0   October 3, 2005                                               ;;;
  21. ;;; 1.01  October 4, 2005   Fixed Att Selection for Attributes only.    ;;;
  22. ;;; 1.02  October 5, 2005   Fixed bug in cond statement                 ;;;
  23. ;;; 1.03  November 15, 2005   Replaced get_att SUBR (recmd by T. Willey);;;
  24. ;;; 1.1   April 6, 2006   Modifications made by CAB from theSwamp.org   ;;;
  25. ;;;                       Fixed duplicate tagname bug.                  ;;;
  26. ;;; 1.11  Added the write_line function.                                ;;;
  27. ;;; 1.2   Fixed block selection to work with Dynamic Blocks.            ;;;
  28. ;;; 1.21  Corrected an error with 'EffectiveName' assumption.           ;;;
  29. ;;;                                                                     ;;;
  30. ;;;                                                                     ;;;
  31. ;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED      ;;;
  32. ;;;   WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR   ;;;
  33. ;;;   PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.             ;;;
  34. ;;;                                                                     ;;;
  35. ;;;  You are hereby granted permission to use, copy and modify this     ;;;
  36. ;;;  software without charge, provided you do so exclusively for        ;;;
  37. ;;;  your own use or for use by others in your organization in the      ;;;
  38. ;;;  performance of their normal duties, and provided further that      ;;;
  39. ;;;  the above copyright notice appears in all copies and both that     ;;;
  40. ;;;  copyright notice and the limited warranty and restricted rights    ;;;
  41. ;;;  notice below appear in all supporting documentation.               ;;;
  42. ;;;                                                                     ;;;
  43. ;;;---------------------------------------------------------------------;;;
  44. (defun c:matchatts (/      blk
  45.  ;The entity name for the Reference Attribute
  46.                     eblk ;Entity list of blk
  47.                     atts ;List of attributes for 'blk'
  48.                     tags ;List of 'tagstrings' for atts
  49.                     keys ;List of 'handle' for atts
  50.                     vals ;List of 'textstring' for atts
  51.                     dcl_id ;Id number for the dialog box
  52.                     dcl_name ;Name for the dialog box
  53.                     strt ;Id from the done_dialog call
  54.                     lst ;List of values for the toggles
  55.                     ssa ;List of attributes the user selects
  56.                     morder ;flag to chack att order, for future use
  57.                     ename ;entity name
  58.                     lst ;List of Keys
  59.                     rname ;Reference Block Name
  60.                     i ;Increment
  61.                    )
  62. ;;;---------------------------------------------------------------------;;;
  63. ;;;A rewrite of the entsel function.                                    ;;;
  64. ;;;---------------------------------------------------------------------;;;
  65.   (defun ent_sel (msg / ent)
  66.     (while (not ent)
  67.       (cond ((setq ent (entsel msg)))
  68.             ((= (getvar "ErrNo") 7)
  69.              (princ "\nSelection missed.  Please try again.")
  70.             )
  71.             ((= (getvar "ErrNo") 52) (exit))
  72.       )
  73.     )
  74.     ent
  75.   )
  76. ;;;---------------------------------------------------------------------;;;
  77. ;;;This is a utility function to return Attribute References for the    ;;;
  78. ;;;supplied object or entity name.                                      ;;;
  79. ;;;---------------------------------------------------------------------;;;
  80.   (defun get_atts (obj)
  81.     (vlax-invoke (vlax-ename->vla-object obj) 'getattributes)
  82.   )
  83. ;;;---------------------------------------------------------------------;;;
  84. ;;;This creates a variable dialog box that changes size based on how    ;;;
  85. ;;;many attributes are passed to it.  The dialog box is temporary and is;;;
  86. ;;;created on the fly.  It is stored in your Acad Temp path location.   ;;;
  87. ;;;---------------------------------------------------------------------;;;
  88.   (defun createdialog (lst keys / num tfn fn wid cnt str)
  89.     (defun write_line (lst file) (foreach x lst (write-line x file)))
  90.     (setq num (length tags))
  91.     (cond ((> num 24) (setq wid 4))
  92.           ((> num 12) (setq wid 3))
  93.           ((> num 6) (setq wid 2))
  94.           (T (setq wid 1))
  95.     )
  96.     (setq tfn (vl-filename-mktemp "match_attribute_value.dcl"))
  97.     (setq fn (open tfn "w"))
  98.     (write_line
  99.       (list
  100.         "temp : dialog { label = \"Match Attributes\";"
  101.         ": boxed_column { label = \"Select Attributes Values to Match: \";"
  102.         ": row {"
  103.       )
  104.       fn
  105.     )
  106.     (setq cnt 0)
  107.     (repeat (1+ wid)
  108.       (write-line ": column {" fn)
  109.       (repeat (/ num wid)
  110.         (if (setq str (nth cnt lst))
  111.           (progn (write-line
  112.                    (strcat ": toggle { label = "
  113.                            "\""
  114.                            str
  115.                            "\""
  116.                            "; key = "
  117.                            "\""
  118.                            (nth cnt keys)
  119.                            "\""
  120.                            ";}"
  121.                    )
  122.                    fn
  123.                  )
  124.                  (setq cnt (1+ cnt))
  125.           )
  126.         )
  127.       )
  128.       (write-line "}" fn)
  129.     )
  130.     (write_line
  131.       (list
  132.         "}"
  133.         "spacer_1;"
  134.         " : toggle { key = \"All\"; label = \"Select All\";}"
  135.         "}"
  136.         "ok_cancel;"
  137.         "}"
  138.        )
  139.       fn
  140.     )
  141.     (close fn)
  142.     tfn
  143.   )
  144. ;;;---------------------------------------------------------------------;;;
  145. ;;;This is the action for 'Select All' Check Box.                       ;;;
  146. ;;;---------------------------------------------------------------------;;;
  147.   (defun on_all_pick (lst / str)
  148.     (if (eq (get_tile "All") "0")
  149.       (setq str "0")
  150.       (setq str "1")
  151.     )
  152.     (mapcar '(lambda (x) (set_tile x str)) lst)
  153.   )
  154. ;;;---------------------------------------------------------------------;;;
  155. ;;;This takes two lists and compares the two.  Every item in vals that  ;;;
  156. ;;;equals "1" is replace with the corresponding item in objs.           ;;;
  157. ;;;---------------------------------------------------------------------;;;
  158. ;;; CAB modified, create a list of pairs (tagname flag)  where flag 1 0 t/nil
  159.   (defun create_list (vals objs)
  160.     (vl-remove nil
  161.                (mapcar '(lambda (x y)
  162.                           (cons y
  163.                                 (if (eq x "1")
  164.                                   1
  165.                                   0
  166.                                 )
  167.                           )
  168.                         )
  169.                        vals
  170.                        objs
  171.                )
  172.     )
  173.   )
  174. ;;;---------------------------------------------------------------------;;;
  175. ;;;Receives a Selection Set and returns Entity Names                    ;;;
  176. ;;;---------------------------------------------------------------------;;;
  177.   (defun ssnames (selection_set / num lst)
  178.     (repeat (setq num (sslength selection_set))
  179.       (setq num (1- num)
  180.             lst (cons (ssname selection_set num) lst)
  181.       )
  182.     )
  183.     lst
  184.   )
  185. ;;;---------------------------------------------------------------------;;;
  186. ;;;Accepts a Group code and an Entity List and returns the value.       ;;;
  187. ;;;---------------------------------------------------------------------;;;
  188.   (defun dxf (gcode elist) (cdr (assoc gcode elist)))
  189. ;;;---------------------------------------------------------------------;;;
  190. ;;;---------------------------------------------------------------------;;;
  191. ;;;---------------------------------------------------------------------;;;
  192. ;;;Main program starts here.
  193.   (while (not blk)
  194.     (setq blk (car (ent_sel "\nSelect Source Object:  ")))
  195.     (cond ((not (setq eblk (entget blk))))
  196.           ((not (eq (dxf 0 eblk) "INSERT"))
  197.            (setq blk nil)
  198.            (princ "\nPlease select a block with attributes. ")
  199.           )
  200.           ((not (eq (dxf 66 eblk) 1))
  201.            (setq blk nil)
  202.            (princ "\nPlease select a block with attributes. ")
  203.           )
  204.           (T blk)
  205.     )
  206.   )
  207.   (setq atts (get_atts blk)
  208.         tags (mapcar 'vla-get-tagstring atts)
  209.         keys (mapcar 'vla-get-handle atts)
  210.         vals (mapcar 'vla-get-textstring atts)
  211.   )
  212.   (setvar "ErrNo" 0)
  213.   (and ; Creates a temporary dialog box with toggles for each
  214.  ; of the tagstrings in tags.  This is a variable dialog
  215.  ; box that changes size based on the number of attributes.
  216.     (setq dcl_name (createdialog tags keys)) ; Loads the dialog box
  217.     (> (setq dcl_id (load_dialog dcl_name)) 0)
  218.     (new_dialog "temp" dcl_id)
  219.  ; If any toggle other than 'Select All' is pressed then
  220.  ; this will turn off the 'Select All' toggle.
  221.     (mapcar '(lambda (x) (action_tile x "(set_tile \"All\" \"0\")"))
  222.             keys
  223.     )
  224.     (action_tile "All" "(on_all_pick keys)")
  225.     (action_tile "cancel" "(done_dialog 0)")
  226.       "accept"
  227.       "(setq lst (mapcar '(lambda (x)(get_tile x)) keys))(done_dialog 1)"
  228.       ;;  CAB removed morder code
  229.       ;; "(setq morder (= (get_tile \"morder\") \"1\")lst (mapcar '(lambda (x)(get_tile x)) keys))(done_dialog 1)"
  230.     )
  231.     ;;  (set_tile "morder" "1")
  232.     (setq strt (start_dialog))
  233.     (not (unload_dialog dcl_id))
  234.     (vl-file-delete dcl_name)
  235.     (setq morder t) ; overridefor now, keep for future use
  236.     (if (eq strt 1)
  237.       (and ; creates a list of attribute objects from the
  238.  ; reference object that were selected in the dialog box.
  239.         ;;  CAB start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  240.         ;;  replace the attriburtes in one insert
  241.         ;;  if morder is true the tag and the order in the list must match
  242.         ;;  else the first matching tag will get the new value
  243.         (defun replaceatts (ent atlst tags vals / blkobj cnt idx)
  244.           (setq blkobj (vlax-ename->vla-object ent)
  245.                 cnt    0
  246.           )
  247.           (foreach atto (vlax-invoke blkobj 'getattributes)
  248.             (cond
  249.               ((and morder ; order must match
  250.                     (= 1 (cdr (nth cnt atlst))) ; flag, ok to replace
  251.                     (eq (vla-get-tagstring atto) (nth cnt tags))
  252.                )
  253.                (vla-put-textstring atto (nth cnt vals))
  254.               )
  255.               ((and
  256.                  (not morder) ; ignore order
  257.                  (= 1 (cdr (nth cnt atlst))) ; flag, ok to replace
  258.                  (setq idx (vl-position (vla-get-tagstring atto) tags))
  259.                )
  260.                (vla-put-textstring atto (nth idx vals))
  261.               )
  262.             )
  263.             (setq cnt (1+ cnt))
  264.           )
  265.           (vla-update blkobj)
  266.         )
  267.         ;; CAB - a list of pairs (tagname flag)  where flag 1 0 t/nil
  268.         (setq atts (create_list lst atts))
  269.         (not
  270.           (prompt
  271.             "\nSelect blocks to update or enter ALL for all matching blocks."
  272.           )
  273.         )
  274.         (if
  275.           (and
  276.             (setq ssa (ssget (list '(0 . "INSERT") '(66 . 1))))
  277.             (setq rname (vlax-ename->vla-object blk))
  278.             (if (vlax-property-available-p rname 'effectivename)
  279.               (progn (setq rname (vla-get-effectivename rname))
  280.                      (mapcar '(lambda (x)
  281.                                 (if (/= rname
  282.                                         (vla-get-effectivename
  283.                                           (vlax-ename->vla-object x)
  284.                                         )
  285.                                     )
  286.                                   (ssdel x ssa)
  287.                                 )
  288.                               )
  289.                              (ssnames ssa)
  290.                      )
  291.               )
  292.               (progn
  293.                 (setq rname (vla-get-name rname))
  294.                 (mapcar
  295.                   '(lambda (x)
  296.                      (if (/= rname
  297.                              (vla-get-name (vlax-ename->vla-object x))
  298.                          )
  299.                        (ssdel x ssa)
  300.                      )
  301.                    )
  302.                   (ssnames ssa)
  303.                 )
  304.               )
  305.             )
  306.           )
  307.            (progn ;  itterate through the selected inserts
  308.              (setq i -1)
  309.              (while (setq ename (ssname ssa (setq i (1+ i))))
  310.                (if (not (eq ename blk)) ; ignore doner block
  311.                  (replaceatts ename atts tags vals)
  312.                )
  313.              )
  314.              (if (= 0 (sslength ssa)) ;(not ssa);(null ssa)
  315.                (princ "\nInvalid blocks selected.  Please start over. ")
  316.              )
  317.            )
  318.         )
  319.         ;;  CAB end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  320.       ) ; This is returned if the user hits Cancel.
  321.       (princ "\nFunction Terminated by User!")
  322.     )
  323.   )
  324.   (princ)
  325. )


EDIT (John): Added code tags.
« Last Edit: July 22, 2022, 10:06:49 AM by JohnK »

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Default check box in the autolisp dialog box..
« Reply #7 on: July 22, 2022, 04:56:25 PM »
The code posted  will not build the dialog as shown in the first post, so it's a bit of a guessing game.

This modification should change the "All' key value to ON :
Code - Auto/Visual Lisp: [Select]
  1.     (write_line
  2.       (list
  3.         "}"
  4.         "spacer_1;"
  5.        ;;  replaced ** [s]" : toggle { key = \"All\"; label = \"Select All\";}"[/s]
  6.         " : toggle { key = \"All\"; label = \"Select All\"; value = \"1\"; }"
  7.         "}"
  8.         "ok_cancel;"
  9.         "}"
  10.        )
  11.       fn
  12.     )
  13.  
  14.  
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Default check box in the autolisp dialog box..
« Reply #8 on: July 22, 2022, 10:02:44 PM »
Look at this also using set_tile 0 or 1 needed.

(mapcar '(lambda (x) (action_tile x "(set_tile \"All\" \"0\")"))
            keys
    )
A man who never made a mistake never made anything

ohmygoodboy

  • Mosquito
  • Posts: 5
Re: Default check box in the autolisp dialog box..
« Reply #9 on: July 24, 2022, 07:02:57 PM »
When I applied the code you told me, the check box was checked as I asked you.
Thank you.

But lisp doesn't work.
It's really difficult.

thank you so much!!

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Default check box in the autolisp dialog box..
« Reply #10 on: July 24, 2022, 10:07:58 PM »
Had another look at code if your just trying to pick attributes in a block then match attributes in same name block that you select. It does not need dcl and can be done in a simpler manner using Nentsel to pick source attributes. 1 -> how many.

Can you confirm that is what your trying to do. The code maybe does more options.
A man who never made a mistake never made anything

Donix

  • Mosquito
  • Posts: 1
Re: Default check box in the autolisp dialog box..
« Reply #11 on: December 13, 2022, 10:27:26 AM »
Hello!

first of all:
Your LISP is a frickin GEM!

Can u help me how to use this between different named dynamic blocks? :smitten:
Now it works with the similar named blocks but i wonder if it could work between two different block.