selecting images using DCL

selecting images using DCL

Homecad2007
Enthusiast Enthusiast
4,172 Views
16 Replies
Message 1 of 17

selecting images using DCL

Homecad2007
Enthusiast
Enthusiast

I have this lisp routine that I am able to pick an item by selecting a name and I have slide images of the what they look like.  I would like to make improvements so that I can pick the image and by picking the image it inserts the appropriate text.  I have tried some examples that others have posted but can seem to apply it to this lisp routine

 

Thanks in advance

Tony

0 Likes
4,173 Views
16 Replies
Replies (16)
Message 2 of 17

john.uhden
Mentor
Mentor

Change your 'image' tiles to 'image_button' tiles and then have an action associated with each tile name.

I have a SPOTLBL routine that provides both a textual list of options and a slide image of each option, so if you pick one it highlights the matching tile or list item.

John F. Uhden

0 Likes
Message 3 of 17

Homecad2007
Enthusiast
Enthusiast

ok the image button was straightforward but now how to associate to each tile name.

 

btw cant seem to connect to your SPOTLBL routine example

0 Likes
Message 4 of 17

john.uhden
Mentor
Mentor

In the following image you can see the list of options on the left and the corresponding array of image_buttons on the right.

 

SpotLBL.jpg

Just like your code, each image_button has a unique name, so after you invoke your DCL, use

(action_tile "image_1" "(do_something 1)") ;; where do_something is your function that takes one argument being the integer for the image ID.

(action_tile "image_2" "(do_something 2)") etc.

Now notice the red border around the selected image_button. You can do that with this tiny gift...

   (defun do_something (|n / |n |tile |x |y |x0 |y0 |color |hl)
      (if (/= |slstyle |n)
         (progn
            (set_tile "slist" (setq |slstyle |n))
            (foreach |n |nlist
               (setq |tile (strcat "sl" |n)
                     |x (1- (dimx_tile |tile))
                     |y (1- (dimy_tile |tile))
                     |x0 0 |y0 0
               )
               (if (= |n |slstyle)
                  (setq |color -18 |hl 1)
                  (setq |color 0 |hl 0)
               )
               (start_image |tile)
               (repeat 4
                  (vector_image |x0 |y0 |x |y0 |color)
                  (vector_image |x |y0 |x |y |color)
                  (vector_image |x |y |x0 |y |color)
                  (vector_image |x0 |y |x0 |y0 |color)
                  (setq |x0 (1+ |x0) |y0 (1+ |y0) |x (1- |x) |y (1- |y) |color |hl)
               )
               (end_image)
            )
         )
      )
   )

which relates the image_button picked to the list_box I call "slist" and the variable I call |slstyle

AND clears the red border around the previously highlighted image_button

AND draws a red border around the selected one.

All that because I wanted the user to have visual confirmation of his pick.

The only difference between yours and mine is that I named my buttons "sl1" sl2" etc.

BTW, the pipe symbol prefix "|" I used is from the days when local symbols weren't really local at all, so I made sure they each had unique names so I could set them to nil on program exit.

John F. Uhden

0 Likes
Message 5 of 17

Sea-Haven
Mentor
Mentor

In your lips you set a list of names so if the slides match that name no need to do the code like 16 times use a foreach and repeat the 4 lines.

(setq x 1)
(foreach sldname names
(setq imno (strcat "im" (rtos x 2 0)))
(setq w (dimx_tile imno) h (dimy_tile imno));get image tile width and height
  (start_image imno)	  ;start the image
  (slide_image 0 0 w h (strcat "c:\\hsbdetails\\Lisp\\slides\\" sldname))  ;display a slide
  (end_image)  ;end image
(setq x (+ x 1))
)

This is an example of a 3x3 dcl 

 

;;;               Uses DD3X3.DCL for the dialogue definition.  The
;;;               slide images are in list ai_pts_lst.120

; ctone is slb library name (tlds) is slide name in library
; use individual slide name if no library
(setq ai_pts_lst '("ctone(TLDS)" "ctone(dsdn)" "ctone(trds)"
                   "ctone(dsr)" "ca3blank" "ctone(DSL)"
                   "ctone(blds)" "ctone(dsup)" "ctone(brds)")
)


