Author Topic: Check if blank is an actual (core) command.  (Read 4508 times)

0 Members and 1 Guest are viewing this topic.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Check if blank is an actual (core) command.
« on: March 30, 2011, 03:34:13 PM »
Is it possible to check if a specific command is actually a command (not LISP) within AutoCAD?

eg.
Line command:
(and LINE)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

gile

  • Gator
  • Posts: 2513
  • Marseille, France
Re: Check if blank is an actual (core) command.
« Reply #1 on: March 30, 2011, 03:49:13 PM »
Hi,

Using getcname function:
(getcname "line")
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Check if blank is an actual (core) command.
« Reply #2 on: March 31, 2011, 07:36:41 AM »
That's a new one to me - merci beaucoup Gilles  8-)

pBe

  • Bull Frog
  • Posts: 402
Re: Check if blank is an actual (core) command.
« Reply #3 on: March 31, 2011, 07:51:57 AM »
unless somewhere alongthe way somebody did this inside a vlx file


Code: [Select]
(defun sample ()
  (princ "\nHello Swamp")
  (princ))

Code: [Select]
(vlax-add-cmd "sample" "sample")
(getcname "sample")
"_SAMPLE"

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Check if blank is an actual (core) command.
« Reply #4 on: March 31, 2011, 08:17:01 AM »
It apparently doesn't work for XPLODE.

Quote
Command: (getcname "xplode")
nil
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Check if blank is an actual (core) command.
« Reply #5 on: March 31, 2011, 08:27:20 AM »
That's only an alias though:

Code: [Select]
_$ (getcname "explode")
"_EXPLODE"

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Check if blank is an actual (core) command.
« Reply #6 on: March 31, 2011, 08:29:07 AM »
Hi,

Using getcname function:
(getcname "line")
Thanks, Gile.

That's only an alias though:

Code: [Select]
_$ (getcname "explode")
"_EXPLODE"
XPlode and Explode are not the same.
« Last Edit: March 31, 2011, 08:38:53 AM by alanjt »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Check if blank is an actual (core) command.
« Reply #7 on: March 31, 2011, 08:40:48 AM »
I was playing around with one of those situations where you are forced to use command to visually place something and I scratched this out...

Code: [Select]
(defun AT:Command (cmd / *error* c e n lst)
  (defun *error* (msg) (and c (setvar 'CMDECHO c)) (reverse lst))
  (setq e (entlast))
  (setq c (getvar 'CMDECHO))
  (setvar 'CMDECHO 1)
  (command cmd)
  (while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (command PAUSE))
  (or (equal (setq n e) (entlast)) (while (setq n (entnext n)) (setq lst (cons n lst))))
  (*error* nil)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

pBe

  • Bull Frog
  • Posts: 402
Re: Check if blank is an actual (core) command.
« Reply #8 on: August 28, 2011, 03:10:25 AM »
what about the other way around? check if a command is a lisp?

Code: [Select]
(defun LC (cmd)
(foreach i (atoms-family 1)
  (if (EQ (strcase cmd) I)
    (print (strcat "Lisp Command Found: " i)))(princ)
  )
)

(LC "C:sample")
(LC "sample")
(LC "C:XPLODE")








Crank

  • Water Moccasin
  • Posts: 1503
Re: Check if blank is an actual (core) command.
« Reply #9 on: August 28, 2011, 03:36:01 AM »
what about the other way around? check if a command is a lisp?

Code: [Select]
(defun LC (cmd)
(foreach i (atoms-family 1)
  (if (EQ (strcase cmd) I)
    (print (strcat "Lisp Command Found: " i)))(princ)
  )
)

(LC "C:sample")
(LC "sample")
(LC "C:XPLODE")
In the macros of my CUI , I don't use atoms-family to check if a lisp is present, but I just use:
Code: [Select]
(if (not c:example)(load "example"))

But now I wonder: Is it possible to check if a command has been added through a .dll , or if the .dll has been loaded ?
Vault Professional 2023     +     AEC Collection

gile

  • Gator
  • Posts: 2513
  • Marseille, France
Re: Check if blank is an actual (core) command.
« Reply #10 on: August 28, 2011, 04:23:11 AM »
Quote
But now I wonder: Is it possible to check if a command has been added through a .dll , or if the .dll has been loaded ?
For .NET defined commands, I use getcname too.
Speaking English as a French Frog

pBe

  • Bull Frog
  • Posts: 402
Re: Check if blank is an actual (core) command.
« Reply #11 on: August 28, 2011, 05:53:24 AM »
In the macros of my CUI , I don't use atoms-family to check if a lisp is present, but I just use:
Code: [Select]
(if (not c:example)(load "example"))

But now I wonder: Is it possible to check if a command has been added through a .dll , or if the .dll has been loaded ?

I undertsand, what i'm getting at is trying to find out if a lisp with the same name as an ALIAS (pgp) is loaded. if somewhere along the way somebody loads a lisp command that  supercedes the ALIAS i would somehow unload it and not the other way around, strange huh?   :-D







Crank

  • Water Moccasin
  • Posts: 1503
Re: Check if blank is an actual (core) command.
« Reply #12 on: August 28, 2011, 05:57:58 AM »
@ gile: Cool! :mrgreen:

@pBe: Roger
Vault Professional 2023     +     AEC Collection

LE3

  • Guest
Re: Check if blank is an actual (core) command.
« Reply #13 on: August 28, 2011, 11:15:52 AM »
Quote
But now I wonder: Is it possible to check if a command has been added through a .dll , or if the .dll has been loaded ?
For .NET defined commands, I use getcname too.

I have used this in the past, but from the ARX side:
Code: [Select]
AcEdCommandStack* pCmdStack = AcEdCommandStack::cast(acrxSysRegistry()->at(ACRX_COMMAND_DOCK));
AcEdCommand *pCmd = pCmdStack->lookupGlobalCmd(_T("CommandName")); // name of the command to look for

Have not tried the C# route but after a quick look appears that there is a wrapper now for the above as: CommandStack - no idea if works or the usage signature.


HTH.-

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Check if blank is an actual (core) command.
« Reply #14 on: August 28, 2011, 12:42:32 PM »
Sorry to drag up old code, but I just wanted to notify that the following:

Code: [Select]
(defun AT:Command ... )

Won't work if the last created entity is an attributed block, e.g.:

Code: [Select]
_$ (mapcar '(lambda ( x ) (cdr (assoc 0 (entget x)))) (AT:Command "LINE"))
("ATTRIB" "ATTRIB" "SEQEND" "LINE" "LINE" "LINE")

I propose:

Code: [Select]
(defun AT:Command2 ( cmd / *error* cm e1 e2 e3 ls )

    (defun *error* ( msg ) (if cm (setvar 'CMDECHO cm)) (reverse ls))

    (if (setq e1 (entlast) e2 e1)
        (while (setq e3 (entnext e2)) (setq e2 e3))
        (setq e2 t)
    )
    (setq cm (getvar 'CMDECHO))
    (setvar 'CMDECHO 1)
    (command cmd)
    (while (= 1 (logand 1 (getvar 'CMDACTIVE)))
        (command pause)
    )   
    (if (not (equal e1 (entlast)))
        (while (setq e2 (entnext e2)) (setq ls (cons e2 ls)))
    )
    (*error* nil)
)

Now:

Code: [Select]
_$ (mapcar '(lambda ( x ) (cdr (assoc 0 (entget x)))) (AT:Command2 "LINE"))
("LINE" "LINE" "LINE")