DCL assign a lisp routine to a button

DCL assign a lisp routine to a button

Anonymous
Not applicable
1,387 Views
7 Replies
Message 1 of 8

DCL assign a lisp routine to a button

Anonymous
Not applicable

I've got a lisp routine and trying to assign that to a button in a DCL form. I might have missed a very basic point. any help?

 

Thanks

0 Likes
1,388 Views
7 Replies
Replies (7)
Message 2 of 8

rkmcswain
Mentor
Mentor

Here is one way. (No mods to your DCL)

 

(defun deldim (/ ss)
  (setq ss (ssget "x" (list (cons 0 "Dimension"))))
  (if ss
    (vl-cmdf ".erase" ss "")
    (princ "\nNo dimensions in this drawing!")
  )
  (princ)
)

(defun c:clup ( / result dcl_id)
  (setq dcl_id (load_dialog "clup.dcl"))
  (if (not (new_dialog "clup" dcl_id))
    (progn
      (alert "The clup.dcl file could not be loaded!")
      (exit)
    )
  )
  (action_tile
    "deldim"
    "(done_dialog)(setq result T)"
  )
  (action_tile
    "cancel"
    "(done_dialog)
     (setq result nil)"
  )
  (action_tile
    "accept"
    "(done_dialog)
     (setq result nil)"
  )
  (start_dialog)
  (unload_dialog dcl_id)

  (if result
    (deldim)
  )
  (princ)
)
(princ)

 

R.K. McSwain     | CADpanacea | on twitter
Message 3 of 8

scot-65
Advisor
Advisor
RK has the right idea.

Use the start_dialog to fetch an integer return from done_dialog:
(setq sd (start_dialog))

Inside the action_tile, assign the done_dialog with an integer flag where 1 is
OK and 0 is nil (standard practice):
(action_tile "deldim" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")

Now, in your "main" section, test sd:
(if (and sd (= sd 1))
(deldim)
);if

RK's code shows more action_tiles than there are tiles in the DCL file.
Remove the accept section.

In your DCL file add a cancel button and give it a is_default:
:button {key="cancel"; label="&Cancel"; is_default=true;}
Remove the ok_only.

As a note, the "OK_" family can be omitted entirely without having to
use the "retirement" features as long as there is the "is_default" attribute
present somewhere inside the DCL file.

Hope this helps.

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

Message 4 of 8

rkmcswain
Mentor
Mentor
....RK's code shows more action_tiles than there are tiles in the DCL file.

FWIW, I just did a quick and dirty edit on OP's code.

 

That extra action_tile was already in there. Smiley Wink

 

Cheers.

R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 5 of 8

Anonymous
Not applicable
 
0 Likes
Message 6 of 8

Anonymous
Not applicable
Thanks guys for your dvice. At the moment by pressing DEL DIM, it's closing the dialog window. If I want to hide the window while I'm selecting items to delete (not cleaning up entire dimensions once), how the lisp will be? Is there any way that by pressing Esc or Enter it delete selected dim inputs?
Cheers
0 Likes
Message 7 of 8

scot-65
Advisor
Advisor

For that you will need to loop the dialog.
Learning curve just got steeper.


One button to select objects (done_dialog 2)

One button is accept (done_dialog 1)

One button is cancel (done_dialog 0)

 

(setq sd 2)

(while (and (= sd 2)(new_dialog...

 

 >>>

 

 (setq sd (start_dialog))

 

);while

 

See attached file I use as a beginning template for a looping dialog.

It will require revisions for your needs. There is no "main" section after the while loop, you will have to add that.

 

This can also be used when "daisy-chaining" dialogs or a "parent/home/(hub)" dialog with "children/(spoke)" dialogs.

 

I like your ambition.

 

???

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

Message 8 of 8

Anonymous
Not applicable

Thanks Scot-65, yes it's very steep for me but no pain, no gain. I'll update this thread soon hopefully by a solution!

0 Likes