Common Methods in ObjectARX C ++

Source: Internet
Author: User
Tags xform

3.8 select an object in AutoCAD
1.Ads_name[Still this name in AutoCAD 2000], acdbnameset () [ads_name_set ()], acdbnameequal () [ads_name_equal ()], acdbnameclear () [ads_name_clear ()], acdbnamenil () [ads_name_nil ()]
In ads, adsrx, or ObjectARX, the method for selecting objects does not change, but some function names are changed in ObjectARX 2000 (other function names are not changed, the data type and DCL dialog box discussed in chapter 6th are also similar ).

 

We will introduce a new data type: ads_name. This type of data is used to save the results of successfully selected objects. Generally, the object is selected
Users can obtain and modify the object features. The old ads and modern API ObjectARX are completely different. Before discussing the differences between ADS and ObjectARX in acquiring object data, let's take a look at the definition of ads_name.
The ads_name data type isArray of two long ElementsTherefore, you cannot use the value assignment operator to make an ads_name object equal to another ads_name object. This is similar to the ads_point data type mentioned above. Just like the ads_point data type,

AutoCAD provides a macro named acdbnameset () to make an ads_name object equal to another ads_name object.

ADS/adsrx provides many macros to process ads_name objects. To make an ads_name object equal to another ads_name object, you can use the acdbnameset () Macro.

To determine whether two ads_name objects are equal, you can use the acdbnameequal () Macro.

To assign a null value (null) to an ads_name object, you can use the acdbnameclear () Macro. To test whether the value of an ads_name object is valid, use the acdbnamenil () Macro.

 

2.Acedentsel ()[Ads_entsel ()], acdbentget () [ads_entget ()], acdbentmod () [ads_entmod ()], acdbentupd () [ads_entupd ()]
Remember that the selection set is also an ads_name object (I know this may cause a lot of confusion ). We will soon discuss the selection set. As mentioned above, ads and ObjectARX are completely different in obtaining and changing object data. We will discuss the ObjectARX method in the following sections.

In adsrx, use the acdbentget () function to obtain object data, and use the acdbentmod () and acdbentupd () functions to modify and update objects. The following are the definitions of these functions:
The entity selected using the acedentsel () function will be associated with the ads_name object. Before discussing the acedentsel () function in detail, let's talk about acdbentget (), acdbentmod (), and acdbentupd () functions.

 

Acdbentget ()The function returns a single-chain table in the result buffer. You can use the rbnext field of the resbuf object to traverse and detect the linked list of the result buffer. If Rb is a resbuf result buffer, the syntax is as follows:
You can also change the values in some result buffers. After the final result is complete, call the acdbentmod () function to modify the internal data of the object. As you can see, this function requires a resbuf object. You can use

The acdbentupd () function is used to observe the modification effect of each acdbentmod () function call. In essence, adsrx is used to process the linked list of the result buffer. The ObjectARX method is completely different from this method, and the difference is huge. For users with large amounts of old data, because of adsrx, these functions can still be used in ObjectARX (Autodesk put ads in ObjectARX ). Since this book is about ObjectARX, the discussion of acdbentget (), acdbentmod (), and acdbentupd () functions ends here.

Return to the acedentsel () function because it is still widely used in ObjectARX. The definition of the acedentsel () function is described as follows:
The acedentsel () function stops running and waits for user input. The entity name is returned in entres, and the point used by the selected entity is returned in ptres. The STR parameter specifies the string displayed before the acedentsel () function is paused. The STR parameter is optional. If it is null, AutoCAD displays the default prompt "select objects :". When you specify a complex entity to respond to the acedentsel () function, the title of the multiline or block is returned. If the acedentsel () function is successfully called, rtnorm is returned. If the call fails, rterror is returned. If you cancel the call (Press ESC), rtcan is returned. The acedentsel () function can be used with the acedinitget () function, as shown in the previous example.Code. How is the acedentsel () function used in ObjectARX? AutoCAD uses graphs as databases for processing. Each entity in each open AutoCAD drawing has a unique AutoCAD database object ID associated with it. With the ID number of the object, we can open the AutoCAD entity to determine the type of entity to be processed. Then we can use the object acquisition and setting method (function) to operate the object. Once an ads_name object is available, we can obtain the ID of the associated AutoCAD database object (Data Type: acdbobjectid ).

