Override existing commands with acedRegCmds->addCommand()

In my plugin I add several commands and I have noticed that if a command is already used by BricsCad my command isn't overriding it.
For example I have the following line:

Acad::ErrorStatus error = acedRegCmds->addCommand(_T("AALP"), _T("AALP_TARGET_ADD"), _T("target"), ACRX_CMD_MODAL, addtarget, NULL, -1, myArxDLL.ModuleResourceInstance());

When I type the command "target" in the command prompt I trigger a already defined command in BricsCad and not my own.
In AutoCAD this override the already defined command so my command is used instead. Is there any settings for this or how to solve it (if possible)?

Comments

  • did you try undefining the old command first? acedCmdUndefine
  • did you try undefining the old command first? acedCmdUndefine

    No I haven't but it didn't do anything when I added this first:
    int retval = acedCmdUndefine(_T("target"), 0);
  • "TARGET" is not directly a native BricsCAD or AutoCAD command - it is a system variable;
    and system variables can be started "like a command" at commandline.

    So when you enter 'target' at commandline, it will run the "system variable's command", as system variables have kind of priority in command detection + interpretation.
    I assume using 'AALP_TARGET_ADD' will run your command, right ?

    Safest approach is to use a different localised name, instead of 'target' ... at least in menu/ribbon/toolbar/toolpalette it does not really matter how the localised command is named :-)

    hope this explains a bit ?
    many greetings !
  • Its_Alive
    edited November 2022
    looks like a bug, I've used acedCmdUndefine before with success, but target doesn't want to play, maybe because it's a sysvar..

    virtual AcRx::AppRetCode On_kLoadDwgMsg(void* pkt)
    {
    AcRx::AppRetCode retCode = AcRxArxApp::On_kLoadDwgMsg(pkt);
    if (acedCmdUndefine(_T("TARGET"), 0))
    acutPrintf(_T("\ntrue"));
    return (retCode);
    }
    static void ArxBrxTest_target(void)
    {
    acutPrintf(_T("\nWho's Abby?"));
    }

    bcad
    true
    C:\Users\Dan\source\repos\test\x64\Debug_Brx\test.brx successfully loaded.
    : TARGET
    TARGET = 0,0,0 (read only)

    acad
    Command: APPLOAD
    true
    test.arx successfully loaded.
    Command: TARGET
    Who's Abby?
  • Yes it's behaving different from AutoCad. There are some other commands that give the same kind of error so had been great if it was fixed. I could of course rename target to something else but in our application we have always used that word when working with AutoCAD so everyone knows it and in our case it is difficult to find a new word since we want to add certain targets to the layout.
  • As Torsten said, TARGET is not a command, and therefore can't be undefined. It's a system variable, and therefore can be entered on the command line as if it were a command.

    It looks like all that's the same in Autocad, since R12. Do you find it's not?

    TARGET (System Variable)
    https://help.autodesk.com/view/ACD/2023/ENU/?guid=GUID-0649E4B8-B11A-411E-96CE-125BEBEB5B42

    In the Command prompt text box, type the full system variable name and press Enter or the Spacebar.
    https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2020/ENU/AutoCAD-Core/files/GUID-6B2F9F11-CACE-405E-B4ED-30F7865BDA6E-htm.html

    since version <= R12
    https://www.cadforum.cz/en/variable.asp?cmd=TARGET
  • Its_Alive
    edited November 2022

    As Torsten said, TARGET is not a command, and therefore can't be undefined. It's a system variable, and therefore can be entered on the command line as if it were a command.

    It looks like all that's the same in Autocad, since R12. Do you find it's not?

    TARGET (System Variable)
    https://help.autodesk.com/view/ACD/2023/ENU/?guid=GUID-0649E4B8-B11A-411E-96CE-125BEBEB5B42

    In the Command prompt text box, type the full system variable name and press Enter or the Spacebar.
    https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2020/ENU/AutoCAD-Core/files/GUID-6B2F9F11-CACE-405E-B4ED-30F7865BDA6E-htm.html

    since version

    Why does my sample work in AutoCAD? it obviously can be undefined. I'm not suggesting the behavior be changed, but your statement is misleading. acedCmdUndefine(_T("TARGET"), 0) returning true in this case might be considered a bug.
  • Anthony Apostolaros
    edited November 2022
    Yes, I would expect that attempting to undefine a variable would return nil. But I don't think that failing to get a nil return proves the variable was undefined. What happens if you enter "Target" on the command line after undefining it? If it's undefined, you should get "Unable to recognize "TARGET." Do you? And is it different in Autocad?
  • Its_Alive
    edited November 2022

    Yes, I would expect that attempting to undefine a variable would return nil. But I don't think that failing to get a nil return proves the variable was undefined. What happens if you enter "Target" on the command line after undefining it? If it's undefined, you should get "Unable to recognize "TARGET." Do you? And is it different in Autocad?

    (command "TARGET")
    TARGET
    TARGET = 0.0000,0.0000,0.0000 (read only)

    (command "UNDEFINE" "TARGET")

    (command "TARGET")
    TARGET Unknown command "TARGET". Press F1 for help.
    Command: nil


  • Anthony Apostolaros
    edited November 2022
    Very interesting. I assume that's from Autocad? My older version of Bricscad doesn't do that, and Torsten's post suggests that the newest version doesn't do it either.

    If so, it would appear that Autocad can un-define a variable. But then what happens to that variable in the .dwg file? It's stored in the drawing file, so wouldn't un-defining it leave a hole in the file format?

    Is it really un-defined, or is it only that its value can no longer be read via what Torsten called the "system variables command"? Does Autocad have any other way to read a variable's value, equivalent to Bricscad's Settings dialog? If so, what does that say when you ask to see the value of Target?

    If you un-define it like that, and then make "Target" an alias for the Circle command, what happens? Does entering "Target" on the command line allow you to draw a circle?
  • Right Autocad hence the whole reason for this thread, it’s different behavior from BricsCAD
    I believe the way it works is that native built-in commands can still be accessed by prefixing the command with a period.
    Internally CAD will either call “.TARGET” or getvar(target). So, changing the command won’t actually change any internal behavior

    Right, the command can be redefined to do what ever the programmer wants, i.e. draw a circle, the user can still access the original native command
    By calling “.TARGET”
  • Just to add, IMHO, its probably bad form to clobber another command without good reason. There are appropriate times, I.e. redefining OPEN or SAVE to force your own GUI. In this case I would recommend prefixing with a Registered Developer Symbol or some short prefix. RDS_TARGET
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Click one of the buttons on the top bar to get involved!