(setq ai_pts_lst2 '("33sq1" "33sq2" "33sq3" "33sq4" "33sq5" "33sq6""33sq7" "33sq8" "33sq9" ))

(defun sq_pick ()
  (cond 
    ((= ans "33sq1")(setq ang1 4.7125)(setq ang2 0.0)(tr))
    ((= ans "33sq2")(tm))
    ((= ans "33sq3")(setq ang1 3.1417)(setq ang2 4.7125)(tr))
    ((= ans "33sq4")(tm))
    ((= ans "33sq5")(princ "run other clean up"))
    ((= ans "33sq6")(tm))
    ((= ans "33sq7")(setq ang1 1.5708)(setq ang2 0.0)(tr))
    ((= ans "33sq8")(tm))
    ((= ans "33sq9")(setq ang1 1.5708)(setq ang2 3.1417)(tr))
    )
)

; calculates next slide
(defun alan4 ()
(setq x (+ x 1))
(setq sldname (nth x ai_pts_lst))
)

; third step
; set up slide libraray 
(defun ai_ptype_start ()
  (setq x -1)
  (foreach pts0 ai_pts_lst2
      (alan4)
      (start_image pts0)
      (slide_image 0 0 (- (dimx_tile pts0) 1) (- (dimy_tile pts0) 1) sldname)
      (end_image)
  )
)

; this is second step
(defun ai_ptype_main (/ globals)
  (ai_ptype_start)
;now check each sq if picked then run alan2
  (foreach pd0 ai_pts_lst2
    (action_tile  pd0  "(done_dialog)(setq ans $key)")
  )
  (start_dialog)

)

; this is first step

  (if (= w2 nil)(setw2))      
  
  (setq app "dd3x3.dcl")
  (if (= id_3x3 nil)
    (progn
    (setq dcl_id (load_dialog app))
    (setq id_3x3 dcl_id)
    )
  )
  (if (not (new_dialog "dd3x3" id_3x3))
  (exit))
  (ai_ptype_main)
  (sq_pick)
  (setq *error* old_error old_error nil)

 

//  DD3x3 dialogue.  Used by the DD3x3 command in DD3x3.lsp.
//  Called from the AutoCAD Release 12 Standard Menu.

dd3x3 : dialog {
  label        = "Please choose item";
  : column {
    : row {
      : image_button {
        key          = "33sq1";
        width        = 10;
        aspect_ratio = 1.0;
        color        = 0;
        allow_accept = true;
      }
      : image_button {
        key          = "33sq2";
        width        = 10;
        aspect_ratio = 1.0;
        color        = 0;
        allow_accept = true;
      }
      : image_button {
        key          = "33sq3";
        width        = 10;
        aspect_ratio = 1.0;
        color        = 0;
        allow_accept = true;
      }
    }
    : row {
      : image_button {
        key          = "33sq4";
        width        = 10;
        aspect_ratio = 1.0;
        color        = 0;
        allow_accept = true;
      }
      : image_button {
        key          = "33sq5";
        width        = 10;
        aspect_ratio = 1.0;
        color        = 0;
        allow_accept = true;
      }
      : image_button {
        key          = "33sq6";
        width        = 10;
        aspect_ratio = 1.0;
        color        = 0;
        allow_accept = true;
      }
      }
      : row {
      : image_button {
        key          = "33sq7";
        width        = 10;
        aspect_ratio = 1.0;
        color        = 0;
        allow_accept = true;
      }
      : image_button {
        key          = "33sq8";
        width        = 10;
        aspect_ratio = 1.0;
        color        = 0;
        allow_accept = true;
      }
      : image_button {
        key          = "33sq9";
        width        = 10;
        aspect_ratio = 1.0;
        color        = 0;
        allow_accept = true;
      }
      }
  }
ok_cancel;
}
0 Likes
Message 6 of 17

Homecad2007
Enthusiast
Enthusiast

thanks for the code simplification, the only thing is that now it seems I am missing some slides and it appears to be random.  Any reason why they might be missing

0 Likes
Message 7 of 17

Homecad2007
Enthusiast
Enthusiast

This routine doesnt seem to work.  I think something is missing

0 Likes
Message 8 of 17

john.uhden
Mentor
Mentor

R12.  I'm impressed.  Looks like you may have been doing this stuff since June 28, 1992.

John F. Uhden

0 Likes
Message 9 of 17

Homecad2007
Enthusiast
Enthusiast

Thanks, I have been using Autocad for some time now, never really mastered lisp, just enough to get me into trouble 🙂

 

0 Likes
Message 10 of 17

Sea-Haven
Mentor
Mentor

Yes started  Autocad like 1.4 I am that old.

 

0 Likes
Message 11 of 17

Sea-Haven
Mentor
Mentor

Check slide names may be a caps / lowercase problem. 52 Characters in the alphabet.

0 Likes
Message 12 of 17

Homecad2007
Enthusiast
Enthusiast

Ok I fixed the images, I want to move the text to the left side, how do I do that? 

 

I can select images now but how do I get the image insert text?

 

Thanks for everyones input

 

0 Likes
Message 13 of 17

Homecad2007
Enthusiast
Enthusiast

I made some adjustments and now I have the images at least showing what detail number they are however I have still not figured out how to activate a command by selecting an image. 

 

I would also like to have the list of names on the left side of the images instead of at the top but not sure how to change the DCL file to do this

 

Any help would be appreciated

 

0 Likes
Message 14 of 17

Sea-Haven
Mentor
Mentor

Did you look at johns post it has what you want.

 

Re select by image just look through the example I posted the sq_pick defun.

 

If you use a menu it auto fills in a description with images.

0 Likes
Message 15 of 17

Homecad2007
Enthusiast
Enthusiast

Unfortunately I could not get John's link to work or your lisp routine to work to see how it was functioning.  I am still not sure how to do this.  Could you please send your lisp routine link

 

Thanks

Tony

0 Likes
Message 16 of 17

Sea-Haven
Mentor
Mentor

I have my slides for this example in a slide library a slb with like a 100 slides in it easier to manage. if you remove the ctone part

(setq ai_pts_lst '("TLDS" "dsdn" "trds"
                   "ds" "ca3blank" "DSL"
                   "blds" "dsup" "brds")
)

 should work ok 

0 Likes
Message 17 of 17

john.uhden
Mentor
Mentor

One thing I didn't mention is that it seems you want to take action based soley on the image pick.  My perception works differently.  I want the user, including myself, to see verification of what they/I have picked and when they/I see it they/I hit "OK."

Seems to me like your approach would be better served by a menu pick. (I'm sorry, did I say that wrong?  Today do we call it a CUI pick?  Remember that I'm just an old fart trying to still learn from all you youngsers, like @Sea-Haven .)

What I would do on an image_button action_tile is to set the name or ID of the desired pick in a local variable, and then when the user picks "OK" the program performs the desired insert or whatever diabolical operations you want to perform.

That doesn't mean you can't do what you want (without the "OK").  But I do think you have to at least perform a (done_dialog) before any ensuing action.

John F. Uhden

0 Likes