The following is the function definition for obtaining an AutoCAD database object ID: The ads_name object is the result of the success of selecting an object using the acedentsel () function.
The following is a piece of ObjectARX code using the acedentsel () function: This function returns the acdbentity pointer with the pent. note how to use the acedentsel () function to select an AutoCAD entity.

3.Acdbentlast() [Ads_entlast ()], acednentsel () [ads_nentsel ()], acednentselp () [ads_nentselp ()]
There are several other entity selection functions in ads: acdbentlast (), acednentsel (), and acednentselp ().

Take a look at the acdbentlast () function. AutoCAD always knows the recently generated object, which can be found through the acdbentlast () function. The acdbentlast () function is defined as follows:
The acdbentlast () function finds the nearest entity in the graph, and stores the most recent (undeleted) primary entity name in the graph database into the result. It can be selected even if the nearest object is outside the screen or on a frozen layer. The most recent entity refers to the recently created entity, soThe acdbentlast () function can be used to obtain the entity name of the entity just added to the AutoCAD database.If the acdbentlast () function is successfully called, rtnorm is returned; otherwise, rterror is returned.

For complex entities with blocks and multi-segment lines, ADS FunctionsAcednentsel () and acednentselp ()(Representing the selection of nested entities) Select attributes (assuming that a block entity is selected and the attributes of the block have been defined) and vertex information (assuming that a multiline is selected ). Compared with the acednentsel () function, Autodesk recommends the acednentselp () function. The acednentselp () function adds updated content than the acednentsel () function, so we only discuss the acednentselp () function.

Below isAcednentselp ()Function Definition: this is a complex function with many parameters. The acednentselp () function pauses running and waits for user input. It returns an entity name (saved to entres) and a vertex (saved to ptres) used to select an entity ). The value of pickflag is false or true, which is used to specify whether the acednentselp () function can interact with humans (that is, allows users to select the point corresponding to the input point ). If the value of pickflag is false, the acednentselp () function prompts you to specify an object. The initial value of the ptres parameter is ignored. If the value of pickflag is true, the initial value of ptres is used to select an object. I have almost never used pickflag to be true. For details about other parameters, see adsrx. If STR is null, AutoCAD uses the standard "select objects: |"
Prompt. The parameter I'm most interested in is entres, which stores one vertex or attribute.

3.9 applications Program Further analysis of the key points of the Instance
The acedgetxxx () class function is used after the first circle is created in the application instance maid. Now let's take a look at these functions. In the while loop, we ask whether you need to draw another circle. As long as the user does not answer "no", it will constantly ask the user to draw circles. Let's take a look at the first two rows of the while loop:
The keyword table in the acedinitget () function is "Yes No". The first parameter is null, so we can accept null input. We could have used rsg_nonull to force users to enter "y" or "N ". In general, the default options of AutoCAD are represented by Angle brackets. Here is <Yes>. If you enter "Y", the kW value of the string is "yes ". If you enter "N ",
", The kW value will be" no ". However, if you press enter only, KW is an empty string. In this case, the rtnone case of the switch statement is used to copy "yes" to the kW buffer zone. Remember that the acedinitget () function only applies to the acedgetxxx () class function that follows it. When you run the application again, try to enter some letters that are not "y" or "N ".
Generated. You will receive a prompt repeatedly until you press y, N, or enter.
If you want to draw a circle, the program will go to the else branch of the IF statement and ask the user to select the center of the circle, as shown in the following code:
Here, rsg_nonull is used to call the acedinitget () function, because we need to select a center. In the next acedgetpoint () function call, note that the first parameter is null. Remember that in the acedgetpoint () function, the first parameter can be used as a reference point for selecting a vertex. This is the first point, so we use null. If you want to select the center of the circle, try to press ENTER
Key, and the system will prompt you to select the center of the circle again.
When the circle radius is input, we use the acedgetdist function to replace the acedgetpoint () function, because the response of the acedgetdist function allows us to select a point or enter a distance value from the keyboard. The following code uses the acedgetdist () function:
Note how to use the combination of rsg_nonull, rsg_nozero, and rsg_noneg to call the acedinitget () function. This is because we need to use the acedgetdist () function that follows the setting of the acedinitget () function. The first parameter in the acedgetdist () function is CP, which is the previously selected point. A rubber band line is drawn from the point CP. After the second point is selected
The distance from the point CP to the second point is saved to the variable rad, which is a variable of the ads_real data type. However, you can also press a value on the keyboard. We do not allow zero and negative input, which is why rsg_nozero and rsg_noneg are also included when the acedinitget () function is called.
In the User-Defined printentinfo () function with an ads_name parameter, we call the acdbentget () function to retrieve the result buffer list. If the call is successful, the result buffer linked list contains the data structure of the object, as shown in the following code segment:
We use the rbent-> rbnext field to traverse the table and check the value of the rbent-> restype field. This field indicates the Data Type stored in the rbent-> resval field.

