CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

实体数据函数

2023-1-1 02:10| 发布者: admin| 查看: 287| 评论: 0|来自: AutoCAD

某些函数对图元数据进行操作,可用于修改当前图形数据库。该函数删除指定的实体。在离开当前图形之前,不会从数据库中清除图元。因此,如果应用程序在该会话期间再次调用并指定相同的实体,则会取消删除该实体。(可用于检索已删除实体的名称。acdbEntDel()acdbEntDel()acdbHandEnt()

注意:使用时,属性和折线顶点不能独立于其父实体删除;只能在主实体上运行。要删除属性或顶点,useorto 调用 AutoCAD ATTEDIT 或 PEDIT 命令,用于重定义实体而不使用不需要的子实体,或者打开顶点或属性并使用其方法擦除它。acdbEntDel()acdbEntDel()acedCommandS()acedCmdS()acdbEntMod()erase()

该函数返回指定实体的定义数据。数据作为结果缓冲区的链接列表返回。列表中每个项目(缓冲区)的类型由 DXF 组代码指定。列表中的第一项包含实体的当前名称 ()。acdbEntGet()restype == -1

ObjectARX 应用程序可以使用以下两个函数检索和打印实体的定义数据。(该函数不处理扩展数据。printdxf()

void getlast() 
{ 
    struct resbuf *ebuf, *eb; 
    ads_name ent1; 
    acdbEntLast(ent1); 
    ebuf = acdbEntGet(ent1); 
    eb = ebuf; 
    acutPrintf("\nResults of entgetting last entity\n"); 
    // Print items in the list.
    for (eb = ebuf; eb != NULL; eb = eb->rbnext) 
        printdxf(eb); 
    // Release the acdbEntGet() list.
    acutRelRb(ebuf); 
} 
int printdxf(eb) 
struct resbuf *eb; 
{ 
    int rt; 
    if (eb == NULL) 
        return RTNONE; 
    if ((eb->restype >= 0) && (eb->restype <= 9)) 
        rt = RTSTR ; 
    else if ((eb->restype >= 10) && (eb->restype <= 19)) 
        rt = RT3DPOINT; 
    else if ((eb->restype >= 38) && (eb->restype <= 59)) 
        rt = RTREAL ; 
    else if ((eb->restype >= 60) && (eb->restype <= 79)) 
        rt = RTSHORT ; 
    else if ((eb->restype >= 210) && (eb->restype <= 239)) 
        rt = RT3DPOINT ; 
    else if (eb->restype < 0) 
        // Entity name (or other sentinel)
        rt = eb->restype; 
    else 
        rt = RTNONE; 
    switch (rt) { 
    case RTSHORT: 
        acutPrintf("(%d . %d)\n", eb->restype, 
            eb->resval.rint); 
        break; 
    case RTREAL: 
        acutPrintf("(%d . %0.3f)\n", eb->restype, 
            eb->resval.rreal); 
        break; 
    case RTSTR: 
        acutPrintf("(%d . \"%s\")\n", eb->restype, 
            eb->resval.rstring); 
        break; 
    case RT3DPOINT: 
        acutPrintf("(%d . %0.3f %0.3f %0.3f)\n", 
            eb->restype, 
            eb->resval.rpoint[X], eb->resval.rpoint[Y], 
            eb->resval.rpoint[Z]); 
        break; 
    case RTNONE: 
        acutPrintf("(%d . Unknown type)\n", eb->restype); 
        break; 
    case -1: 
    case -2:  
        // First block entity
        acutPrintf("(%d . <Entity name: %8lx>)\n", 
            eb->restype, eb->resval.rlname[0]); 
    } 
    return eb->restype; 
} 

In the next example, the following (default) conditions apply to the current drawing.

  • The current layer is 0
  • The current linetype is CONTINUOUS
  • The current elevation is 0
  • Entity handles are disabled

Also, the user has drawn a line with the following sequence of commands:

Command: line

Specify first point: 1,2

Specify next point or [Undo]: 6,6

Specify next point or [Undo]: ENTER

Then a call to would print the following (the name value will vary). getlast()

Results from acdbEntGet() of last entity:

(-1 . <Entity name: 60000014>)

(0 . "LINE")

(8 . "0")

(10 1.0 2.0 0.0)

(11 6.0 6.0 0.0)

(210 0.0 0.0 1.0)

Note: The function prints the output in the format of an AutoLISP association list, but the items are stored in a linked list of result buffers. printdxf()

The result buffer at the start of the list (with a -1 sentinel code) contains the name of the entity that this list represents. The function uses it to identify the entity to be modified. acdbEntMod()

The codes for the components of the entity (stored in the field) are those used by DXF. As with DXF, the entity header items are returned only if they have values other than the default. Unlike DXF, optional entity definition fields are returned regardless of whether they equal their defaults. This simplifies processing; an application can always assume that these fields are present. Also unlike DXF, associated X, Y, and Z coordinates are returned as a single point variable (), not as separate X (10), Y (20), and Z (30) groups. The value contains the group number of the X coordinate (in the range 10–19). restyperesval.rpointrestype

To find a group with a specific code, an application can traverse the list. The function shown here searches a result buffer list for a group of a specified type. entitem()

static struct resbuf *entitem(rchain, gcode) 
struct resbuf *rchain; 
int gcode; 
{ 
    while ((rchain != NULL) && (rchain->restype != gcode)) 
        rchain = rchain->rbnext; 
    return rchain; 
} 

If the DXF group code specified by the argument is not present in the list (or if is not a valid DXF group), “falls off the end” and returns . Note that is equivalent to the AutoLISP function . gcodegcodeentitem()NULLentitem()(assoc)

The function modifies an entity. It passes a list that has the same format as a list returned by , but with some of the entity group values (presumably) modified by the application. This function complements ; the primary means by which an ObjectARX application updates the database is by retrieving an entity with , modifying its entity list, and then passing the list back to the database with . acdbEntMod()acdbEntGet()acdbEntGet()acdbEntGet()acdbEntMod()

Note: To restore the default value of an entity's color or linetype, use to set the color to 256, which is BYLAYER, or the linetype to BYLAYER. acdbEntMod()

The following code fragment retrieves the definition data of the first entity in the drawing, and changes its layer property to MYLAYER.

ads_name en; 
struct resbuf *ed, *cb; 
char *nl = "MYLAYER"; 
if (acdbEntNext(NULL, en) != RTNORM) 
    return BAD; // Error status  
ed = acdbEntGet(en); // Retrieve entity data.
for (cb = ed; cb != NULL; cb = cb->rbnext) 
    if (cb->restype == 8) {											// DXF code for Layer
        // Check to make sure string buffer is long enough.
        if (strlen(cb->resval.rstring) < (strlen(nl))) 
            // Allocate a new string buffer.
            cb->resval.rstring = realloc(cb->resval.rstring, 
                strlen(nl) + 1); 
        strcpy(cb->resval.rstring, nl); 
        if (acdbEntMod(ed) != RTNORM) { 
            acutRelRb(ed); 
            return BAD; // Error
        } 
        break; // From the for loop
    } 
acutRelRb(ed); // Release result buffer.

内存管理是 ObjectARX 应用程序的责任。示例中的代码确保字符串缓冲区的大小正确,并在操作完成后释放返回(并传递给)的结果缓冲区,无论调用是否成功。 acdbEntGet()acdbEntMod()acdbEntMod()

注意:如果使用修改块定义中的图元,则会影响对该块的所有 INSERT 或外部参照参照;此外,块定义中的图元不能被 删除。acdbEntMod()acdbEntDel()

应用程序还可以通过调用函数将实体添加到图形数据库。就像,参数 to 是一个结果缓冲区列表,其格式类似于返回的列表。(调用将忽略实体名称字段 [-1](如果存在)。新图元将追加到图形数据库中(它将成为图形中的最后一个图元)。如果实体是复杂实体(折线或块),则在完成之前不会将其追加到数据库中。acdbEntMake()acdbEntMod()acdbEntMake()acdbEntGet()acdbEntMake()

以下示例代码片段在 MYLAYER 层上创建一个圆圈。

int status; 
struct resbuf *entlist; 
ads_point center = {5.0, 7.0, 0.0}; 
char *layer = "MYLAYER"; 
entlist = acutBuildList(RTDXF0, "CIRCLE",// Entity type
    8, layer, // Layer name 
    10, center, // Center point 
    40, 1.0, // Radius 
    0 ); 
if (entlist == NULL) { 
    acdbFail("Unable to create result buffer list\n"); 
    return BAD; 
} 
status = acdbEntMake(entlist); 
acutRelRb(entlist); // Release acdbEntMake buffer.
if (status == RTERROR) { 
    acdbFail("Unable to make circle entity\n"); 
    return BAD; 
} 

对传递给它们的实体数据执行与 AutoCAD DXFIN 命令在读取 DXF 文件时执行的一致性检查相同的一致性检查。如果无法创建有效的图形图元,则它们将失败。acdbEntMod()acdbEntMake()


路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:52

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部