-
I need to get the text from the blocks inserted into the drawing, how can I do this? |
Beta Was this translation helpful? Give feedback.
Answered by
erfansn
May 17, 2025
Replies: 2 comments
-
Here is my code: Dwg_Data dwg;
memset(&dwg, 0, sizeof(Dwg_Data));
int success = dwg_read_file(filePath.c_str(), &dwg);
if (!(success < DWG_ERR_CRITICAL))
{
throw std::exception("Wrong file!");
}
int found{ 0 };
char* text_value{ nullptr };
int isnew{ 0 };
for (BITCODE_BL i = 0; i < dwg.num_objects; i++)
{
Dwg_Object* obj = &dwg.object[i];
if (obj->type == DWG_TYPE_TEXT)
{
Dwg_Entity_TEXT* textEntity = obj->tio.entity->tio.TEXT;
if (textEntity && textEntity->text_value) {
dwg_dynapi_entity_utf8text(textEntity, "TEXT", "text_value", &text_value, &isnew, NULL);
}
}
else if (obj->type == DWG_TYPE_MTEXT)
{
Dwg_Entity_MTEXT* mtextEntity = obj->tio.entity->tio.MTEXT;
if (mtextEntity && mtextEntity->text) {
dwg_dynapi_entity_utf8text(mtextEntity, "MTEXT", "text", &text_value, &isnew, NULL);
}
}
found++;
text.append(separator + utf8_decode(text_value));
}
text = text + separator;
if (!found)
{
throw std::exception("Text not found!");
}
dwg_free(&dwg); |
Beta Was this translation helpful? Give feedback.
0 replies
-
You must query the INSERT entity, then iterate on its owned entities |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
rurban
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You must query the INSERT entity, then iterate on its owned entities