3.10 select set
A selection set is a set of objects in the current drawing of AutoCAD. It is referenced by the name. Here it is an ads_name object. The select set is very similar to the "Group" of the AutoCAD entity )". Once you have a selection set, you can determine the number of entities that constitute the selection set (also known as the selection set length reference ). Now that we know the length of the set, we can use the Loop Mechanism to traverse each object in the set and read and modify the object. An object can only be represented once in one selection set. However, an object can belong to multiple selection sets. If we have a select set SS1 and want to add a straight line object to the select set, we can manually select a straight line object. Based on the rule, we can select a straight-line Object multiple times, but the object selected multiple times in the selection set is represented only once. Assuming that we create the second select set ss2 and select the same straight line object, the object is added to the second select set. Currently, linear entities appear in the SS1 and ss2 sets, but linear entities are expressed only once in each set.
The select set is a famous set of objects. The objects in the select set are manually selected by the AutoCAD user or added based on the object characteristics. Select an object based on the features. For example, select all circles with a radius less than 0.25 on the "parts" layer, which allows us to change their radius to 0.375. Select a set or even an object on a frozen layer. The selection set can also be empty-it is just a container for storing AutoCAD entities, just like a paper bag with candy. If you haven't put candy in it or you have eaten all of them, the paper bag is empty. Table 3-6 lists the ads functions used to process the selected set.
Table 3-6 ADS selection set function
Select the Autolisp function that is equivalent to the set function description.
Acedssget () Select the entity ssget to be added to the selection set
Acedsslength () Returns the length of the specified set sslength.
Acedssadd () Add an object to an existing selection set or create an empty selection set ssadd
Acedssdel () Delete An entity ssdel from an existing Selector
Acedssname () Retrieve the ads_name ssname of the object in the selection set
Acedssmemb () Test whether an object is a member of the selected set ssmemb.
Acedssfree () Release select set-

1. acedssget () [ads_ssget ()]
The selection set is an ads_name object. To add an object to a specified selection set, you must use the acedssget () function to select an object. Or, if you know the object name in advance, you can use the acedssadd () function.

