How to start a command via command line

Hi,

we need a way to start the Bricscad line command within C# code

=> if some of our command will be triggered by customer we want to do some special stuff (e.g. set color/layer/linetype etc.), than we want to start the normal "line command".. afterwards we have to reset changed variables...

The "SendCommand" is asynchron, so if we reset the variables right after the SendCommand, the reset will be done before line is created :-(

How can we handle this?

regards,
Peter

Comments

  • You can use a command reactor for this. It can be used both for setting up your 'special stuff' and for resetting.

  • Hi,

    thanks - now the main question is how to start the normal "LINE" command within my .Net code (the sendstringtoexecute doesn't work, because its not synchronized, so the commandended of my own command will be triggered before command start of line is triggered)

    regards,
    Peter

  • In your callback you should be able to check for the name of the command that has ended (or failed or been cancelled).

  • The problem is how to start command and wait for user input with c#

    In c++ the code below waits for user input and continue work after Line-command is finished (and the line will be drawn on Layer "TEST_LAYER")

    1) set layer to "TEST_LAYER" and save original layer
    2) start Line command:
    bool bCmdIsActive = true;
    int lv_iRc = acedCommand(RTSTR, _T("._LINE"),
    RTSTR, PAUSE,
    RTNONE);
    while (iRc == RTNORM && lv_bCmdIsActive)
    {
    iRc = acedCommand(RTSTR, PAUSE, RTNONE);

    CString szCmd = T("");
    struct resbuf rb;
    if (ads_getvar(_T("CMDNAMES"), &rb) != RTNORM)
    {
    iRc = RTERROR;
    }
    else
    {
    szCmd = rb.resval.rstring;
    //rb.resval.rstring = free(rb.resval.rstring);
    }
    szCmd.ReleaseBuffer();
    szCmd.Trim(_T(".
    "));
    if (szCmd == szCmp)
    lv_bCmdIsActive = true;
    else
    lv_bCmdIsActive = false;
    }
    3) reset layer to original value

    In c# the Docuemnt.SendCommand("._LINE") seems to send the command to the command line (and executed asynchron later on) ,
    follow code will be executed before line command is started (so the layer is switched back before line is created!!!)

    How can I handle this inside c#?

    regards,
    Peter

  • Roy Klein Gebbinck
    edited March 2017

    In your code you are waiting for the command to finish (using the 'pause' approach) instead of using SendCommand.
    I do not use C# myself but in Lisp that approach will also work:
    (defun c:Line_Red ( / *error* doc oldCecolor) (defun *error* (msg) (setvar 'cecolor oldCecolor) (vla-endundomark doc) (princ msg) (princ) ) (vl-load-com) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vla-endundomark doc) (vla-startundomark doc) (setq oldCecolor (getvar 'cecolor)) (setvar 'cecolor "1") (command "_.line") (while (/= (logand (getvar 'cmdactive) 3) 0) (command pause) ) (setvar 'cecolor oldCecolor) (vla-endundomark doc) (princ) )

This discussion has been closed.