tpm_elemfind

Land Desktop Development ARX CPP SDK

Up a level
tpm_elemfind
 
 

Finds an element within a topology.

ade_id

tpm_elemfind(

ade_id tpm_id,

int type,

struct resbuf *pattern);

Returns an element ID or ADE_NULLID.

tpm_id The topology ID.
type The type of element to find. Values can be: 1 (node), 2 (link), or 3 (polygon).
pattern The name of the point or entity. If pattern is a point, in which case type must be 1, the function returns the nearest point or link, or the enclosing polygon. If pattern is an entity name, in which case type can have any value, the function returns the corresponding object.

The following sample finds a specific element in an existing network topology and uses the tpm_editaddelem sample as a baseline.

A resbuf is created containing the information required to draw a new pline. The pline is drawn using acedCmd(). The new pline's entity id is then obtained using acdbEntLast(). The topology that will recieve the new link is loaded and opened using tpm_acload() and tpm_acopen() respectively. A resbuf containing the new pline entity is constructed, then tpm_editaddelem() is called with all required parameters. Appropriate status messages are displayed based on the return code.

To find the new element; A resbuf is created containing the pattern parameter information, (entity name). Tpm_elemfind() is then called with all required parameters. The return value is validated against ADE_NULLID and appropriate status messages are displayed. Topologies are closed and unloaded from memory and the resbufs are released as required.

struct resbuf* pNewPlineRb = acutBuildList(
                                RTSTR, "_pline",
                                RTSTR, "54.0816,50.8243",
                                RTSTR, "68,53",
                                RTSTR, "",
                                0);
int returnCode = acedCmd(pNewPlineRb);
ads_name newPline;
returnCode = acdbEntLast(newPline);
char* pszTopoName = "NetTopo";
int topoWriteAccess = 1;
returnCode = tpm_acload(pszTopoName, 0);
ade_id topoId = tpm_acopen(pszTopoName, topoWriteAccess);
struct resbuf* pNewElementRb = acutBuildList(RTENAME, newPline, 0);
int elementType = 2;
returnCode = tpm_editaddelem(topoId, elementType, pNewElementRb);
if (RTNORM == returnCode){
    acutPrintf(
        "\nThe new element was successfully added.");
}
else {
    acutPrintf(
        "\nThe new element was not added.");
}

// Find the new element.
struct resbuf* pSeekPatternRb = acutBuildList(RTENAME, newPline, 0);
ade_id elementId = tpm_elemfind(topoId, elementType, pSeekPatternRb);
if (ADE_NULLID != elementId){
    acutPrintf(
        "\nThe new element has a id of: %.0lf"
        , elementId);
}
else {
    acutPrintf(
        "\nThe specified element was not found.");
}
tpm_acclose(topoId);
tpm_acunload(pszTopoName);
acutRelRb(pNewPlineRb);
acutRelRb(pNewElementRb);
acutRelRb(pSeekPatternRb);