The following is the definition of the acedssget () function: The acedssget () function returns a selection set, which is obtained when an AutoCAD selection mode is specified, the selection mode can be specified through the prompt of the AutoCAD user or filtering the graphic database. There are multiple ways to use the acedssget () function. First, we will describe the parameters in the function, and then describe various methods to use the acedssget () function.
The STR parameter is an optional string that specifies the object selection mode. The pt1 and pt2 Parameters specify the optional points of the selection mode. For polygon or fence selection mode options, the pt1 parameter can also be a result buffer linked list containing multiple points. The filter parameter is an optional result buffer linked list that enables the acedssget () function to filter graphics to select entities with certain types and/or characteristics. No matter which mode you use to obtain the selection set, the parameter SS is used to identify the name of the selection set. The STR parameter specifies which selection mode to use. It can be one of the strings listed in Table 3-7.
From table 3-7, we can see that there are multiple selection modes for the set. If you want to explore all the options, refer to the help documentation. Generally, I only do two things: Let the user select an object (null option) or select an object ("X" option) based on the feature ).
Below are some representative program codes that call the acedssget () function. As shown in the acutbuildlist () function call example, points listed by the polygon options CP and WP (but not f) are automatically closed without specifying the end point as the start point.
Table 3-7 Select mode options of the acedssget () function : Str Value
Value (select mode) Description
Null single-point selection (specify pt1) or user selection (pt1 is also null)
"I" specifies the pickfirst entity set
"C" crossing selection mode
"CP" crossing polygon selection mode
"F" fence (or open polygon) selection mode
"L" last selection mode, select the recently generated entity
"P" previous selection mode, select the previous selection set
"W" window selection mode
"WP" window polygon selection mode
"X" is only used to filter selection modes
"G" groups selection mode
": $" Prompts supplied selection mode
":?" "Other" callbacks selection mode
": D" duplicates allowed selection mode
": E" everything in Aperture selection mode
": K" keyword callbacks selection mode
": N" nested selection mode
": S" single object selection mode
"." User selection mode
"#" Non-geometric selection mode (all, last, previous)
"A" All selection mode
"B" box selection mode
"M" multiple selection mode

3.10.1 select set filtering
to use the select set filtering mode, the STR parameter must be set to "X ". The select set filtering mode allows you to select entities based on features. The filter parameter is a result buffer table. Here, the acedssget () function details the object types and feature types to be used. If the filter parameter is null and the STR parameter is "X", the Select set SS will contain each
entity in the current AutoCAD image, regardless of whether the object is on the frozen layer. Function call:
the current select set SS contains every entity in the current AutoCAD image. So how do we select all the circular entities in the database? To effectively use the selection set, you must know the DXF group code. First, we must construct a result buffer, but because we only look for one entity, we can use the acutnewrb () function to create the result buffer. The following is a piece of code
example:
The following program code instance generates a selection set composed of all the entities on a layer. The DXF group code of the layer is 8.
well, let's take a slightly more complex example. Suppose we want to select all circles on the "parts" layer. This is an instance that uses the acutbuildlist () function to construct the result buffer table and then transmits it to the acedssget () function.

3.10.2 select set link filtering
Relational operators can be used in the selection set. For example, we need to select all circles with a radius greater than or equal to 2.0 on the "parts" layer. By default, the acedssget () function selects entities that meet all the criteria in the filter table. When filtering, the implicit relationship between each two items is "equal )". For numeric group codes (integers, real numbers, points, and vectors ), you can specify other relational operations by using the special group code "-4" that contains a descriptive relational operator in the result buffer. This operator is applied to the result buffer that follows it. Relational operators are specified by strings. Table 3-8 lists all Relational operators.
Relational operators can be well illustrated by examples. In the following example, select all circles with a radius greater than or equal to 2.0 on the "parts" layer. The program code is as follows:
Table 3-8 select the relational operator of the Set filter table
relational operator description
"*" arbitrary (always true)
"=" equals
"! = "Not equal to (C/C ++)
"/= "not equal to (AutoLISP)
"<>" is not equal to
"<" less than
"<=" less than or equal to
">" greater than
"> =" greater than or equal to
"&" bitwise "and" (only used for integer group codes)
"& =" equals to (only used for integer group codes)

3.10.3 filter conditions of the selected set
In addition to link testing, we can also use conditional operators. Table 3-9 lists all selection set conditional operators.
Table 3-9 conditional operators for filtering tables in a select set
Content termination operator in the beginning Operator
"<And" one or more operation objects "and>"
"<Or" one or more operation objects "or>"
"<XOR": two operation objects: "XOR>"
"<Not" an operation object "not>"
The conditional operator of the select set allows us to select a set like all circles with a radius of 1.0 in the graph and all lines on the "parts" layer. The code after programming is as follows:
In this example, the relationship filtering and conditional filtering of the selected set are helpful.

