![]() |
【转帖】objectarx&dummies教程(九)—— interacting with autocad
objectarx&dummies教程(九)—— interacting with autocad
objectarx&dummies教程(九)—— interacting with autocad class 9 - interacting with autocad hello, on the last class i have presented how to perform selection sets. this class i will show how can you interact with autocad using global functions and acquiring information such as numbers, coordinates, system variables and much more. invoking commands objectarx provide us two global functions that allows us to invoke registered commands. this functionality is very handy and will help users to perform quick operations that don't require complex procedures. even this method is quite simple you should avoid using it in complex and huge operations. this method may also create problems when dealing with events handling. the two provided functions are acedcmd() and acedcommand(). the first one invokes the command through a passed in resbuf list which will inform all command parameters. the second function will receive a variable number of parameters which will reproduce the way you fire the command from the prompt interface. below are these functions signature: int acedcmd(const struct resbuf * rbp); int acedcommand(int rtype, ... unnamed); to build the resbuf list when using acedcmd() there is a utility function called acutbuildlist() which constructs this linked list easily. you just need to pass paired values with codes that describe the types and end the list with a 0 or rtnone value. another good practice is to clear the command prompt, calling acedcommand(rtnone) , after issued the command. don't forget to free memory used, when using resbuf pointers, through the acutrelrb() utility function to avoid memory leaks. there are several ways to use theses functions and i will show some of them below: acedcmd(): a) moving the last created entity based on (0,0,0): ads_point pt; pt[0] = pt[1] = pt[2] = 0.0; struct resbuf *mv; mv = acutbuildlist(rtstr,"_move",rtstr,"_last",rtstr,"", rtpoint,pt,rtstr,pause,0); acedcmd(mv); acedcommand(rtnone); acutrelrb(mv); b) calling a "redraw" native command: struct resbuf *cmdlist; cmdlist = acutbuildlist(rtstr, "_redraw", 0); acedcmd(cmdlist); acedcommand(rtnone); acutrelrb(cmdlist); acedcommand(): a) calling a zoom command and pausing for user input: acedcommand(rtstr, "zoom", rtstr, pause, rtnone); b) creating both a circle and a line entities: acedcommand(rtstr, "circle", rtstr, "10,10",rtstr, pause, rtstr, "line", rtstr, "10,10", rtstr, "20,20", rtstr, "", 0); system variables your application will probably need to access autocad system variables that can be read or write. objectarx provide two functions to deal with these variables using the resbuf structure to access and/or modify values. the function are called acedgetvar() and acedsetvar() and below are their signatures: int acedgetvar(const char * sym,struct resbuf * result); int acedsetvar(const char * sym,const struct resbuf * val); the first parameter is the variable name the second the resbuf pointer to set / get information. the following example show how to change the fillet radius which is stored through a system variable: struct resbuf rb, rb1; acedgetvar("filletrad", &rb); rb1.restype = rtreal; rb1.resval.rreal = 1.0; acedsetvar("filletrad", &rb1); it is very important that you specify the correct type of resbuf item acquired. in this case, the fillet radius is a real number which is rtreal type. user input functions there are additional global functions to allow interaction with users via command prompt interface. each of these functions could be used alone or with other ones. the following table shows what each function does: acedgetint gets an integer value acedgetreal gets a real value acedgetdist gets a distance acedgetangle gets an angle (oriented to 0 degrees specified by the angbase) acedgetorient gets an angle (oriented to 0 degrees at the right) acedgetpoint gets a point acedgetcorner gets the corner of a rectangle acedgetkword gets a keyword acedgetstring gets a string each of these functions returns a int number as a result code that could be one of the following: rtnorm user entered a valid value rterror the function call failed rtcan user entered esc rtnone user entered only enter rtrej autocad rejected the request as invalid rtkword user entered a keyword or arbitrary text autocad allows you to prevent invalid values when user respond to your input functions. this feature can be made through the acedinitget() function which can receive one or a combination of the following values: rsg_nonull disallow null input rsg_nozero disallow zero values rsg_noneg disallow negative values rsg_nolim do not check drawing limits, even if limcheck is on rsg_dash use dashed lines when drawing rubber-band line or box rsg_2d ignore z coordinate of 3d points (acedgetdist() only) rsg_other allow arbitrary input—whatever the user enters the following example shows how to acquire a value greater than zero: int age = -1; acedinitget(rsg_nonull rsg_nozero rsg_noneg, null); acedgetint("how old are you? ", &age); |
所有的时间均为北京时间。 现在的时间是 10:46 AM. |