Share
 
 

General Access

The most general of the functions that access AutoCAD are acedCommand() and acedCmd(). Like the (command) function in AutoLISP, these functions send commands and other input directly to the AutoCAD Command prompt.

int acedCommand(int rtype, ...);

int acedCmd(const struct resbuf * rbp);

Unlike most other AutoCAD interaction functions, acedCommand() has a variable-length argument list: arguments to acedCommand() are treated as pairs except for RTLE and RTLB, which are needed to pass a pick point. The first of each argument pair identifies the result type of the argument that follows, and the second contains the actual data. The final argument in the list is a single argument whose value is either 0 or RTNONE. Typically, the first argument to acedCommand() is the type code RTSTR, and the second data argument is a string that is the name of the command to invoke. Succeeding argument pairs specify options or data that the specified command requires. The type codes in the acedCommand() argument list are result types.

The data arguments must correspond to the data types and values expected by that command's prompt sequence. These can be strings, real values, integers, points, entity names, or selection set names. Data such as angles, distances, and points can be passed either as strings (as the user might enter them) or as the values themselves (that is, as integer, real, or point values). An empty string (“”) is equivalent to entering a space on the keyboard.

Because of the type identifiers, the acedCommand() argument list is not the same as the argument list for the AutoLISP®(command) routine. Be aware of this if you convert an AutoLISP routine into an ObjectARX® application.

There are restrictions on the commands that acedCommand() can invoke, which are comparable to the restrictions on the AutoLISP (command) function.

Note: The acedCommand() and acedCmd() functions can invoke the AutoCAD SAVE or SAVEAS command. When they do so, AutoLISP issues a kSaveMsg message to all other ObjectARX applications currently loaded, but not to the application that invoked SAVE. The comparable code is sent when these functions invoke NEW, OPEN, END, or QUIT from an application.

The following sample function shows a few calls to acedCommand().

int docmd() 
{ 
    ads_point p1; 
    ads_real rad; 
    if (acedCommand(RTSTR, "circle", RTSTR, "0,0", RTSTR, 
        "3,3", 0) != RTNORM) 
        return BAD; 
    if (acedCommand(RTSTR, "setvar", RTSTR, "thickness", 
        RTSHORT, 1, 0) != RTNORM) 
        return BAD; 
    p1[X] = 1.0; p1[Y] = 1.0; p1[Z] = 3.0; 
    rad = 4.5; 
    if (acedCommand(RTSTR, "circle", RT3DPOINT, p1, RTREAL, 
        rad, 0) != RTNORM) 
        return BAD; 
    return GOOD; 
}

Provided that AutoCAD is at the Command prompt when this function is called, AutoCAD performs the following actions:

  1. Draws a circle that passes through (3.0,3.0) and whose center is at (0.0,0.0).
  2. Changes the current thickness to 1.0. Note that the first call to acedCommand() passes the points as strings, while the second passes a short integer. Either method is possible.
  3. Draws another (extruded) circle whose center is at (1.0,1.0,3.0) and whose radius is 4.5. This last call to acedCommand() uses a 3D point and a real (double-precision floating-point) value. Note that points are passed by reference, because ads_point is an array type.

Was this information helpful?