3.10.4 select an extended Entity Data Filtering set
Since R11, AutoCAD has a mechanism to add data to objects, called xdata ). I am not going to discuss in depth how to expand object data, because a new mechanism named xrecords has been introduced in AutoCAD R14 and later versions since AutoCAD R13 C4a, this will be discussed in later chapters. Extended object data is usually the text string, value, 3D point, distance, layer name, or other data appended to an object by an external application. The size of extended data is 16 KB per entity. Note that xrecords is not attached to any entity. Therefore, the existence of xrecords does not require the existence of an object. You can search extended data by using the-3 group code to mark the specified application name in the filter table. The acedssget () function returns an entity set that registers extended data with a specific name. The acedssget () function does not retrieve a single extended data item (the Group Code range is 1000 ~ 2000 ).
The following is a code segment for selecting all objects. All objects have extended data registered with the app ID "appname": There are still a lot of information about extended object data in the adsrx document, however, because xrecords is used in AutoCAD R14 and later versions, we will discuss xrecords in detail in later chapters.

3.10.5 conversion matrix and selection set
acedxformss () [
ads_xformss ()]
using the acedxformss () function, the select set can use the conversion matrix. Using the conversion matrix, you can select objects in a set for ratio, movement, rotation, or image. This can be achieved by calling the acedxformss () function with appropriate matrix element settings, instead of repeating the entire selection set and executing acedcommand ()/acedcmd () function to compare, move, rotate, or mirror each object. Here I don't want to fully discuss matrix math. ObjectARX has defined the numerical functions used to process matrix algebra (see acgematrix2d and acgematrix3d matrix operation classes ). As mentioned above, the conversion matrix is a 4 × 4 level array with the ads_real data type. The first three columns of the matrix determine the ratio and rotation, and the fourth column is a translation vector. The value of the last row of the matrix must be [0 0 0 1]. The function that passes the ads_matrix parameter ignores this value. Adsrx defines the symbol t for the translation operation, as shown below:

The acedxformss () function is defined as follows: The acedxformss () function applies a conversion matrix genmat to the selection set specified by ssname. The genmat parameter is a 4× 4th matrix. If genmat does not have an even ratio, the acedxformss () function returns rterror. Applying a conversion matrix to a selection set is a method of changing the ratio, rotating, or moving an object in the selection set without using the acedcommand (), acedcmd (), or acdbentmod () function. If the acedxformss () function is successfully called, rtnorm is returned; otherwise, rterror is returned.
The following is a program code for initializing the matrix:
In the above function, we use a nested for loop to initialize the parameter ID of the ads_matrix type (the value of each element is 0 ), then, a for loop is used to initialize the elements 0, 0, 1, 2, 3, and 3 to set the value to 1. Now the matrix is initialized as a constant matrix. Observe the following translation matrix determined by Tx, Ty, and TZ:
Change the values of the first three elements in the fourth column and apply the acedxformss () function. All objects in the selection set will move the appropriate distance along the X, Y, and Z directions. Note: If you only need to move in the X direction, you only need to change the Tx value in the matrix.
When processing the select set and acedxformss () function, all the proportional coefficients must be equal, that is, SX = Sy = Sz. There are other 2D and 3D operations such as rotating matrices (see adsrx and ObjectARX documents ). Now let's take a look at a conversion matrix instance for selecting set operations.
This is the transformation matrix of the selection set. The zooming coefficient in the X, Y, and Z directions is 0.5, and the moving distance of the selection set is (20.0, 5.0 ).
The following is the program code:

3.10.6 select a set
Now that we have seen various methods to create a selection set, let's take a look at the functions that operate these selection sets. Perhaps the first thing we need to know is how many entities constitute the selection set.
1.Acedsslength ()[Ads_sslength ()]
The acedsslength () function returns the number of entities that constitute the selection set.

It is defined as follows: The acedsslength () function returns a long integer Len, indicating the number of objects contained in the sname of the selected set. The result is the number of specific entities. No matter how the set is selected, the set does not contain repeated entities. If the acedsslength () function is successfully called, rtnorm is returned. Otherwise, an error code is returned. The acedsslength () function is usually used with the for loop.
Code:

