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
Solved! Go to Solution.
Solved by pendean. Go to Solution.
@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.
"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
(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)
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.]
I wrote (command "undefine" "ID") in an automatically loaded file and it seems to work.
Thanks all.
@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
"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.
@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.
@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.
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.