Close

Using the Library

A project log for A Simple DXF Output Library

Here is a simple DXF output library that may or may not be supported by your CAD package.

agp.cooperagp.cooper 04/19/2019 at 10:460 Comments

Using the Library

First copy the header file (dxfout.h) into your project folder.

Next, add the line #include "dxfout.h" to your program (near the top, perhaps just below the system file headers).

Here is an example (dxfoutTest.c):

/ Include Libraries
#include <stdio.h>
#include <stdlib.h>

// Please check dxfout.h for function parameter definitions
#include "dxfout.h"

int main(int argc,char **argv) {
  printf("DXFOut V1.0 - Written by Alan Cooper (AlanCooper@StartMail.com)\n");

  // Open a new DXF file
  char fileName[128];
  sprintf(fileName,"DXFOutTest.dxf");
  FILE *F1=fopen(fileName,"w");

  // Create a small box:
  //   Use Shape (closed polyline)
  //   Set Colour 0
  //   Set Layer "Test"
  //   Note: Z coordinate is 0
  DXF_Begin(F1);                  // Required once
  DXF_ShapeBegin(F1,"Test",0);    // Required for each shape (closed polyline)
  DXF_ShapePoint(F1,10,30,0);
  DXF_ShapePoint(F1,30,30,0);
  DXF_ShapePoint(F1,30,10,0);
  DXF_ShapePoint(F1,10,10,0);
  DXF_ShapeEnd(F1);               // Required for each shape (closed polyline)

  // Put a point in the middle
  DXF_Point(F1,"Test",1,20,20,0);

  // Make point look like a cross-hair using lines
  DXF_Line(F1,"Test",2,22,20,0,25,20,0);
  DXF_Line(F1,"Test",2,18,20,0,15,20,0);
  DXF_Line(F1,"Test",2,20,22,0,20,25,0);
  DXF_Line(F1,"Test",2,20,18,0,20,15,0);

  // Put a circle around the cross-hair
  DXF_Circle(F1,"Test",3,20,20,0,5);

  // And another box but using polyline (open polyline)
  DXF_PolylineBegin(F1,"Test",4); // Required for each shape (closed polyline)
  DXF_PolylinePoint(F1, 9,31,0);
  DXF_PolylinePoint(F1,31,31,0);
  DXF_PolylinePoint(F1,31, 9,0);
  DXF_PolylinePoint(F1, 9, 9,0);
  DXF_PolylinePoint(F1, 9,31,0);  // Close the box
  DXF_PolylineEnd(F1);            // Required for each shape (closed polyline)

  DXF_End(F1);                    // Required once

  // Close the DXF file
  fclose(F1);

  return 0;
}

And here is the output in a CAD package:

Before you accept that it has worked, check that the boxes and the circle are in fact one polyline and not multiple lines (i.e. individual segments).

Next

For my next post I will look at adding graphical output to the test program.

AlanX

Discussions