DCL List from Image Button

DCL List from Image Button

tcoley95E9Z
Enthusiast Enthusiast
4,677 Views
33 Replies
Message 1 of 34

DCL List from Image Button

tcoley95E9Z
Enthusiast
Enthusiast

Hello all,

 

I am working on a lsp that has a quick library for our day to day block design (we constantly result in many file paths to get to these so this would save a lot of time). The issue I am running across, however is when I select an image tile, I want to have a list populated of the blocks in that category. See image below for current DCL layout.

tcoley95E9Z_0-1707751303660.png

Temp has no function for now and I plan on keeping it that way

(Yes I know its messy right now.. just a draft)

 

This is my lisp code.

 

 

defun c:BTools (/ Dcl_Id% Folder$ Slides@ Slide1$ Slide2$ Slide3$ Slide4$ Return$ X# Y#)
  
  (princ "\nBTOOLS")(princ)
  
  ; Set Default Variables
  (setq Slides@ (list nil "Block Design" "Paper Space" "Plumbing" "WIP") ;; NAME OF THE .SLD FILE
        Slide1$ (nth 1 Slides@)
        Slide2$ (nth 2 Slides@)
        Slide3$ (nth 3 Slides@)
        Slide4$ (nth 4 Slides@)
        Folder$ "C:\\...\\...\\Documents\\"
        Return$ ""
  );setq
  
  ; Load Dialog
  (setq Dcl_Id% (load_dialog "MyDialogs.dcl"))
  (new_dialog "MySlideImages" Dcl_Id%)
  
  ; Set Dialog Initial Settings
  (set_tile "Title" " BTOOLS - TOOLS FOR DRAFTING")
  (set_tile "Text1" Slide1$)
  (set_tile "Text2" Slide2$)
  (set_tile "Text3" Slide3$)
  (set_tile "Text4" Slide4$)
  
  ; Adjust X# and Y# per image_buttom outline to fit slide_image
  (start_image "Slide1")(setq X# (- (dimx_tile "Slide1") 2))
  (setq Y# (- (dimy_tile "Slide1") 2))(end_image)
  (start_image "Slide1")(slide_image -5 -4 X# Y# (strcat Folder$ Slide1$))(end_image)
  (start_image "Slide2")(slide_image 1 1 X# Y# (strcat Folder$ Slide2$))(end_image)
  (start_image "Slide3")(slide_image 1 1 X# Y# (strcat Folder$ Slide3$))(end_image)
  (start_image "Slide4")(slide_image 1 1 X# Y# (strcat Folder$ Slide4$))(end_image)
  
  ; Dialog Actions
  (action_tile "Slide1" "(setq Return$ Slide1$)")
  (action_tile "Slide2" "(setq Return$ Slide2$)")
  (action_tile "Slide3" "(setq Return$ Slide3$)")
  (action_tile "Slide4" "(setq Return$ Slide4$)")
  (start_dialog)
  
  ; Unload Dialog
  (unload_dialog Dcl_Id%)
  (princ (strcat "\n" Return$))
  (princ)
  
)

 

 

 

0 Likes
4,678 Views
33 Replies
Replies (33)
Message 2 of 34

paullimapa
Mentor
Mentor

Looks like a good start. Please also post your dcl so will know list box key

Questions:

Where’s location of blocks?

Hopefully they’re in separate folders under:

"C:\\...\\...\\Documents\\"

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 34

tcoley95E9Z
Enthusiast
Enthusiast

Blocks location are currently in that folder path you listed.

 

Here is the DCL.. It's pretty messy right now, cleanup for me is fine I'd just rather be able to get this problem solved before cleaning it up

 

MySlideImages : dialog {

  key = "Title";
  width = 60;
  height = 25;
  label = "";//Title$ from lsp file


// Where images go
  : boxed_column{
    key = "lst1";
    label = "Category";
    : column {
      : row {
        : image_button {
          key = "Slide1";
          width = 17.26;
          height = 5.28;
          aspect_ratio = 1;
          color = -2;
        }
        : image_button {
          key = "Slide2";
          width = 17.26;
          height = 5.28;
          aspect_ratio = 1;
          color = -2;
        }
        : image_button {
          key = "Slide3";
          width = 17.26;
          height = 5.28;
          aspect_ratio = 1;
          color = -2;
        }
        // : image_button {
        //   key = "Slide4";
        //   width = 17.26;
        //   height = 5.28;
        //   aspect_ratio = 1;
        //   color = -2;
        // }
      } //Top images

      : row {
        : column {
          : text {
            key = "Text1";
            label = "";//Text1$ from lsp file
            width = 17.26;
            fixed_width = true;
            alignment = centered;
          }
        }
        : column {
          : text {
            key = "Text2";
            label = "";//Text2$ from lsp file
            width = 17.26;
            fixed_width = true;
            alignment = centered;
          }
        }
        : column {
          : text {
            key = "Text3";
            label = "";//Text3$ from lsp file
            width = 17.26;
            fixed_width = true;
            alignment = centered;
          }
        }
      } //Top text callouts
    }
  }

  : row{
        :boxed_column {
          key = "lst2";
          label = "Type";
          : list_box {
            width = 25;
            height = 10;
          }
        }

         : column{
          : boxed_column{
            label = " Temp ";
          }
          spacer;
          : row{
            ok_cancel;
          } 
        }
        
  }
}

 

0 Likes
Message 4 of 34

paullimapa
Mentor
Mentor

Thanks for sharing your dcl. I can see now your list box key

key = "lst2"

Now I’m assuming when you say blocks these are individual drawings. It would be a lot easier if each categories of blocks are in their separate subfolders. Now when you click on the slide then the action callback can run the vl-directory-files function to get a list of dwgs in a specifed folder which returns a list for you to populate the list box

https://help.autodesk.com/view/OARX/2024/PTB/?guid=GUID-C28C0CB0-FBBE-4AA8-BAC4-2FF222772514


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 34

tcoley95E9Z
Enthusiast
Enthusiast
Thanks! I'll give it a try here soon and update you on it.
0 Likes
Message 6 of 34

paullimapa
Mentor
Mentor

Great then you can use the functions shown here to populate:

"lst2"

https://help.autodesk.com/view/ACDLT/2024/ENU/?guid=GUID-9C5213CA-B349-4F08-A6B8-960BC3BCFC84


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

tcoley95E9Z
Enthusiast
Enthusiast
Hey I'm really new to handling Image Buttons.. how do I have my image button be updated the second someone were to click on it.. not clicking on it then hitting 'ok'?
0 Likes
Message 8 of 34

tcoley95E9Z
Enthusiast
Enthusiast
^^^^ My biggest issue right now is I am able to store a variable for the selected image title but only after I click "OK".
This part of the code: "(princ (strcat "\n" Return$))" (Line 43)
But I want this variable to be updated when I just simply click on an image tile, not click THEN click OK. Then I would be able to have my list be populated utilizing vl-directory-files.

Thanks
0 Likes
Message 9 of 34

paullimapa
Mentor
Mentor

I'm not sure I understand what you're saying.

I thought your idea was to have the 3 images representing the 3 categories up top and those images don't change but they're just representational. Then when one of those categories are selected the list box will then show all the drawings for that category for selection and maybe when a drawing is selected and OK button is clicked then it'll Insert that block into the current drawing.

paullimapa_0-1707773941745.png

But if you want to select the Block in the list box and then have the slide image to now show a preview of that Block that cannot be done. You would have to first open up each drawing/Block & make a slide of the drawing/Block and then include in the code to update the slide to now show at top. You might as well use the built-in Design Center DC app to do this:

paullimapa_1-1707774577647.png

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 10 of 34

tcoley95E9Z
Enthusiast
Enthusiast
I apologize for any confusion.. yes the first image is correct. They are just categories for different blocks in each respective subfolder named "Block Design" "Paper Space" and "Plumbing". I just dont know how to have the list of blocks in the subfolders instantly populate when I click one of the categories.. not after I click THEN press okay.. does that make sense? Sorry its a bit confusing lol
0 Likes
Message 11 of 34

paullimapa
Mentor
Mentor

What made you thought of only storing the variable Return$ in the action call back:

(action_tile "Slide1" "(setq Return$ Slide1$)")

Now that you know about the vl-directory-files function why don't you just define a function that calls vl-directory-files based on the slide image selected to list the drawings in that category like I mentioned which returns a list for you to then populate the list box:

(action_tile "Slide1" "(do_listbox $key)")

So now when "Slide1" is selected a separate function defined as do_listbox runs. The $key which = "Slide1" is passed as an argument so the do_listbox function will know which directory to return the list:

; do_listbox
; Argument:
; slide-category = folder location to list blocks
; Returns:
; list of drawings in that folder location
(defun do_listbox (slide-category)
 (cond
   ((eq slide-category "Slide1")
     (vl-directory-files (strcat Folder$ Slide1$) "*.dwg")
   )
   ((eq slide-category "Slide2")
     (vl-directory-files (strcat Folder$ Slide2$) "*.dwg")
   )
   ((eq slide-category "Slide3")
     (vl-directory-files (strcat Folder$ Slide3$) "*.dwg")
   )
   ((eq slide-category "Slide4")
     (vl-directory-files (strcat Folder$ Slide4$) "*.dwg")
   )
 )
; return result as a list of drawings
)

 In 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 34

paullimapa
Mentor
Mentor

actually to make it even easier just change the following action calls from:

 

  ; Dialog Actions
  (action_tile "Slide1" "(setq Return$ Slide1$)")
  (action_tile "Slide2" "(setq Return$ Slide2$)")
  (action_tile "Slide3" "(setq Return$ Slide3$)")
  (action_tile "Slide4" "(setq Return$ Slide4$)")

 

to this:

 

  ; Dialog Actions
  (action_tile "Slide1" "(setq filelist(vl-directory-files (strcat Folder$ Slide1$) \"*.dwg\"))")
  (action_tile "Slide2" "(setq filelist(vl-directory-files (strcat Folder$ Slide2$) \"*.dwg\"))")
  (action_tile "Slide3" "(setq filelist(vl-directory-files (strcat Folder$ Slide3$) \"*.dwg\"))")
  (action_tile "Slide4" "(setq filelist(vl-directory-files (strcat Folder$ Slide4$) \"*.dwg\"))")

 

Now you can even include following the vl-directory files function call with the function I posted earlier on populating the list box...see if you can figure how to do that


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 13 of 34

paullimapa
Mentor
Mentor

just looked a little bit closer at your dcl for your list box:

 

        :boxed_column {
          key = "lst2";
          label = "Type";
          : list_box {
            width = 25;
            height = 10;
          }
        }

 

The key is in the wrong position. It should be placed under the list_box like this:

 

        :boxed_column {
          label = "Type";
          : list_box {
            key = "lst2";
            width = 25;
            height = 10;
          }
        }

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 14 of 34

tcoley95E9Z
Enthusiast
Enthusiast
Hey Paul,
I really appreciate your patience with me through this. I tried implementing that above function and it does return the files but only after I press 'OK'. I am pretty lost in having the list_box automatically populate when one image_button is simply pressed once.
0 Likes
Message 15 of 34

paullimapa
Mentor
Mentor

take a look at what I did with the attached.

1. I changed location of My Documents so not sure if that matches yours:

;        Folder$ "C:\\...\\...\\Documents\\"
        Folder$ (strcat(getenv"userprofile")"\\Documents\\")

I added this function which populates the list box with the filelist:

; do_lstbox populates list box with filelist & select first item
 (defun do_lstbox ()
  (start_list "lst2" 3)    ; Start population of the list box 
  (mapcar 'add_list filelist) ; add items from the list
  (end_list)               ; end population
  (setq selection "0")     ; set default selection value
  (set_tile "lst2" selection) ; highlight first item in list box
 )  

These are the actions I'm using when you click on the dcl:

; Dialog Actions
  (action_tile "Slide1" "(setq filelist(vl-directory-files (setq Return$ (strcat Folder$ Slide1$)) \"*.dwg\"))(do_lstbox)")
  (action_tile "Slide2" "(setq filelist(vl-directory-files (setq Return$ (strcat Folder$ Slide2$)) \"*.dwg\"))(do_lstbox)")
  (action_tile "Slide3" "(setq filelist(vl-directory-files (setq Return$ (strcat Folder$ Slide3$)) \"*.dwg\"))(do_lstbox)")
  (action_tile "Slide4" "(setq filelist(vl-directory-files (setq Return$ (strcat Folder$ Slide4$)) \"*.dwg\"))(do_lstbox)")
  (action_tile "accept" "(setq selection (get_tile \"lst2\"))(done_dialog 1)") ; get latest item selected in list box then close dcl
  (action_tile "cancel" "(done_dialog 0)") ; cancel dcl

When the dialog starts I also added this variable:

; Start dialog
  (setq stid (start_dialog)) 

This way when the dialog closes I can check what to do:

; check if accept or cancel button selected to close dialog
  (if(not (zerop stid)) 
    (progn ; then ok button selected
     (setq blkfile (strcat Return$ "\\" (nth (atoi selection) filelist)))
     (alert(strcat"Item Selected is: " selection "\nBlock File is " blkfile))
    )
    ; else cancel button selected
    (alert"Function Cancelled")
  )

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 16 of 34

tcoley95E9Z
Enthusiast
Enthusiast
Thanks! I think the issue I'm arriving at right now is that within my documents folder, I have subfolders that are named the same as each category (Block Design folder, Paper Space folder, etc.) because I don't want all the blocks to show up at once, just the ones in the category. How would I be able to have the filelist show these subfolders? For example, if I hit 'Block Design' I would want to list all the blocks in
"C:\...\Documents\Block Design"
0 Likes
Message 17 of 34

paullimapa
Mentor
Mentor

That’s what the code I posted would do 

For example 

"(setq filelist(vl-directory-files (setq Return$ (strcat Folder$ Slide1$)) \"*.dwg\"))

This only shows dwg files under that folder


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 18 of 34

tcoley95E9Z
Enthusiast
Enthusiast

Huh thats weird.. It doesnt populate for me. Here is my folder structure if this helps.

Ignore 'Paper Space2' it is not being used.

tcoley95E9Z_0-1707841935011.png

 

0 Likes
Message 19 of 34

tcoley95E9Z
Enthusiast
Enthusiast
Never mind It populated! I have no clue why it didnt at first. Thank you so much Paul!
0 Likes
Message 20 of 34

paullimapa
Mentor
Mentor

glad that it finally worked for you...now if you want this to work for everyone in the office you'll have to change the folder locations to a common area where those library of drawings reside...cheers!!!


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