Sei sulla pagina 1di 35

Extended Dataxdata [AutoLISP Developer's Guide: ALG]

Pgina 1 de 6

Using the AutoLISP Language

Several AutoLISP functions are provided to handle extended data (xdata), which is created by applications written with ObjectARX or AutoLISP. If an entity contains xdata, it follows the entity's regular definition data. You can retrieve an entity's extended data by calling entget. The entget function retrieves an entity's regular definition data and the xdata for those applications specified in the entget call. When xdata is retrieved with entget, the beginning of extended data is indicated by a 3 code. The 3 code is in a list that precedes the first 1001 group. The 1001 group contains the application name of the first application retrieved, as shown in the table and as described in the following sections.
Group codes for regular and extended data

Group code (1, 2 (0239

Field Entity name) Regular definition data fields) . . . Extended data sentinel Registered application name 1) XDATA fields) . . . Registered application name 2) XDATA fields) . . . Registered application name 3) . .

Type of data Normal entity definition data

) (3 (1001 (1000, 10021071

Extended data

(1001 (1000, 10021071

(1001

Topics in this section:


Organization of Extended Data Registration of an Application Retrieval of Extended Data Attachment of Extended Data to an Entity Management of Extended Data Memory Use Handles in Extended Data

Comments?

Using the AutoLISP Language

file://D:\Documents and Settings\Raul\Configuracin local\Temp\~hh4009.htm

10/08/2005

Extended Dataxdata [AutoLISP Developer's Guide: ALG]

Pgina 2 de 6

Extended data consists of one or more 1001 groups, each of which begins with a unique application name. The xdata groups returned by entget follow the definition data in the order in which they are saved in the database. Within each application's group, the contents, meaning, and organization of the data are defined by the application. AutoCAD maintains the information but does not use it. The table also shows that the group codes for xdata are in the range 10001071. Many of these group codes are for familiar data types, as follows:
String

1000. Strings in extended data can be up to 255 bytes long (with the 256th byte reserved for the null character).
Application Name

1001 (also a string value). Application names can be up to 31 bytes long (the 32nd byte is reserved for the null character) and must adhere to the rules for symbol table names (such as layer names). An application name can contain letters, digits, and the special characters $ (dollar sign), - (hyphen), and _ (underscore). It cannot contain spaces.
Layer Name

1003. Name of a layer associated with the xdata.


Database Handle

1005. Handle of an entity in the drawing database.


3D Point

1010. Three real values, contained in a point.


Real

1040. A real value.


Integer

1070. A 16-bit integer (signed or unsigned).


Long

1071. A 32-bit signed (long) integer. If the value that appears in a 1071 group is a short integer or real value, it is converted to a long integer; if it is invalid (for example, a string), it is converted to a long zero (0L). Note AutoLISP manages 1071 groups as real values. If you use entget to retrieve an entity's definition list that contains a 1071 group, the value is returned as a real, as shown in the following example: (1071 . 12.0) If you want to create a 1071 group in an entity with entmake or entmod, you can use either a real or an integer value, as shown in the following example: (entmake '((..... (1071 . 12) .... ))) (entmake '((..... (1071 . 12.0) .... ))) (entmake '((..... (1071 . 65537.0) .... ))) (entmake '((..... (1071 . 65537) .... ))) But AutoLISP still returns the group value as a real: (entmake '((..... (1071 . 65537) .... ))) The preceding statement returns the following: (1071 . 65537.0) ObjectARX always manages 1071 groups as long integers. Several other extended data groups have special meanings in this context (if the application chooses to use them):
Control String

file://D:\Documents and Settings\Raul\Configuracin local\Temp\~hh4009.htm

10/08/2005

Extended Dataxdata [AutoLISP Developer's Guide: ALG]

Pgina 3 de 6

1002. An xdata control string can be either "{" or "}". These braces enable the application to organize its data by subdividing it into lists. The left brace begins a list, and the right brace terminates the most recent list. Lists can be nested. Note If a 1001 group appears within a list, it is treated as a string and does not begin a new application group.
Binary Data

1004. Binary data that is organized into variable-length chunks, which can be handled in ObjectARX with the ads_binary structure. The maximum length of each chunk is 127 bytes. Note AutoLISP cannot directly handle binary chuncks, so the same precautions that apply to long (1071) groups apply to binary groups as well.
World Space Position

1011. Unlike a simple 3D point, the WCS coordinates are moved, scaled, rotated, and mirrored along with the parent entity to which the extended data belongs. The WCS position is also stretched when the STRETCH command is applied to the parent entity and when this point lies within the select window.
World Space Displacement

1012. A 3D point that is scaled, rotated, or mirrored along with the parent, but not stretched or moved.
World Direction

1013. A 3D point that is rotated or mirrored along with the parent, but not scaled, stretched, or moved. The WCS direction is a normalized displacement that always has a unit length.
Distance

1041. A real value that is scaled along with the parent entity.
Scale Factor

1042. Also a real value that is scaled along with the parent. The DXF group codes for xdata are also described in the DXF Reference.

Comments?

Using the AutoLISP Language

To be recognized by AutoCAD, an application must register the name or names that it uses. Application names are saved with the extended data of each entity that uses them, and also in the APPID table. Registration is done with the regapp function, which specifies a string to use as an application name. If it successfully adds the name to APPID, it returns the name of the application; otherwise it returns nil. A result of nil indicates that the name is already present in the symbol table. This is not an actual error condition but an expected return value, because the application name needs to be registered only once per drawing. To register itself, an application should first check that its name is not already in the APPID table. If the name is not there, the application must register it. Otherwise, it can simply go ahead and use the data, as described later in this section. The following fragment shows the typical use of regapp. (The tblsearch function is described in

Symbol Table and Dictionary Access.)

(setq appname "MYAPP_2356") (if (tblsearch "appid" appname) (princ (strcat

; Unique application name. ; Checks if already registered.

file://D:\Documents and Settings\Raul\Configuracin local\Temp\~hh4009.htm

10/08/2005

Extended Dataxdata [AutoLISP Developer's Guide: ALG]

Pgina 4 de 6

"\n" appname " already registered. ")) (if (= (regapp appname) nil) ; Some other problem. (princ (strcat "\nCan't register XDATA for " appname ". ")) ) ) The regapp function provides a measure of security, but it cannot guarantee that two separate applications have not chosen the same name. One way of ensuring this is to adopt a naming scheme that uses the company or product name and a unique number (like your telephone number or the current date and time).

Comments?

Using the AutoLISP Language

An application can call entget to obtain the xdata that it has registered. The entget function can return both the definition data and the xdata for the applications it requests. It requires an additional argument, application, that specifies the application names. The names passed to entget must correspond to applications registered by a previous call to regapp; they can also contain wild-card characters. By default, associative hatch patterns contain extended data. The following code shows the association list of this xdata.
Command: (entget (car (entsel)) '("ACAD")) Select object: Select an associative hatch

Entering the preceding code at the command line returns a list that looks something like this:
((-1 . <Entity name: 600000c0>) (0 . "INSERT") (8 . "0") (2 . "*X0") (10 0.0 0.0 0.0) (41 . 1.0) (42 . 1.0) (50 . 0.0) (43 . 1.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0) (-3 ("ACAD" (1000 . "HATCH") (1002 . "{") (1070 . 16) (1000 . "LINE") (1040 . 1.0) (1040 . 0.0) (1002 . "}"))))

This fragment shows a typical sequence for retrieving xdata for two specified applications. Note that the application argument passes application names in list form: (setq working_elist (entget ent_name '("MY_APP_1" "SOME_OTHER") ) ) (if working_elist (progn ... (entmod working_elist) ) )

; Only xdata from "MY_APP_1" ; and "SOME_OTHER" is retrieved.

; ; ; ;

Updates working entity groups. Only xdata from registered applications still in the working_elist list are modified.

As the sample code shows, you can modify xdata retrieved by entget by using a subsequent call to entmod, just as you can use entmod to modify normal definition data. You can also create xdata by

file://D:\Documents and Settings\Raul\Configuracin local\Temp\~hh4009.htm

10/08/2005

Extended Dataxdata [AutoLISP Developer's Guide: ALG]

Pgina 5 de 6

defining it in the entity list passed to entmake. Returning the extended data of only those applications specifically requested protects one application from corrupting another application's data. It also controls the amount of memory that an application needs to use and simplifies the xdata processing that an application needs to perform. Note Because the strings passed by application can include wild-card characters, an application name of "*" will cause entget to return all extended data attached to an entity.

Comments?

Using the AutoLISP Language

You can use xdata to store any type of information you want. For example, draw an entity (such as a line or a circle), then enter the following code to attach xdata to the entity: (setq lastent (entget (entlast))) ; Gets the association ; list of definition data ; for the last entity. (regapp "NEWDATA") ; Registers the ; application name. (setq exdata ; Sets the variable '((-3 ("NEWDATA" ; exdata equal to the (1000 . "This is a new thing!") ; new extended data ))) ; in this case, a text ) ; string. (setq newent (append lastent exdata)) ; Appends new data list to ; entity's list. (entmod newent) ; Modifies the entity with the new ; definition data. To verify that your new xdata has been attached to the entity, enter the following code and select the object: (entget (car (entsel)) '("NEWDATA")) This example shows the basic method for attaching extended data to an entity.

Comments?

Using the AutoLISP Language

Extended data is currently limited to 16K per entity. Because the xdata of an entity can be created and maintained by multiple applications, problems can result when the size of the xdata approaches its limit.

file://D:\Documents and Settings\Raul\Configuracin local\Temp\~hh4009.htm

10/08/2005

Extended Dataxdata [AutoLISP Developer's Guide: ALG]

Pgina 6 de 6

AutoLISP provides two functions, xdsize and xdroom, to assist in managing the memory that xdata occupies. When xdsize is passed a list of xdata, it returns the amount of memory (in bytes) that the data will occupy. When xdroom is passed the name of an entity, it returns the remaining number of free bytes that can still be appended to the entity. The xdsize function reads an extended data list, which can be large. This function can be slow, so it is not recommended that you call it frequently. A better approach is to use it (in conjunction with xdroom) in an error handler. If a call to entmod fails, you can use xdsize and xdroom to find out whether the call failed because the entity didn't have enough room for the xdata.

Comments?

Using the AutoLISP Language

Extended data can contain handles (group 1005) to save relational structures within a drawing. One entity can reference another by saving the other's handle in its xdata. The handle can be retrieved later from xdata and then passed to handent to obtain the other entity. Because more than one entity can reference another, xdata handles are not necessarily unique. The AUDIT command does require that handles in extended data either be NULL or valid entity handles (within the current drawing). The best way to ensure that xdata entity handles are valid is to obtain a referenced entity's handle directly from its definition data by means of entget. The handle value is in group 5. When you reference entities in other drawings (for example, entities that are attached with XREF), you can avoid protests from AUDIT by using extended entity strings (group 1000) rather than handles (group 1005). The handles of cross-referenced entities are either not valid in the current drawing, or they conflict with valid handles. However, if an XREF Attach changes to an XREF Bind or is combined with the current drawing in some other way, it is up to the application to revise the entity references accordingly. When drawings are combined by means of INSERT, INSERT*, XREF Bind (XBIND), or partial DXFIN, handles are translated so they become valid in the current drawing. (If the incoming drawing did not employ handles, new ones are assigned.) Extended entity handles that refer to incoming entities are also translated when these commands are invoked. When an entity is placed in a block definition (with the BLOCK command), the entity within the block is assigned new handles. (If the original entity is restored by means of OOPS, it retains its original handles.) The value of any xdata handles remains unchanged. When a block is exploded (with the EXPLODE command), xdata handles are translated in a manner similar to the way they are translated when drawings are combined. If the xdata handle refers to an entity that is not within the block, it is unchanged. However, if the xdata handle refers to an entity that is within the block, the data handle is assigned the value of the new (exploded) entity's handle.

Comments?

file://D:\Documents and Settings\Raul\Configuracin local\Temp\~hh4009.htm

10/08/2005

Datos extendidos [Manual de referencia de DXF: DXF]

Pgina 1 de 3

Los datos extendidos (datoseX) se crean con las aplicaciones AutoLISP y ObjectARX. Si una entidad contiene datos extendidos, figurarn a continuacin de los de definicin normal de la entidad. Los cdigos de grupo comprendidos entre 1000 y 1071 describen los datos extendidos. El siguiente es un ejemplo de entidad con datos extendidos en formato DXF. Datos de definicin de entidad normales: 0 INSERT 5 F11 100 AcDbEntity 8 TOP 100 AcDbBlockReference 2 BLOCK_A 10 0.0 20 0.0 30 0.0 Datos de definicin de entidad extendidos: 1001 AME_SOL 1002 { 1070 0 1071 1.95059E+06 1070 519 1010 2.54717 1020 2.122642 1030 2.049201 1005 ECD 1005 EE9 1005 0 1040 0.0 1040 1.0

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

Datos extendidos [Manual de referencia de DXF: DXF]

Pgina 2 de 3

1000 MILD_STEEL El cdigo de grupo 1001 indica el comienzo de los datos extendidos. Frente a los datos de entidad normales, en el caso de datos extendidos un mismo cdigo de grupo puede aparecer varias veces y el orden es significativo. Los datos extendidos se agrupan por el nombre registrado de la aplicacin. Cada grupo de aplicacin registrada comienza con un cdigo de grupo 1001, con el nombre de aplicacin como valor de la cadena. Los nombres de registro de las aplicaciones corresponden a las entradas de la tabla de smbolos APPID. Una aplicacin puede utilizar tantos nombres de APPID como sean necesarios. Los nombres APPID son permanentes, aunque pueden suprimirse cuando no se utilicen en el dibujo. Cada nombre APPID no puede tener ms de un grupo de datos enlazado con cada entidad. Dentro de un grupo de aplicacin, es la propia aplicacin la que define la secuencia de grupos de datos extendidos y su significado. La siguiente tabla muestra los cdigos de grupos de datos extendidos.
Cdigos de grupo de datos extendidos y sus descripciones

Nombre de entidad Cadena Nombre de aplicacin

Cdigo Descripcin de grupo 1000 1001 tambin un valor de cadena 1002 Las cadenas de datos extendidos pueden tener hasta 255 bytes de longitud (estando reservado el byte 256 para el carcter nulo) Los nombres de aplicacin pueden tener hasta 31 bytes de longitud (el byte 32 est reservado para el carcter nulo). Nota No aada un grupo 1001 a los datos extendidos porque AutoCAD interpretar que es el comienzo de un nuevo grupo de datos extendidos de la aplicacin. Las cadenas de control de datos extendidos pueden ser "{"o "}". Estas llaves permiten a la aplicacin distribuir los datos en listas. La llave de apertura marca el inicio de una lista y la de cierre termina la ltima lista. Las listas pueden estar anidadas. Cuando AutoCAD lee los datos extendidos para una aplicacin concreta, comprueba que todas las llaves de apertura tengan su correspondiente llave de cierre. Nombre de la capa asociada con los datos extendidos Los datos binarios se organizan en bloques de longitud variable. La longitud mxima de cada bloque es de 127 bytes. En los archivos DXF ASCII, los datos binarios se representan como una cadena de dgitos hexadecimales, dos por byte binario. Identificadores de entidades en la base de datos de dibujo Nota Cuando un dibujo con identificadores e identificadores de datos extendidos se importa en otro dibujo con INSERT, INSERT *, Unir REFX, UNIRX o ABRE parcialmente, los identificadores de datos extendidos se traducen de la misma manera que sus identificadores de entidades correspondientes, conservando as su unin. Esto tambin se hace en la operacin de descomposicin de bloques o en cualquier otra operacin de AutoCAD. Cuando REVISION detecta un identificador de datos extendidos que no coincide con el identificador de una entidad del archivo de dibujo, se considera un error. Si REVISION fija las entidades, establece el identificador en 0. Tres valores reales, en el orden X, Y, Z. Pueden tomarse como registro de punto o vector. AutoCAD nunca modifica sus valores. A diferencia de un simple punto 3D, las coordenadas universales se mueven, se giran, se les aplican escalas o se reflejan junto con la entidad original a la cual pertenecen los datos extendidos. La posicin universal tambin se puede estirar cuando se aplica el comando ESTIRA a la entidad original y este punto se encuentra dentro de la ventana de seleccin. Tambin un punto 3D al que se aplica una escala, que se gira y que se refleja junto con la entidad original (pero no se mueve ni se estira) Es tambin un punto 3D que se gira y se refleja junto con la entidad original (pero no se mueve ni se estira ni se le aplica ninguna escala)

Cadena de control

Nombre de capa 1003 Datos binarios 1004

Identificador de base de datos

1005

3 valores reales

1010, 1020, 1030 1011, 1021, 1031

Posicin universal

Desplazamiento 1012, universal 1022, 1032 Direccin real 1013, 1023, 1033

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

Datos extendidos [Manual de referencia de DXF: DXF]

Pgina 3 de 3

Real Distancia

1040 1041

Un valor real. Valor real al que se aplica una escala junto con la entidad original Tambin un valor real al que se aplica una escala junto con la entidad original. La diferencia entre una distancia y un factor de escala la define la aplicacin. Valor entero de 16 bits (con signo o sin l) Valor entero de 32 bits con signo (largo)

Factor de escala 1042 Entero Largo 1070 1071

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

Asignacin y recuperacin de datos extendidos [Manual del desarrollador de Active... Pgina 1 de 1

Cdigo de ejemplo

Puede utilizar datos extendidos (datoseX) como un medio para enlazar informacin con los objetos de un dibujo.

Asignacin de datos extendidos a un conjunto de seleccin [Manual del desarrollad...

Pgina 1 de 1

En este ejemplo, se pide al usuario que designe objetos del dibujo. Los objetos designados se introducen en un conjunto de seleccin y los datos extendidos especificados se enlazan con todos los objetos de dicho conjunto. Sub Ch10_AttachXDataToSelectionSetObjects() ' Create the selection set Dim sset As Object Set sset = ThisDrawing.SelectionSets.Add("SS1") ' Prompt the user to select objects sset.SelectOnScreen ' Define the xdata Dim appName As String, xdataStr As String appName = "MY_APP" xdataStr = "This is some xdata" Dim xdataType(0 To 1) As Integer Dim xdata(0 To 1) As Variant ' Define the values for each array '1001 indicates the appName xdataType(0) = 1001 xdata(0) = appName '1000 indicates a string value xdataType(1) = 1000 xdata(1) = xdataStr ' Loop through all entities in the selection ' set and assign the xdata to each entity Dim ent As Object For Each ent In sset ent.SetXData xdataType, xdata Next ent End Sub

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

Visualizacin de los datos extendidos de todos los objetos de un conjunto de selecci... Pgina 1 de 1

Este ejemplo muestra los datos extendidos enlazados en el ejemplo anterior. Si enlaza datos extendidos que no son cadenas (tipo 1000), necesitar corregir este cdigo. Sub Ch10_ViewXData() ' Find the selection created in previous example Dim sset As Object Set sset = ThisDrawing.SelectionSets.Item("SS1") ' Define the xdata variables to hold xdata information Dim xdataType As Variant Dim xdata As Variant Dim xd As Variant 'Define index counter Dim xdi As Integer xdi = 0 ' Loop through the objects in the selection set ' and retrieve the xdata for the object Dim msgstr As String Dim appName As String Dim ent As AcadEntity appName = "MY_APP" For Each ent In sset msgstr = "" xdi = 0 ' Retrieve the appName xdata type and value ent.GetXData appName, xdataType, xdata ' If the xdataType variable is not initialized, there ' was no appName xdata to retrieve for that entity If VarType(xdataType) <> vbEmpty Then For Each xd In xdata msgstr = msgstr & vbCrLf & xdataType(xdi) _ & ": " & xd xdi = xdi + 1 Next xd End If ' If the msgstr variable is NULL, there was no xdata If msgstr = "" Then msgstr = vbCrLf & "NONE" MsgBox appName & " xdata on " & ent.ObjectName & _ ":" & vbCrLf & msgstr Next ent End Sub

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

SetXdata method [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

SetXData Method
Sets the extended data (XData) associated with an object.

See Also | Example Signature object.SetXData XDataType, XData Object All Drawing Objects , AttributeReference, Block, Dictionary, DimStyle, Group, Layer, Linetype, PlotConfigurations, RegisteredApplication, TextStyle, UCS, View, Viewport; XRecord The object or objects this method applies to. XDataType Variant (array of short); input-only XData Array of Variant; input-only Remarks Extended data is an example of instance-specific data created by applications written with ObjectARX or AutoLISP. This data can be added to any entity. This data follows the entity's definition data and is maintained in the order in which it was saved into the document. (AutoCAD maintains this information but doesn't use it.)

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

SetXdata Example [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

SetXData Example
Using Programming Languages other than VBA Sub Example_SetXdata() ' This example creates a line and attaches extended data to that line. ' Create the line Dim lineObj As AcadLine Dim startPt(0 To 2) As Double, endPt(0 To 2) As Double startPt(0) = 1#: startPt(1) = 1#: startPt(2) = 0# endPt(0) = 5#: endPt(1) = 5#: endPt(2) = 0# Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt) ZoomAll ' Initialize all the xdata values. Note that first data in the list should b ' application name and first datatype code should be 1001 Dim DataType(0 To 9) As Integer Dim Data(0 To 9) As Variant Dim reals3(0 To 2) As Double Dim worldPos(0 To 2) As Double DataType(0) = 1001: Data(0) = "Test_Application" DataType(1) = 1000: Data(1) = "This is a test for xdata" DataType(2) DataType(3) DataType(4) DataType(5) DataType(6) DataType(7) = = = = = = 1003: 1040: 1041: 1070: 1071: 1042: Data(2) Data(3) Data(4) Data(5) Data(6) Data(7) = = = = = = "0" 1.23479137438413E+40 1237324938 32767 32767 10 ' ' ' ' ' ' layer real distance 16 bit Integer 32 bit Integer scaleFactor

reals3(0) = -2.95: reals3(1) = 100: reals3(2) = -20 DataType(8) = 1010: Data(8) = reals3 ' real worldPos(0) = 4: worldPos(1) = 400.99999999: worldPos(2) = 2.798989 DataType(9) = 1011: Data(9) = worldPos ' world space position ' Attach the xdata to the line lineObj.SetXData DataType, Data ' Return the xdata for the line Dim xdataOut As Variant Dim xtypeOut As Variant lineObj.GetXData "", xtypeOut, xdataOut End Sub

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

GetXdata method [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

GetXData Method
Gets the extended data (XData) associated with an object.

See Also | Example Signature object.GetXData AppName, XDataType, XDataValue Object All Drawing Objects , AttributeReference, Block, Dictionary, DimStyle, Group, Layer, Linetype, PlotConfigurations, RegisteredApplication, TextStyle, UCS, View, Viewport; XRecord The object or objects this method applies to. AppName String; input-only A NULL string will return all the data attached to the object, regardless of the application that created it. Supplying an application name will return only the data that was created by the specified application. XDataType Variant (array of shorts); output-only XDataValue Variant (array of variants); output-only Remarks Extended data is an example of instance-specific data created by applications written with ObjectARX or AutoLISP. This data can be added to any object. This data follows the object's definition data, and is maintained in the order that it was saved into the document. (AutoCAD maintains this information, but doesn't use it.)

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

GetXdata Example [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

GetXData Example
Using Programming Languages other than VBA Sub Example_GetXData() ' This example creates a line and attaches extended data to that line. ' Create the line Dim lineObj As AcadLine Dim startPt(0 To 2) As Double, endPt(0 To 2) As Double startPt(0) = 1#: startPt(1) = 1#: startPt(2) = 0# endPt(0) = 5#: endPt(1) = 5#: endPt(2) = 0# Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt) ZoomAll ' Initialize all the xdata values. Note that first data in the list should b ' application name and first datatype code should be 1001 Dim DataType(0 To 9) As Integer Dim Data(0 To 9) As Variant Dim reals3(0 To 2) As Double Dim worldPos(0 To 2) As Double DataType(0) = 1001: Data(0) = "Test_Application" DataType(1) = 1000: Data(1) = "This is a test for xdata" DataType(2) DataType(3) DataType(4) DataType(5) DataType(6) DataType(7) = = = = = = 1003: 1040: 1041: 1070: 1071: 1042: Data(2) Data(3) Data(4) Data(5) Data(6) Data(7) = = = = = = "0" 1.23479137438413E+40 1237324938 32767 32767 10 ' ' ' ' ' ' layer real distance 16 bit Integer 32 bit Integer scaleFactor

reals3(0) = -2.95: reals3(1) = 100: reals3(2) = -20 DataType(8) = 1010: Data(8) = reals3 ' real worldPos(0) = 4: worldPos(1) = 400.99999999: worldPos(2) = 2.798989 DataType(9) = 1011: Data(9) = worldPos ' world space position ' Attach the xdata to the line lineObj.SetXData DataType, Data ' Return the xdata for the line Dim xdataOut As Variant Dim xtypeOut As Variant lineObj.GetXData "", xtypeOut, xdataOut End Sub

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

Filtro para datos extendidos [Manual del desarrollador de ActiveX y VBA: AAG]

Pgina 1 de 1

Cdigo de ejemplo

Se pueden utilizar aplicaciones externas para asociar datos tales como cadenas de texto, valores numricos, puntos 3D, distancias y nombres de capa a objetos de AutoCAD. Estos son los denominados datos extendidos o datoseX. Se pueden crear filtros de entidades que contengan datos extendidos de una aplicacin especfica. Para obtener ms informacin acerca de los datos extendidos, vase Asignacin y recuperacin de datos extendidos.

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

Seleccin de crculos que contienen datos extendidos [Manual del desarrollador de ...

Pgina 1 de 1

En el siguiente ejemplo, se filtran los crculos que contienen datos extendidos procedentes de la aplicacin "MI_APL". Sub Ch4_FilterXdata() Dim sstext As AcadSelectionSet Dim mode As Integer Dim pointsArray(0 To 11) As Double mode = acSelectionSetWindowPolygon pointsArray(0) = -12#: pointsArray(1) = -7#: pointsArray(2) = 0 pointsArray(3) = -12#: pointsArray(4) = 10#: pointsArray(5) = 0 pointsArray(6) = 10#: pointsArray(7) = 10#: pointsArray(8) = 0 pointsArray(9) = 10#: pointsArray(10) = -7#: pointsArray(11) = 0 Dim FilterType(1) As Integer Dim FilterData(1) As Variant Set sstext = ThisDrawing.SelectionSets.Add("SS9") FilterType(0) FilterData(0) FilterType(1) FilterData(1) = = = = 0 "Circle" 1001 "MI_APL"

sstext.SelectByPolygon mode, pointsArray, FilterType, FilterData End Sub

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

XRecord object [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

XRecord object
XRecord objects are used to store and manage arbitrary data. VBA class name: Create using: Access via:

AcadXRecord Dictionary.AddXRecord Dictionary.Item

This object is similar in concept to XData but is not limited by size or order. Unlike XData, XRecords work with the standard AutoCAD group codes that are all below 1000 in value. All the standard AutoCAD group codes are supported. This means that, in addition to all the normally used data types, an XRecord is capable of storing object IDs, which allows XRecords to own other objects including other XRecords. The following group codes are common to all XRecord objects: 100 Subclass marker (AcDbXrecord) 1-369 (except 5 and 105) These values can be used by an application in any way. XRecord obects are saved with the drawing and are directly accessible by other ObjectARX and LISP programs. So, if data security is an issue for your application, you should be careful when storing information in XRecords. NOTE XRecord objects are designed to work in such a way as to not offend Releases 13c0 through 13c3. However, if read into a pre-Release 13c4 level of AutoCAD, XRecord objects disappear. To create an XRecord, use the AddXRecord method. To edit or query an XRecord, use the following methods and properties:
Methods Properties Events

Delete GetXData GetXRecordData SetXData SetXRecordData

Application Handle HasExtensionDictionary Name ObjectID ObjectName OwnerID TranslateIDs

Modified

GetExtensionDictionary Document

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

Pgina 1 de 1

Using the AutoLISP Language

Xrecord objects are used to store and manage arbitrary data. They are composed of DXF group codes with normal object groups (that is, non-xdata group codes), ranging from 1 through 369 for supported ranges. This object is similar in concept to xdata but is not limited by size or order. Xrecord objects are designed to work in such a way as not to offend releases R13c0 through R13c3. However, if read into a pre-R13c4 level of AutoCAD, xrecord objects disappear. The following examples provide methods for creating and listing xrecord data. (defun C:MAKEXRECORD( / xrec xname ) ; create the xrecord's data list. (setq xrec `((0 . "XRECORD")(100 . "AcDbXrecord") (1 . "This is a test xrecord list") (10 1.0 2.0 0.0) (40 . 3.14159) (50 . 3.14159) (62 . 1) (70 . 180)) ) ; use entmakex to create the xrecord with no owner. (setq xname (entmakex xrec)) ; add the new xrecord to the named object dictionary. (dictadd (namedobjdict) "XRECLIST" xname) (princ) ) (defun C:LISTXRECORD ( / xlist ) ; find the xrecord in the named object dictionary. (setq xlist (dictsearch (namedobjdict) "XRECLIST")) ; print out the xrecord's data list. (princ xlist) (princ) )

file://D:\DOCUME~1\Raul\CONFIG~1\Temp\JSLVIKG8.htm

10/08/2005

SetXRecordData method [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

SetXRecordData Method
Sets the extended record data (XRecordData) associated with a dictionary.

See Also | Example Signature object.SetXRecordData XRecordDataType, XRecordData Object Dictionary; XRecord The object or objects this method applies to. XRecordDataType Variant (array of short); input-only XRecordData Variant (array of variants); input-only Remarks XRecord objects are used to store and manage arbitrary data. This object is similar in concept to XData, but is not limited by size or order. Unlike XData, XRecords work with the standard AutoCAD group codes, which are all below 1000 in value. All the standard AutoCAD group codes are supported. This means that, in addition to all the normally used data types, an XRecord is capable of storing object IDs, which allows XRecords to own other objects including other XRecords. The following group codes are common to all XRecord objects: Group codes 100 1-369 (except 5 and 105) Description Subclass marker (AcDbXrecord) These values can be used by an application in any way.

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

SetXRecordData Example [ActiveX and VBA Reference: AAR]

Pgina 1 de 2

SetXRecordData Example
Using Programming Languages other than VBA Sub Example_SetXRecordData() ' This example creates a new XRecord if one doesn't exist, ' appends data to the XRecord, and reads it back. To see data being added, ' run the example more than once. Dim Dim Dim Dim TrackingDictionary As AcadDictionary, TrackingXRecord As AcadXRecord XRecordDataType As Variant, XRecordData As Variant ArraySize As Long, iCount As Long DataType As Integer, Data As String, msg As String

' Unique identifiers to distinguish our XRecordData from other XRecordData Const TYPE_STRING = 1 Const TAG_DICTIONARY_NAME = "ObjectTrackerDictionary" Const TAG_XRECORD_NAME = "ObjectTrackerXRecord" ' Connect to the dictionary in which the XRecord is stored On Error GoTo CREATE Set TrackingDictionary = ThisDrawing.Dictionaries(TAG_DICTIONARY_NAME) Set TrackingXRecord = TrackingDictionary.GetObject(TAG_XRECORD_NAME) On Error GoTo 0 ' Get current XRecordData TrackingXRecord.GetXRecordData XRecordDataType, XRecordData ' If there is no array already, create one If VarType(XRecordDataType) And vbArray = vbArray Then ArraySize = UBound(XRecordDataType) + 1 ' Get the size of the data ArraySize = ArraySize + 1 ' Increase to hold new ReDim Preserve XRecordDataType(0 To ArraySize) ReDim Preserve XRecordData(0 To ArraySize) Else ArraySize = 0 ReDim XRecordDataType(0 To ArraySize) As Integer ReDim XRecordData(0 To ArraySize) As Variant End If ' Append new XRecord Data ' ' For this sample, we only append the current item to the XRecord XRecordDataType(ArraySize) = TYPE_STRING: XRecordData(ArraySize) = CStr(Now) TrackingXRecord.SetXRecordData XRecordDataType, XRecordData ' Read back all XRecordData entries TrackingXRecord.GetXRecordData XRecordDataType, XRecordData ArraySize = UBound(XRecordDataType) ' Retrieve and display stored XRecordData For iCount = 0 To ArraySize ' Get information for this element DataType = XRecordDataType(iCount) Data = XRecordData(iCount) If DataType = TYPE_STRING Then msg = msg & Data & vbCrLf End If Next

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

SetXRecordData Example [ActiveX and VBA Reference: AAR]

Pgina 2 de 2

MsgBox "The data in the XRecord is: " & vbCrLf & vbCrLf & msg, vbInformation Exit Sub CREATE: ' Create the objects that hold the XRecordData If TrackingDictionary Is Nothing Then ' Make sure the tracking object is th Set TrackingDictionary = ThisDrawing.Dictionaries.Add(TAG_DICTIONARY_NAM Set TrackingXRecord = TrackingDictionary.AddXRecord(TAG_XRECORD_NAME) End If Resume End Sub

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

AddXRecord method [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

AddXRecord Method
Creates an XRecord object in any dictionary.

See Also | Example Signature RetVal = object.AddXRecord(Keyword) Object Dictionary The object or objects this method applies to. Keyword String, input-only The name of the XRecord within the dictionary. RetVal XRecord object The newly created XRecord object.

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

GetXRecordData method [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

GetXRecordData Method
Gets the extended record data (XRecordData) associated with a dictionary.

See Also | Example Signature object.GetXRecordData XRecordDataType, XRecordDataValue Object Dictionary; XRecord The object or objects this method applies to. XRecordDataType Variant (array of shorts); output-only XRecordDataValue Variant (array of variants); output-only Remarks XRecord objects are used to store and manage arbitrary data. This object is similar in concept to XData but is not limited by size or order. Unlike XData, XRecords work with the standard AutoCAD group codes which are all below 1000 in value. All the standard AutoCAD group codes are supported. This means that, in addition to all the normally used data types, an XRecord is capable of storing object IDs, which allows XRecords to own other objects including other XRecords. The following group codes are common to all XRecord objects: Group codes 100 1-369 (except 5 and 105) Description Subclass marker (AcDbXrecord) These values can be used by an application in any way.

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

SetXRecordData Example [ActiveX and VBA Reference: AAR]

Pgina 1 de 2

SetXRecordData Example
Using Programming Languages other than VBA Sub Example_SetXRecordData() ' This example creates a new XRecord if one doesn't exist, ' appends data to the XRecord, and reads it back. To see data being added, ' run the example more than once. Dim Dim Dim Dim TrackingDictionary As AcadDictionary, TrackingXRecord As AcadXRecord XRecordDataType As Variant, XRecordData As Variant ArraySize As Long, iCount As Long DataType As Integer, Data As String, msg As String

' Unique identifiers to distinguish our XRecordData from other XRecordData Const TYPE_STRING = 1 Const TAG_DICTIONARY_NAME = "ObjectTrackerDictionary" Const TAG_XRECORD_NAME = "ObjectTrackerXRecord" ' Connect to the dictionary in which the XRecord is stored On Error GoTo CREATE Set TrackingDictionary = ThisDrawing.Dictionaries(TAG_DICTIONARY_NAME) Set TrackingXRecord = TrackingDictionary.GetObject(TAG_XRECORD_NAME) On Error GoTo 0 ' Get current XRecordData TrackingXRecord.GetXRecordData XRecordDataType, XRecordData ' If there is no array already, create one If VarType(XRecordDataType) And vbArray = vbArray Then ArraySize = UBound(XRecordDataType) + 1 ' Get the size of the data ArraySize = ArraySize + 1 ' Increase to hold new ReDim Preserve XRecordDataType(0 To ArraySize) ReDim Preserve XRecordData(0 To ArraySize) Else ArraySize = 0 ReDim XRecordDataType(0 To ArraySize) As Integer ReDim XRecordData(0 To ArraySize) As Variant End If ' Append new XRecord Data ' ' For this sample, we only append the current item to the XRecord XRecordDataType(ArraySize) = TYPE_STRING: XRecordData(ArraySize) = CStr(Now) TrackingXRecord.SetXRecordData XRecordDataType, XRecordData ' Read back all XRecordData entries TrackingXRecord.GetXRecordData XRecordDataType, XRecordData ArraySize = UBound(XRecordDataType) ' Retrieve and display stored XRecordData For iCount = 0 To ArraySize ' Get information for this element DataType = XRecordDataType(iCount) Data = XRecordData(iCount) If DataType = TYPE_STRING Then msg = msg & Data & vbCrLf End If Next

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

SetXRecordData Example [ActiveX and VBA Reference: AAR]

Pgina 2 de 2

MsgBox "The data in the XRecord is: " & vbCrLf & vbCrLf & msg, vbInformation Exit Sub CREATE: ' Create the objects that hold the XRecordData If TrackingDictionary Is Nothing Then ' Make sure the tracking object is th Set TrackingDictionary = ThisDrawing.Dictionaries.Add(TAG_DICTIONARY_NAM Set TrackingXRecord = TrackingDictionary.AddXRecord(TAG_XRECORD_NAME) End If Resume End Sub

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

AddXRecord method [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

AddXRecord Method
Creates an XRecord object in any dictionary.

See Also | Example Signature RetVal = object.AddXRecord(Keyword) Object Dictionary The object or objects this method applies to. Keyword String, input-only The name of the XRecord within the dictionary. RetVal XRecord object The newly created XRecord object.

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

AddXRecord Example [ActiveX and VBA Reference: AAR]

Pgina 1 de 2

AddXRecord Example
Using Programming Languages other than VBA Sub Example_AddXRecord() ' This example creates a new XRecord if one doesn't exist, ' appends data to the XRecord, and then reads it back. To see data being ad ' run the example more than once. Dim Dim Dim Dim TrackingDictionary As AcadDictionary, TrackingXRecord As AcadXRecord XRecordDataType As Variant, XRecordData As Variant ArraySize As Long, iCount As Long DataType As Integer, Data As String, msg As String

' Unique identifiers to distinguish this XRecordData from other XRecordData Const TYPE_STRING = 1 Const TAG_DICTIONARY_NAME = "ObjectTrackerDictionary" Const TAG_XRECORD_NAME = "ObjectTrackerXRecord" ' Connect to the dictionary in which to store the XRecord On Error GoTo CREATE Set TrackingDictionary = ThisDrawing.Dictionaries(TAG_DICTIONARY_NAME) Set TrackingXRecord = TrackingDictionary.GetObject(TAG_XRECORD_NAME) On Error GoTo 0 ' Get current XRecordData TrackingXRecord.GetXRecordData XRecordDataType, XRecordData ' If there is no array yet then create one If VarType(XRecordDataType) And vbArray = vbArray Then ArraySize = UBound(XRecordDataType) + 1 ' Get the size of the data ArraySize = ArraySize + 1 ' Increase to hold new ReDim Preserve XRecordDataType(0 To ArraySize) ReDim Preserve XRecordData(0 To ArraySize) Else ArraySize = 0 ReDim XRecordDataType(0 To ArraySize) As Integer ReDim XRecordData(0 To ArraySize) As Variant End If ' Append new XRecord Data ' ' For this sample we only append the current time to the XRecord XRecordDataType(ArraySize) = TYPE_STRING: XRecordData(ArraySize) = CStr(Now) TrackingXRecord.SetXRecordData XRecordDataType, XRecordData ' Read back all XRecordData entries TrackingXRecord.GetXRecordData XRecordDataType, XRecordData ArraySize = UBound(XRecordDataType) ' Retrieve and display stored XRecordData For iCount = 0 To ArraySize ' Get information for this element DataType = XRecordDataType(iCount) Data = XRecordData(iCount) If DataType = TYPE_STRING Then msg = msg & Data & vbCrLf End If Next

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

AddXRecord Example [ActiveX and VBA Reference: AAR]

Pgina 2 de 2

MsgBox "The data in the XRecord is: " & vbCrLf & vbCrLf & msg, vbInformation Exit Sub CREATE: ' Create the objects that hold this XRecordData If TrackingDictionary Is Nothing Then ' Make sure to have tracking object Set TrackingDictionary = ThisDrawing.Dictionaries.Add(TAG_DICTIONARY_NAM Set TrackingXRecord = TrackingDictionary.AddXRecord(TAG_XRECORD_NAME) End If Resume End Sub

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

Dictionary object [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

Dictionary object
A container object for storing and retrieving objects. VBA class name: Create using: Access via:

AcadDictionary Dictionaries.Add Dictionaries.Item

Dictionaries provide a mechanism for storing and retrieving objects with associated string keywords. The objects in a dictionary may be referenced by their keywords. A dictionary can contain any type of object, including other dictionaries. A dictionary does not perform type checking of entries. You can create new dictionaries, add entries to an existing dictionary, and get the keyword for a given object or the object for a given keyword. You can change the object that is associated with a given keyword, or rename the keyword for a given object. This dictionary is similar to a collection in AutoCAD, and is used for custom object implementation. This object does not represent the spellchecking dictionary. The spellchecking dictionary is specified in the Preferences object. To add a dictionary to the application, use the Add method. To edit or query a dictionary, use the following methods and properties:
Methods Properties Events

AddObject AddXRecord Delete GetName GetObject GetXData Item Remove Rename Replace SetXData

Application Count Document HasExtensionDictionary Name ObjectID ObjectName OwnerID

Modified

GetExtensionDictionary Handle

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

HandleToObject method [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

HandleToObject Method
Gets the object that corresponds to the given handle.

See Also | Example Signature RetVal = object.HandleToObject(Handle) Object Document The object or objects this method applies to. Handle String; input-only The handle of the object to return. RetVal Object The object that corresponds to the given handle. Remarks This method can return only objects in the current document.

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

HandleToObject Example [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

HandleToObject Example
Using Programming Languages other than VBA Sub Example_HandleToObject() ' This example creates a spline in model space, and returns the ' handle for the spline. Then the spline is returned from the handle and col ' Create the spline Dim splineObj As AcadSpline Dim startTan(0 To 2) As Double Dim endTan(0 To 2) As Double Dim fitPoints(0 To 8) As Double startTan(0) = 0.5: startTan(1) = 0.5: startTan(2) = 0 endTan(0) = 0.5: endTan(1) = 0.5: endTan(2) = 0 fitPoints(0) = 1: fitPoints(1) = 1: fitPoints(2) = 0 fitPoints(3) = 5: fitPoints(4) = 5: fitPoints(5) = 0 fitPoints(6) = 10: fitPoints(7) = 0: fitPoints(8) = 0 Set splineObj = ThisDrawing.ModelSpace.AddSpline(fitPoints, startTan, endTan ZoomAll ' Find the handle of the spline Dim handle As String handle = splineObj.handle MsgBox "The handle of the Spline is: " & splineObj.handle, , "HandleToObject ' Find an object from a given handle Dim tempObj As AcadObject Set tempObj = ThisDrawing.HandleToObject(handle) ' Now use the newly initialized object variable to color the object Dim color As AcadAcCmColor Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.16") Call color.SetRGB(80, 100, 244) tempObj.TrueColor = color ThisDrawing.Regen True MsgBox "The Spline is now blue.", , "ObjectIDToObject Example" End Sub

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

ObjectIDToObject method [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

ObjectIDToObject Method
Gets the object that corresponds to the given object ID.

See Also | Example Signature RetVal = object.ObjectIDToObject(ID) Object Document The object or objects this method applies to. ID Long; input-only The object ID of the object to return. RetVal Object The object that corresponds to the given object ID. Remarks This method can return only objects that are in the current document.

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

ObjectIDToObject Example [ActiveX and VBA Reference: AAR]

Pgina 1 de 1

ObjectIDToObject Example
Using Programming Languages other than VBA Sub Example_ObjectIDToObject() ' This example creates a spline in model space, and returns the ' handle for the spline. Then the spline is returned from the handle and col ' Create the spline Dim splineObj As AcadSpline Dim startTan(0 To 2) As Double Dim endTan(0 To 2) As Double Dim fitPoints(0 To 8) As Double startTan(0) = 0.5: startTan(1) = 0.5: startTan(2) = 0 endTan(0) = 0.5: endTan(1) = 0.5: endTan(2) = 0 fitPoints(0) = 1: fitPoints(1) = 1: fitPoints(2) = 0 fitPoints(3) = 5: fitPoints(4) = 5: fitPoints(5) = 0 fitPoints(6) = 10: fitPoints(7) = 0: fitPoints(8) = 0 Set splineObj = ThisDrawing.ModelSpace.AddSpline(fitPoints, startTan, endTan ZoomAll ' Find the objectID of the spline Dim objectID As Long objectID = splineObj.objectID MsgBox "The objectID of the Spline is: " & splineObj.objectID, , "ObjectIDTo ' Find an object from a given objectID Dim tempObj As AcadObject Set tempObj = ThisDrawing.ObjectIdToObject(objectID) ' Now use the newly initialized object variable to color the object Dim color As AcadAcCmColor Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.16") Call color.SetRGB(80, 100, 244) tempObj.TrueColor = color ThisDrawing.Regen True MsgBox "The Spline is now blue.", , "ObjectIDToObject Example" End Sub

mk:@MSITStore:D:\Documents%20and%20Settings\Raul\Mis%20documentos\Auto... 10/08/2005

Potrebbero piacerti anche