2.Acedssname ()[Ads_ssname ()]
In the above Code, if the value of the Len variable returned by the acedsslength () function is greater than 0, we can get a specific entity indicated by the long integer variable I in the selection set. You can use the acedssname () function to obtain the object at a specific position in the selected set. Indicates that the sequence number of the object in the selection set starts from 0, and the sequence number of the first object is 0.

The following is the definition of the acedssname () function: The acedssname () function selects the entity whose position number is I in the Set SS, and returns the entity name in entres. The entity starts from 0. Therefore, I must be non-negative and not greater than the sequence number (acedsslength (SS)-1) of the last entity in the selection set ). The entity name in the selection set obtained using the acedssget () function is always the primary entity name. The acedssname () function cannot obtain the child entity name (for example, the attributes of a block and the vertex of a multi-segment line ). If the acedssname () function is successfully called, rtnorm is returned. Otherwise, an error code is returned.
In the past, for ads and selection sets, the acedsslength () function returns the length of the selection set. Once the length of the set is available, you can use the for loop to select the set and use the acedssname () function to obtain the object name. Once an object name is available, you can use the acdbentget () function to obtain the object data. This function returns the object data in the form of a linked list in the result buffer. Then, you can modify the result buffer table and call the acdbentmod () function to change the object database. If necessary, you can call the acdbentupd () function to update the object expression. As mentioned above, ObjectARX provides a better mechanism for processing entity databases, some of which have been hinted at in the above Code segment. Now we tend to stop using the acdbentget (), acdbentmod (), and acdbentupd () functions. However, we still use the selection set.

3.Acedssfree ()[Ads_ssfree ()]
In the last line of the above Code segment, the acedssfree () function is called. When processing the selected set, it is important to release the selected set after the operation is complete, because AutoCAD can only open a limited number of selected sets at the same time (up to 128 ).

The following is the definition of the acedssfree () function: The acedssfree () function releases the selection set specified by sname. The selection set must be obtained by calling the acedssget () or acedssadd () function in advance. We will discuss the acedssadd () and acedssdel () functions later.
The adsrx application cannot open more than 128 selection sets at the same time. If this limit is reached, AutoCAD rejects the creation of more selection sets. At the same time, we do not recommend using a large number of selection sets. Maintain a reasonable number of selection sets and call the acedssfree () function to release useless selection sets. If the acedssfree () function is successfully called, rtnorm is returned. Otherwise, an error code is returned.

4.Acedssadd ()[Ads_ssadd ()]
The acedssadd () function creates a new selection set or adds an object to an existing selection set.

The acedssadd () function is defined as follows: the parameter ename specifies an object, and the sname specifies a selection set. If both ename and sname are null, The acedssadd () function creates a new selection set without an object (you can add an empty selection set for an object later). Its name is set by result. If ename is a valid object, but sname is null, The acedssadd () function creates a new selection set, which contains an entity ename and the Set Name Is result. If ename specifies a valid object and sname specifies an existing selection set, the acedssadd () function adds the object ename to the selected set specified by sname. In all cases, the acedssadd () function sets the result to the name of the newly created or updated set. If the entity specified by ename has already been in the selection set specified by sname, The acedssadd () function does not consider such requests or report errors. The sname and result parameters can specify the same selection set. This is the most intuitive way to add an object ename to an existing selection set. Call the acedssadd () function and call the acedssfree () function to release each selection set created with the sname parameter null. This also applies to the null selection set (when the ename is also null ). If the acedssadd () function returns an error code, no new selection set is created. If the acedssadd () function is successfully called, rtnorm is returned. Otherwise, an error code is returned.

5.Acedssdel ()[Ads_ssdel ()]
Use the acedssdel () function to delete objects from an existing selector. The acedssdel () function is defined as follows:
The acedssdel () function removes the entity specified by the ename from the selected set ss. The Object Name and select set name must be valid for the current image.
6. acedssmemb () [ads_ssmemb ()]
Finally, the acedssmemb () function can be used to check whether an object is in an existing selection set. The acedssmemb () function is defined as follows:
The acedssmemb () function tests whether the entity ename is a member of the selection set ss. The Object Name and select set name must be valid for the current image. If the acedssmemb () function finds the ename, rtnorm is returned. If not, rterror is returned.

