You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to write text to a dwg file using dwg_add_TEXT but it didn't work and after running the executable the dwg file became unopenable. When opening a file, it prompts that the loading failed.Could you help me figure out what the problem is?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dwg.h>
#include <time.h>
#include <unistd.h>
#include "dwg_api.h"
static int add_text(Dwg_Data *dwg, dwg_point_3d *pt)
{
int error = 0;
char text[128];
double height = dwg->header_vars.TEXTSIZE;
time_t t = time (NULL);
Dwg_Object_BLOCK_HEADER *hdr = dwg_get_block_header (dwg, &error);
Dwg_Entity_TEXT *ent;
if (error || !hdr) {
fprintf(stderr, "Error retrieving block header: %d\n", error);
return 1;
}
if (height <= 0) {
height = 2.5;
}
strftime (text, sizeof (text), "Last updated: %c", localtime (&t));
if ((ent = dwg_add_TEXT (hdr, text, pt, height)))
{
ent->horiz_alignment = HORIZ_ALIGNMENT_RIGHT;
return 0;
}
return 1;
}
int main() {
int result=0;
const char *filename = "test.dwg";
Dwg_Data dwg;
dwg_point_3d pt;
memset (&dwg, 0, sizeof (Dwg_Data));
result = dwg_read_file(filename, &dwg);
printf("%d\n", result);
if (result != 0) {
fprintf(stderr, "Failed to open DWG file: %s\n", filename);
return 1;
}else {
printf("Successfully opened DWG file: %s\n", filename);
}
// get the insertion point for text
//pt.x = dwg.header_vars.LIMMAX.x;
//pt.y = dwg.header_vars.LIMMAX.y;
pt.x = 100;
pt.y = 100;
pt.z = 0.0;
if (add_text(&dwg, &pt) == 0) {
fprintf(stderr, "Text added at (%f, %f)\n", pt.x, pt.y);
} else {
fprintf(stderr, "Failed to add text.\n");
}
unlink (filename);
if (dwg.header.version > R_2000)
dwg.header.version = R_2000;
result = dwg_write_file (filename, &dwg);
printf("%d\n", result);
if (result != 0) {
fprintf(stderr, "Failed to write DWG file: %s\n", filename);
} else {
printf("Successfully updated DWG file: %s\n", filename);
}
dwg_free(&dwg);
printf("Successfully closed DWG file: %s\n", filename);
return 0;
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I tried to write text to a dwg file using dwg_add_TEXT but it didn't work and after running the executable the dwg file became unopenable. When opening a file, it prompts that the loading failed.Could you help me figure out what the problem is?
Beta Was this translation helpful? Give feedback.
All reactions