cant able to run LISP with DCL

cant able to run LISP with DCL

smallƑish
Advocate Advocate
954 Views
12 Replies
Message 1 of 13

cant able to run LISP with DCL

smallƑish
Advocate
Advocate

Attached is a very simple LSP and DCL file,

Need help running it. the dialogue box pops up , But drops out then click the button

 

smallish_0-1708105973024.gif

 

0 Likes
Accepted solutions (2)
955 Views
12 Replies
Replies (12)
Message 2 of 13

paullimapa
Mentor
Mentor

What happens when you run this from the AutoCAD command prompt instead of vlide?

Also what do you expect to happen when you click that button?


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

smallƑish
Advocate
Advocate

When we click the C10 button (DCL), the C10 lisp command should activate and ask for a center point to draw a circle with 10 rad.

 

0 Likes
Message 4 of 13

paullimapa
Mentor
Mentor

Your lisp is missing at least 2 components:

1. action statements - what happens when a button is clicked

I know you included this in your dcl but going back to the graphic screen requires the dialog to be first closed which your action statement in the dcl does not cover. I prefer to do all the action statements in lisp code which gives a lot more flexibility.  One way of doing this since your buttons are similar is to code it like this:

 

 

; include actions statements before start dialog
(foreach tile '("C10""C15""C20")(action_tile tile "(setq clicked $key)(done_dialog)")) ; this sets value in clicked variable & then closes dialog
; start dialog
(start_dialog dialogResult)

 

 

2. condition statements - test results to run commands after dialog closes

This is where your different function calls should go. So one way of doing this is using these lines:

 

 

; unload dialog
(unload_dialog dialogResult)
; test to see what if anything was selected:
(cond
 ((= clicked "C10") (c:C10))
 ((= clicked "C15") (c:C15))
 ((= clicked "C20") (c:C20))
 (t(alert"Nothing Selected"))
) ; cond

 

 

 


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

paullimapa
Mentor
Mentor
Accepted solution

ok, just found more problems:

Though not required but a good standard of practice:

I renamed your defun command to treecircle to match with the filename.

I localized your variable + the one I added:

; defined function as treecircle
(defun c:treecircle 
; localize variables
 (/ clicked dialogResult)
  (setq dialogResult (load_dialog "treecircle.dcl"))

After load_dialog you have to include this line:

; need to include this line
(new_dialog "treecircle" dialogResult)

Your start_dialog code is incorrect:

; start dialog
;  (start_dialog dialogResult)
; this is the proper method 
  (start_dialog)

Lastly your dcl includes this but no attributes:

https://documentation.help/AutoCAD-ALISP-VLISP/WS73099cc142f4875516d84be10ebc87a53f-7abc.htm

        :spacer {}

See attached revised files

 


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

paullimapa
Mentor
Mentor

now for your next challenge...bring the dialog back after each circle drawing continuously until you click the OK/Cancel button


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

smallƑish
Advocate
Advocate

That's what I was thinking,

 

also When I try to make it VLX, its not activating by treecircle command!!

0 Likes
Message 8 of 13

paullimapa
Mentor
Mentor

Unfortunately, I can't help you with VLX since I don't use this feature.


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

smallƑish
Advocate
Advocate

What we have to do for it, to come back the dialogue box, till exit.

0 Likes
Message 10 of 13

paullimapa
Mentor
Mentor
Accepted solution

ok, here's the magic...at least one method of doing it.

First I added another variable what-next

This is the variable that will be checked to see if it loops or not.

 

; defined function as treecircle
(defun c:treecircle 
; localize variables
 (/ clicked dialogResult what-next)
  (setq dialogResult (load_dialog "treecircle.dcl"))
  (if (not dialogResult)
    (exit)
  )
; setup for dialog loop
(setq what-next 1) ; start with higher than 0
(while (> what-next 0) ; loop as long as value is greater than 0
 (new_dialog "treecircle" dialogResult)

 

Notice the while loop occurs after the load_dialog function. So the dialog only needs to be loaded once. It stays in memory until it's unloaded.

After the while statement then run the new_dialog function to make the dialog appear on the screen. This is the function that needs to repeat in the loop or else you won't see the dialog again.

Then I added additional action statements to pass the value declared when start_dialog runs & done_dialog function closes the dialog (note the matching uppercase on OK & CANCEL which is how you've included these keys in the dcl):

 

; include actions statements before start dialog
 (foreach tile '("C10""C15""C20")(action_tile tile "(setq clicked $key)(done_dialog 1)")) ; this sets value in clicked variable & then closes dialog
 (action_tile "OK" "(done_dialog 1)")     ; OK button close dialog but continue loop
 (action_tile "CANCEL" "(done_dialog 0)") ; CANCEL button close dialog & end loop
; start dialog
;  (start_dialog dialogResult)
; this is the proper method 
  (setq what-next (start_dialog)) ; save done_dialog return value

 

Now the condition statement tests need to be moved up right after start_dialog function so these can run in the while loop. After circle functions are completed, since the what-next value continues to be greater than 0 then it'll  loop back up top and run new_dialog again. But if not, like when the CANCEL button is clicked which sets the what-next value to 0 then the while loop ends and the unload_dialog function is called to remove the dcl from memory and close the routine:

 

; check return value 
 (if(> what-next 0)     ; if greater than 0
  (progn
   (cond                 ; test to see what if anything was selected:
    ((= clicked "C10") (princ(strcat"\nDraw Circle " clicked "..."))(c:C10))
    ((= clicked "C15") (princ(strcat"\nDraw Circle " clicked "..."))(c:C15))
    ((= clicked "C20") (princ(strcat"\nDraw Circle " clicked "..."))(c:C20))
    (t(alert"Nothing Selected"))
   ) ; cond
  ) ; progn
  ; else is 0 
  (alert"Function Cancelled")
 ) ; if
) ; while
; unload dialog
 (unload_dialog dialogResult)
 (princ)
) ; defun

 

 


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

Sea-Haven
Mentor
Mentor

I dont understand why you even need a dcl if your just choosing a circle diameter your defuns work as is. If you dont want the code to be loaded till you actually need it then use the "AUTOLOAD" function in a startup lisp. 

 

 

(autoload "TREESDIA" '("10"))
(autoload "TREESDIA" '("12"))
(autoload "TREESDIA" '("15"))

 

 

Just a comment we used CIV3D so trees would come in as blocks but the cogo point description had trunk & Diameter so we would read that description and reset the dynamic block with correct spread and a trunk as a circle. 

 

Just look at my Multi radio butons.lsp it will do what you want and Ok or pick button closes, so could add a while to pick blocks once dia is found.

 

 

(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (= ahdef nil)(setq ahdef 1))
(setq ans (atoi (ah:butts ahdef "V" '("Choose a dia " "1" "2" "3" "4" "5" "6" "7" "8" "9" "10")))) ; ans holds the button picked as an integer value

 

SeaHaven_0-1708225351836.png

If you do (setq ahdef but) will remember last button selected.

0 Likes
Message 12 of 13

smallƑish
Advocate
Advocate

This message changed my view about DCL. I believe with just referring your explanation and example codes, everyone can make their own dialogue and execute it with lisp properly. I feel proud to be part of it. Thank you so much from bottom of my heart.  

0 Likes
Message 13 of 13

paullimapa
Mentor
Mentor

Once again glad to have helped…cheers!!!


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