Call external lisp within a lisp of a DCL

Call external lisp within a lisp of a DCL

sam_safinia
Advocate Advocate
855 Views
7 Replies
Message 1 of 8

Call external lisp within a lisp of a DCL

sam_safinia
Advocate
Advocate

How can I call up to run a external lisp within a DCL lisp?

 

defun C:test (/ AAA  BBB ccc ddd       ) ;;; BBB is a function in an external lisp
  (setq dcl_id (load_dialog "test.dcl"))
  (if (not (new_dialog "test" dcl_id))
    (progn (alert " Error in loading the dialog (test.dcl) ")
           (exit)
    )
  )
     (action_tile
       "D_AAA"
       "(setq ccc t)(done_dialog)"
	   )
     (action_tile
       "D_BBB"
       "(setq ddd t)(done_dialog)"
     )
	(action_tile "cancel" "(done_dialog)")
  (start_dialog)
  (unload_dialog dcl_id)
  (cond 
           ((and ccc) (progn (c:AAA)     (C:TEST)))
           ((and ddd) (progn (c:BBB)     (C:TEST))) ;; BBB is external function 
  )
  (princ)
)

DCL

test : dialog {
          label = "Test";         
        : button {
            label = "Test1"; 
            key = "D_AAA";
			is_default = false;
        } 
        : button {
            label = "Test2"; 
            key = "D_BBB";
			is_default = false;
        }   		
     ok_only ;
   }

 

I want to assign function BBB to an external lisp to work for button Test2 in attached dcl.

 

Thanks

0 Likes
856 Views
7 Replies
Replies (7)
Message 2 of 8

Moshe-A
Mentor
Mentor

hi,

 

it is more easy than you think...you need to load it in memory before calling it

 

(cond 
   ((/=  ccc nil)

     (load "aaa")

     (c:AAA) 

   )

   ((/= ddd nil)

     (load "bbb")

     (c:BBB )

  )

); cond

 

 

ofcourse you can check if the load is successful

 

(load "aaa")

(if (c:aaa)

   (do_run)

   (echo_error_msg)

)

 

the (load) function has a second argument [onfailure]  to return if the load fails

 

if (c:AAA) and (c:BBB) are just a regular functions there is not need to prefix functions name with C:

 

 

cheers

moshe

 

 

Message 3 of 8

hmsilva
Mentor
Mentor

Hi s_plant,
in addition to Moshe-A suggestions, and if I did understood your goal:
do the selected function, AAA or BBB, return to the test.dcl and only exits the loop when the user chooses 'Cancel'.


Perhaps something like this:

 

(defun c:test (/ ccc ddd)
   (setq dcl_id (load_dialog "test.dcl"))
   (if (not (new_dialog "test" dcl_id))
      (progn (alert " Error in loading the dialog (test.dcl) ")
             (exit)
      )
   )
   (action_tile
      "D_AAA"
      "(setq ccc t)(done_dialog)"
   )
   (action_tile
      "D_BBB"
      "(setq ddd t)(done_dialog)"
   )
   (action_tile "cancel" "(done_dialog)")
   (start_dialog)
   (unload_dialog dcl_id)
   (cond
      (ccc (c:AAA) (C:TEST))
      (ddd (c:BBB) (C:TEST))
   )
   (princ)
)

(defun c:AAA nil
   (alert "\n This is AAA function")
)
(defun c:BBB nil
   (alert "\n This is BBB function")
)

DCL

 

test : dialog {
          label = "Test";         
        : button {
            label = "Test1"; 
            key = "D_AAA";
			is_default = false;
        } 
        : button {
            label = "Test2"; 
            key = "D_BBB";
			is_default = false;
        }   		
     cancel_button ;
   }

 

Hope this helps,
Henrique

EESignature

Message 4 of 8

sam_safinia
Advocate
Advocate
Thanks Henrique and Mashe. Both suggestions are working.

Is it possible to assign multi function(or in therefore lisps) to only one action tile? I mean by hitting a button several lisp run at once.

Thanks
0 Likes
Message 5 of 8

hmsilva
Mentor
Mentor

@s_plant wrote:
Thanks Henrique and Mashe. Both suggestions are working.

Is it possible to assign multi function(or in therefore lisps) to only one action tile? I mean by hitting a button several lisp run at once.

You're welcome, s_plant.
Yes, in your code, you are calling two functions per button:

 

(cond
      (ccc (c:AAA) (C:TEST))
      (ddd (c:BBB) (C:TEST))
   )

 

 

you can add functions as needed:

 

(cond
      (ccc (c:AAA) (DDD) (C:EEE) (C:TEST))
      (ddd (c:BBB) (ETC) (C:TEST))
   )


Henrique

 

EESignature

0 Likes
Message 6 of 8

Moshe-A
Mentor
Mentor

when you hit a dcl button you can run as many lisps files/functions as you like by just calling them in a row

 

0 Likes
Message 7 of 8

sam_safinia
Advocate
Advocate

I tried your suggestions but did not get it right. To be specific,

how can I assign this lisp to second button "Test2" considering following cases?

 

case 1: when it is an external lisp (or vlx)

 

case 2 : when we can accommodate it within our main lisp "Test"

 

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

Thanks

0 Likes
Message 8 of 8

sam_safinia
Advocate
Advocate

It's fixed by removing brackets as:

 

(cond
      (ccc (c:AAA) fff (C:EEE) (C:TEST)) ;; No bracket need for setq it was (fff)
   )

 Thanks guys

0 Likes