TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MSTG007 on February 08, 2017, 11:53:23 AM

Title: Routine not executing in (Command "x") fashion
Post by: MSTG007 on February 08, 2017, 11:53:23 AM
I am using the following routine that I am trying to get to run:

Code: [Select]
(command "DLAO" "0-*" "")
This is the error I keep getting.

Code: [Select]
Command: (command "DLAO" "0-*" "")
Unknown command "DLAO".  Press F1 for help.
Unknown command "0-*".  Press F1 for help.
nil


Thank you for the help... What am I missing? (besides my head!)

Code: [Select]
(defun c:DLAO (/ Layn a ln)
(if (and
(setq Layn (strcase (getstring "\nEnter Layer to Delete: ")))
(not (member layn '("0" "" "DEFPOINTS")))
)
(while (setq a (tblnext "LAYER" (null a)))
(if (wcmatch (setq ln (strcase (cdr (assoc 2 a)))) layn)
(command "-Laydel" "Name" ln "" "Y")
)
)
)
(princ)
)
Title: Re: Routine not executing in (Command "x") fashion
Post by: ribarm on February 08, 2017, 12:08:17 PM
The closest to what you want to achieve without making (defun foo ( layname / var1 var2 ... )) is maybe something like this :

Code: [Select]
(vl-load-com)
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "DLAO\n0-*\n")
Title: Re: Routine not executing in (Command "x") fashion
Post by: MSTG007 on February 08, 2017, 12:14:08 PM
Yea... I would have never even figured that one out... I was looking around and still did not see anything that you came up with. But Hey! You did it! Works like I am wanting it too! Thanks again for your help....
Title: Re: Routine not executing in (Command "x") fashion
Post by: MSTG007 on February 08, 2017, 12:32:41 PM
I just noticed something when I added this to a routine. I have a routine that will save out several files from the current active dwg. I have placed your code near the middle of the routine. However, once the routine finishes up on the last drawing to be saved, it runs your code only on that save out.

Code: [Select]
(ALERT "Save As .CE.XREF.1.")
(COMMAND "_saveas" "" "~")
(ALERT "Save As .CE.XREF.2.")
(COMMAND "_saveas" "" "~")
(ALERT "Save As .CE.XREF.3.")
(vl-load-com)
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "DLAO\n0-*\n")
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "DLAO\nC_*\n")
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "DLAO\nCNT_*\n")
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "DLAO\nEX_PTS*\n")
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "DLAO\nPROFILE*\n")
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "DLAO\nTB1*\n")
(COMMAND "_saveas" "" "~")
(ALERT "Save As .CE.XREF.4.")
(COMMAND "_saveas" "" "~")
(ALERT "Save As .CE.XREF.5.")
(COMMAND "_saveas" "" "~")
Title: Re: Routine not executing in (Command "x") fashion
Post by: ribarm on February 08, 2017, 12:38:39 PM
You can't mess (command) calls or any other lisp statements from inside lisp with (vla-sendcommand) call inside that same lisp... This is because (vla-sendcommand) starts and works in separate namespace than lisp from where it resides to... The best you could do is to wrap all (command) calls and lisp statements in single (vla-sencommand) statement in the array you want, but be aware that execution will be performed after complete lisp finishes - totally independent and separately...
Title: Re: Routine not executing in (Command "x") fashion
Post by: Grrr1337 on February 09, 2017, 04:31:20 AM
The closest to what you want to achieve without making (defun foo ( layname / var1 var2 ... )) is maybe something like this :

Code: [Select]
(vl-load-com)
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "DLAO\n0-*\n")
Thanks for sharing this, Marko!  :idea:
Heres what I've learnt from this:
Code - Auto/Visual Lisp: [Select]
  1. ; (vla-SendCommand (vla-get-ActiveDocument (vlax-get-acad-object)) "test\nYes\n")
  2. (defun C:test ( / )
  3.   (initget "Yes No")
  4.   (if (= "Yes" (cond ((getkword "\nAlert you? [Yes/No] <No>: ")) ("No")))
  5.     (alert "\nYou've been alerted with (C:test).")
  6.   )
  7.   (princ)
  8. )
  9.  
  10. ; (vla-SendCommand (vla-get-ActiveDocument (vlax-get-acad-object)) "(test)\nYes\n")
  11. (defun test ( / )
  12.   (initget "Yes No")
  13.   (if (= "Yes" (cond ((getkword "\nAlert you? [Yes/No] <No>: ")) ("No")))
  14.     (alert "\nYou've been alerted with (test).")
  15.   )
  16.   (princ)
  17. )