3.11 data type conversion functions
Sometimes the data type is required to be converted, especially when the acutprintf () function is used to prompt the user in the command line. Table 3-10 lists ads conversion functions.
Table 3-10 common ads conversion functions
Description
Acdbrtos () converts the value of the ads_real type to a string.
Acdbangtos () converts an angle to a string by format
Acuttoupper () converts characters to uppercase letters
Acuttolower () converts characters to lowercase letters
Acedtrans () converts a point or shift from one coordinate system to another.
1. acdbrtos () [ads_rtos ()]
The acdbrtos () function is defined as follows:
The acdbrtos () function converts Val to a string in the format set by unit and prec (precision). The result is put into Str. Str must point to a buffer that can hold a formatted string. The Unit parameter selects the Unit System of the converted string. The value must conform to the value range allowed by the lunits of the AutoCAD System variable (1 ~ 5. See "system variables" in AutoCAD online help "). If UNIT
The value is-1, and the acdbrtos () function uses the current value of lunits. The prec parameter selects the number of decimal places contained in the string. If the prec value is-1, the acdbrtos () function uses the current value of the AutoCAD System variable luprec. The current value of the AutoCAD dimension variable dimzin controls whether the acdbrtos () function writes the leading zero and ending zero into Str. If the acdbrtos () function is successfully called
, Returns rtnorm; otherwise, an error code is returned.
2. acdbangtos () [ads_angtos ()]
The acdbangtos () function is defined as follows:
The acdbangtos () function converts V to a string in the format set by unit and prec (precision). The Unit of parameter V is radian, and the result is str, STR must point to a buffer that can hold a formatted string. The size of the string depends on the request mode and precision. Generally, 15 bytes is enough. The Unit parameter selects the unit system after angle conversion, and its value must comply with the AutoCAD System variable Au
Nits value range. In addition, if the unit value is set to-1, the acdbangtos () function uses the current value of aunits. The prec parameter selects the number of decimal places contained in the string. If the value of prec is set to-1, the acdbangtos () function uses the current value of the AutoCAD System variable auprec. The current value of the AutoCAD dimension variable dimzin controls whether the acdbangtos () function
STR is written at the beginning and end with zero. The AutoCAD User Guide describes how to set dimzin values. If the acdbangtos () function is successfully called, rtnorm is returned. Otherwise, an error code is returned.
3. acuttoupper () [ads_toupper ()] and acuttolower () [ads_tolower ()]
The acuttoupper () and acuttolower () functions are defined as follows:
These two functions convert the character parameter (ASCII integer) to uppercase or lowercase characters.
4. acedtrans () [ads_trans ()]
The acedtrans () function is defined as follows:
The acedtrans () function converts coordinate points or displacement from one coordinate system to another. The PT parameter can be interpreted as either a three-dimensional point or a three-dimensional displacement vector. The from parameter specifies the coordinate system of PT, And the to parameter specifies the coordinate system after conversion. If the disp parameter is not equal to 0, PT is considered as a displacement vector, otherwise PT is a point. Description acedt
The best way to use RANS () functions is through examples. The code of the coordinate system used by AutoCAD is: 1 indicates the WCS (World coordinate system), and 2 indicates the current UCS (user coordinate system ). AutoCAD also defines 2 and 3. These values are rarely used. You can refer to the relevant documents.
The following is a program code for converting from the UCS to the WCS:
This is the first program code that does not use the result buffer pointer. If the result buffer type variable is declared as a local variable in the function, it is automatically cleared when the function exits. You do not need to call the acutrelrb () function. However, note that the & operator must be placed before the resbuf variable, because the acedtrans () function requires a pointer (or address) pointing to the resbuf structure ).
3.12 application instance _2
In this application, we demonstrate again the use of acedgetxxx () class functions and the use of select set functions. When cyclically selecting a set, it also demonstrates how to use the result buffer linked list to change the feature of the selected set object. In a pure ObjectARX application, changing the properties of an object is done by the get and set functions in the corresponding object class. Let's first observe
The program code of the application instance, and then the main points are discussed. The content of the file is as follows:
The following table lists the content of the User-Defined command cel's tmp_2commands.cpp file:
3.13 key points of application instance
This application can select a group of entities and change the layers of these entities to the layers of the selected target entities. Although similar commands already exist in AutoCAD R14/2000, all I want to explain is the use of the selection set. In this application, you are required to select the entity that makes up the selection set srcss, as shown below:
Then, call the acedentsel () function to select the target object, as shown below:
If everything is normal, the User-Defined chgentslyr () function will be called to implement all the actions of the program. This function requires two parameters: one is an entity and the other is a selection set. Note that they are all data of the ads_name type. We must extract the data of the target object. This can be achieved by calling the acdbentget () function, which returns the result buffer pointed to by the pointer rbtargent.
Partition list. We use the result buffer pointer rbtrav to traverse the linked list. Here, we extract the layer name and copy it to lyrname. Do not use the result buffer pointer rbtargent to traverse the linked list, because after this operation, the memory allocated by the acdbentget () function cannot be released-a typical Memory leakage error, which is extremely common. The next step is to use the acedsslength () function to get the selection
The length of the set, and then enters the for loop. In the for loop, use the acedssname () function to obtain the Object Name and return it in ssentname. We use the result buffer pointer rbtrav to traverse the linked list again. When the result buffer of the layer is reached, change the value of rbtrav-> resval. rstring to lyrname. Note why we use the acdbentmod (rbssent) function to update the instance
Body. The result buffer rbssent is used to update the object because rbssent is the result buffer linked list, And rbtrav is only used to traverse the result buffer pointer of the linked list. Release the rbssent buffer before the for loop starts the next round. Once returned from a function call, call the acedssfree () function before exiting the application. Don't forget to release the selection set.
3.14 application instance
This application demonstrates how to use the ads_matrix data type matrix for the selection set and the selection set function acedxformss () for operations on the ads_matrix data type (). Matrix can be used to perform proportional transformation, rotation, mirroring, and translation, and rotate around X, Y, or Z axes. In this application, we only show the proportional transformation. The content of the file is as follows:
The following table lists the content of the User-Defined command TSS's tmp_3commands.cpp file:
3.15 analysis of key points of application instance
In the TSS () (conversion select set) function, there is an ads_matrix Data Type Variable XForm and a selection set ssgrp. Use the acedssget () function to request the user to select a group of entities. If the selection is successful, the entity is placed in the ssgrp of the selection set. Then, use the acedgetreal () function to request the user to input a proportional coefficient. note how we initialize the acedinitget () function.
. Since we have an effective selector set and a proportional coefficient, we can call the User-Defined ident_init () function initialization matrix, which is a nested for loop, initialize all matrix elements to 0.0. Then, we use a for loop to initialize the elements on the diagonal lines of the first three columns to 1.0. Elements initialized as 1.0 are ID [0] [0], Id [1] [1], and Id [2] [
2]. After matrix initialization, we use the proportional coefficient in SF to replace the values of these three elements. We do not need to use the for loop to traverse the selection set. Simply call the acedxformss (ssgrp, XForm) function, which will change the proportional coefficient of all objects in the selection set. There are many matrix conversion operation functions in the geometric class acge of ObjectARX.
There are a lot of ads functions I have not covered (or not discussed in detail), mainly because these functions are designed for ads/C Programming and ObjectARX has its own definition, its programming format is much more sophisticated (not biased ). I have not involved the ads functions: aceddefun (), acedgetfuncode (), acedregfund (), acedinvoke (), acedgetargs (), acdbentdel (), acdben
Tmod (), acdbentnext (), acdbentget (), acdbentupd (), and acdbhandent. The adsrx function I have discussed is the most likely function to be used in ObjectARX.
We already have the basic knowledge of adsrx. Next we will continue to learn chapter 4th. By understanding the database and object structure of AutoCAD, we will start to explore ObjectARX.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.