Author Topic: Routine not executing in (Command "x") fashion  (Read 1567 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Routine not executing in (Command "x") fashion
« 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)
)
Civil3D 2020

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Routine not executing in (Command "x") fashion
« Reply #1 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")
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Re: Routine not executing in (Command "x") fashion
« Reply #2 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....
Civil3D 2020

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Re: Routine not executing in (Command "x") fashion
« Reply #3 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" "" "~")
Civil3D 2020

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Routine not executing in (Command "x") fashion
« Reply #4 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...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Routine not executing in (Command "x") fashion
« Reply #5 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. )
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg