Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can't redefine the "ID" command?

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
kpennell
641 Views, 13 Replies

Can't redefine the "ID" command?

I've written a script that improves the default "ID" command, but it's not working.

 

Any insight as to why?  I was able to redefine the "DI" command.

 

Thanks

KP

13 REPLIES 13
Message 2 of 14
pendean
in reply to: kpennell

Can you elaborate? Usually you have to UNDEFINE a command before you can create a replacement with the same exact name.

And what is DI?
Message 3 of 14
Kent1Cooper
in reply to: kpennell


@kpennell wrote:

I've written a script that improves the default "ID" command, but it's not working.

 

Any insight as to why?  I was able to redefine the "DI" command.

....


No insight based on the information provided.  Post the code, describe how it's intended to work and in what way it doesn't work [doesn't do anything? does something different than expected? error message(s)?], etc., etc.

 

Would I be correct in assuming that it's not a Script, but an AutoLisp routine involving (defun) to define a command name?  "Script" has a specific meaning in AutoCAD, and a Script is not something that can be used to redefine a command, though a Script might possibly be able to emulate the operation of certain commands.

Kent Cooper, AIA
Message 4 of 14
kpennell
in reply to: kpennell

"DI" is set to be AutoCAD's "DIST" command.

 

I think I see where you're going with this tho.  I'll look into undefining commands.  Maybe dangerous, but I'll learn something.

 

Thanks

KP

Message 5 of 14
kpennell
in reply to: Kent1Cooper

    (setvar "qaflags" 0)

    (setq Cucs (getpoint "\nSelect point..."))
    (setq Wucs (trans Cucs 1 0))

    (setq Version (getvar "acadver"))

    (cond
    ((= Version "18.2s (LMS Tech)")())
    (T(setvar "clipromptupdate" 1))
    )

    (setq UserPrec (getvar "luprec"))

    (setq CucsX (car Cucs))
    (setq CucsXArch (rtos CucsX 4 UserPrec))
    (setq CucsXDec (rtos CucsX 2 UserPrec))

    (setq CucsY (cadr Cucs))
    (setq CucsYArch (rtos CucsY 4 UserPrec))
    (setq CucsYDec (rtos CucsY 2 UserPrec))

    (setq CucsZ (caddr Cucs))
    (setq CucsZArch (rtos CucsZ 4 UserPrec))
    (setq CucsZDec (rtos CucsZ 2 UserPrec))

    (setq WucsX (car Wucs))
    (setq WucsXArch (rtos WucsX 4 UserPrec))
    (setq WucsXDec (rtos WucsX 2 UserPrec))

    (setq WucsY (cadr Wucs))
    (setq WucsYArch (rtos WucsY 4 UserPrec))
    (setq WucsYDec (rtos WucsY 2 UserPrec))

    (setq WucsZ (caddr Wucs))
    (setq WucsZArch (rtos WucsZ 4 UserPrec))
    (setq WucsZDec (rtos WucsZ 2 UserPrec))

    (cond
    ((and (= CucsX WucsX)(= CucsY WucsY)(= CucsZ WucsZ))(princ (strcat "\nWorld UCS: X = " WucsXArch " (" WucsXDec ")     Y = " WucsYArch " (" WucsYDec ")     Z = " WucsZArch " (" WucsZDec ")")))
    (T    (princ (strcat "\nWorld UCS: X = " WucsXArch " (" WucsXDec ")     Y = " WucsYArch " (" WucsYDec ")     Z = " WucsZArch " (" WucsZDec ")"))
        (princ (strcat "\nCurrent UCS: X = " CucsXArch " (" CucsXDec ")     Y = " CucsYArch " (" CucsYDec ")     Z = " CucsZArch " (" CucsZDec ")")))
    )

    (princ)

Message 6 of 14
Kent1Cooper
in reply to: pendean


@pendean wrote:
.... And what is DI?

DI is the alias for the DIST command.

Kent Cooper, AIA
Message 7 of 14
Kent1Cooper
in reply to: kpennell

Okay, that answers the first request -- now on to the others.  [I had to remove the elements specific to newer releases than mine, but after I did, it does what seems to be intended, for me.]

Kent Cooper, AIA
Message 8 of 14
kpennell
in reply to: Kent1Cooper

I wrote (command "undefine" "ID") in an automatically loaded file and it seems to work.

 

Thanks all.

Message 9 of 14
Kent1Cooper
in reply to: kpennell


@kpennell wrote:

....  I'll look into undefining commands.  Maybe dangerous....


Not too dangerous -- there's always REDEFINE, and any Undefinitions disappear when you close the drawing.

 

If Undefining first was the only issue, then maybe there's no need for my other questions.  But I have some suggestions:

 

There are a lot of variables that are used only once, so you may as well skip the variables, and use the determinations of their values directly where you were using the variables.

 

There's no need to save the User's precision setting and force (rtos) to use it -- if you don't specify a precision, it will just use the current setting.

 

You can determine whether the point is the same in WCS and UCS terms more simply, using (equal) with the Points, without the need to compare each coordinate.

 

You are spelling out the reporting of the World CS coordinates twice, unnecessarily.  It can report that regardless, and then only if you're not in the WCS, also report the Current UCS coordinates.

 

See what you think of this [add back your QAFLAGS setting and version-specific elements if you want, and remove the 2 from the command name if you load it after undefining ID]:
 

(defun C:ID2 (/ PtC PtW)
  (setq
    PtC (getpoint "\nSpecify point: ")
    PtW (trans PtC 1 0)
  ); setq
  (prompt ; in either case
    (strcat
      "\nWorld CS:  X = " (rtos (car PtW) 4) " (" (rtos (car PtW) 2) ")"
      "  Y = " (rtos (cadr PtW) 4) " (" (rtos (cadr PtW) 2) ")"
      "  Z = " (rtos (last PtW) 4) " (" (rtos (last PtW) 2) ")"
    ); strcat
  ); prompt
  (if (not (equal PtC PtW)); not in WCS
    (prompt
      (strcat
        "\nCurrent UCS:  X = " (rtos (car PtC) 4) " (" (rtos (car PtC) 2) ")"
        "  Y = " (rtos (cadr PtC) 4) " (" (rtos (cadr PtC) 2) ")"
        "  Z = " (rtos (last PtC) 4) " (" (rtos (last PtC) 2) ")"
      ); strcat
    ); prompt
  ); if
  (princ)
); defun

Kent Cooper, AIA
Message 10 of 14
kpennell
in reply to: Kent1Cooper

"There are a lot of variables that are used only once, so you may as well skip the variables, and use the determinations of their values directly where you were using the variables."

 

I like stepping through this way, becasue its the way i understand it best.  I don't code all the time, so when i get back to it, it's easier oforr me to understand what's going on.

 

"There's no need to save the User's precision setting and force (rtos) to use it -- if you don't specify a precision, it will just use the current setting."

 

Agreed, now that understand the verbage on the "rtos" function.  Good point.

 

"You can determine whether the point is the same in WCS and UCS terms more simply, using (equal) with the Points, without the need to compare each coordinate."

 

Agreed

 

"You are spelling out the reporting of the World CS coordinates twice, unnecessarily.  It can report that regardless, and then only if you're not in the WCS, also report the Current UCS coordinates.

 

Agreed.

 

Thanks KC for helping me see.  You are a fine teacher.

 

Message 11 of 14
Kent1Cooper
in reply to: kpennell


@kpennell wrote:

"There are a lot of variables that are used only once, so you may as well skip the variables, and use the determinations of their values directly where you were using the variables."

 

I like stepping through this way, becasue its the way i understand it best.  I don't code all the time, so when i get back to it, it's easier oforr me to understand what's going on.

....


Given that, here's another way you can still simplify things a little.  You can set any number of variables within one (setq) function, instead of closing (setq) and getting back into it for each one separately:

 

    (setq
      CucsX (car Cucs)
      CucsXArch (rtos CucsX 4)

;.... and all the others ....
      WucsZArch (rtos WucsZ 4)
      WucsZDec (rtos WucsZ 2)

    ); end setq

 

If you make that change, be sure to remove all the right parentheses that were closing the individual (setq) functions at the end of each variable's line.

Kent Cooper, AIA
Message 12 of 14
pendean
in reply to: Kent1Cooper

It was a tongue-in-cheek question to make the OP think about it as you cannot undefine DI, just DIST 🙂
Message 13 of 14
Kent1Cooper
in reply to: pendean


@pendean wrote:
It was a tongue-in-cheek question to make the OP think about it as you cannot undefine DI, just DIST 🙂

I suppose that depends on how you [forgive me...] define "undefine."  Agreed, you can't Undefine DI using the Undefine command, but you could, in effect, undefine it by editing the command-aliases file, and then redefine it as you would a full command name.

Kent Cooper, AIA
Message 14 of 14
kpennell
in reply to: Kent1Cooper

I knew about "undefine" a long while back, it must have been years.  I had forgotten the difference between alias' and real AutoCAD commands, which I believe to be the source of my problem.  You can override alias' but you can't override true commands, without undefining them first.

 

Oh and I redefined a command as well.  That could come in quite handy.  Thanks KC.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost