yucad3d

Getting Started

The minimal path: link, create a document, embed a viewport, draw, save.

1. Link against yucad

Include the single public header and load the DLL. The header is C-only — no <string>, no namespaces, safe to include from C, C++ or to translate into a Delphi/C# binding.

#include "yucad_api.h"   /* declares every Cad* export + CAD_* constants */

At link time use the import library yucad.lib, or resolve exports at runtime with LoadLibrary/GetProcAddress. All exports are undecorated __stdcall names.

2. Create a document

Everything hangs off a drawing handle (hDwg) returned by CadCreate. A handle is a 32-bit integer; 0 always means invalid / failure.

YuHandle dwg = CadCreate();
if (!dwg) { /* creation failed */ }

3. Embed a viewport

yucad renders into a child window that lives inside a window you own. Pass your host HWND and yucad builds an OpenGL surface inside it:

YuHwnd view = CadWndCreate(dwg, myHwnd, 0, 0, 0, 800, 600);

From here the library paints the black CAD viewport, the grid, the crosshair and all entities, and handles mouse/keyboard for pan, zoom and interactive commands. See Windows & OpenGL for the second, host-owned rendering mode (CadWin*).

4. Draw entities

Add geometry directly by coordinate. Coordinates are double X, Y, Z (2D drawings simply pass Z = 0). Every CadAdd* returns the new entity's handle:

YuHandle line   = CadAddLine(dwg, 0,0,0,  100,50,0);
YuHandle circle = CadAddCircle(dwg, 50,25,0,  20);
YuHandle text   = CadAddText(dwg, 10,10,0, "HELLO", 5.0, 0.0);
CadUpdate(dwg);   /* refresh the viewport */

5. Interactive commands

Instead of adding geometry by coordinate, start an interactive command and let the library run the mouse loop, rubber-band preview and snapping:

CadCmdStart(dwg, CAD_CMD_DRAW_LINE);   /* user now clicks points in the viewport */

Command IDs are the CAD_CMD_* constants. Register an event callback to be notified when a command finishes.

6. Save to DXF

CadFileSaveAs(dwg, "drawing.dxf");
/* ... later ... */
YuHandle dwg2 = CadCreate();
CadFileOpen(dwg2, "drawing.dxf");

7. Tear down

Destroy the document when done. This releases the viewport and all entities.

CadDestroy(dwg);
All calls for one document must happen on the same thread that owns its window — the host UI thread. See C ABI & Handles for the threading contract.