yucad3d

Enumerate all entities

Walk every layer and every entity, reading per-entity data (here: counting entities whose UserData equals 7).

// 1 — Enumerate all entities by layer; find UserData==7 (AllEntities.htm)
static void samp_all_entities() {
    int total = 0, found = 0, hLayer = CadGetFirstLayer(g_hDwg);
    while (hLayer) {
        int hEnt = CadLayerGetFirstEntity(hLayer);
        while (hEnt) { ++total; if (CadEntityGetUserData(hEnt) == 7) ++found;
                       hEnt = CadLayerGetNextEntity(hLayer, hEnt); }
        hLayer = CadGetNextLayer(g_hDwg, hLayer);
    }
    wchar_t s[160]; swprintf(s, 160, L"Sample 1: %d entities across layers, %d with UserData==7", total, found);
    set_status(s);
}
    1: begin
         total := 0; found := 0; hLayer := CadGetFirstLayer(FhDwg);
         while hLayer <> 0 do
         begin
           hEnt := CadLayerGetFirstEntity(hLayer);
           while hEnt <> 0 do
           begin
             Inc(total);
             if CadEntityGetUserData(hEnt) = 7 then Inc(found);
             hEnt := CadLayerGetNextEntity(hLayer, hEnt);
           end;
           hLayer := CadGetNextLayer(FhDwg, hLayer);
         end;
    private void SampleAllEntities()
    {
        int total = 0, found = 0, hLayer = YuCadApi.CadGetFirstLayer(_hDwg);
        while (hLayer != 0)
        {
            int hEnt = YuCadApi.CadLayerGetFirstEntity(hLayer);
            while (hEnt != 0) { total++; if (YuCadApi.CadEntityGetUserData(hEnt) == 7) found++;
                                hEnt = YuCadApi.CadLayerGetNextEntity(hLayer, hEnt); }
            hLayer = YuCadApi.CadGetNextLayer(_hDwg, hLayer);
        }
        SetStatus($"Sample 1: {total} entities across layers, {found} with UserData==7");
    }
This code is extracted verbatim from the shipped demo hosts (examples/cpp, examples/delphi, examples/csharp) — run the matching menu item there to see it live.