DwgList 2021 DLL TechDocs

API Sample Program

// DwgListDllTest.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <string>
#include <iostream>
#include "DwgListDLL.h"
using namespace std;
/*
extern "C" DWGLIST_API bool dwglist_Init();
extern "C" DWGLIST_API bool dwglist_UnInit();
extern "C" DWGLIST_API int  dwglist_ProcessFile(char* fName);
extern "C" DWGLIST_API int  dwglist_getNumberOfXrefs();
extern "C" DWGLIST_API const char* dwglist_getXrefName(unsigned int count);
extern "C" DWGLIST_API int dwglist_getNumberOfBlocks();
extern "C" DWGLIST_API const char* dwglist_getBlockName(unsigned int count);
*/

bool fileExists(const std::string& fileName, int& errCode)
{
	struct stat statbuf;
	if (stat(fileName.c_str(), &statbuf) != -1)
		return true;
	else
		errCode = errno;
	return false;
}

int main(int argc, char* argv[])
{
	cout << "        DWGList DLL Test Program" << endl;
	cout << "Copyright (c) 2021 Tailor Made Software, Ltd" << endl;
	cout << "--------------------------------------------" << endl;
	cout << "Input File: " << argv[1] << endl << endl;
	int errCode;
	string dwgFileName = argv[1];
	string blockName;
	if (argc > 2)
		blockName = argv[2];
	if (fileExists(dwgFileName, errCode))
	{
		if (dwglist_Init("aaaa-bbbb-cccc-dddd-eeee-ffff-gggg") == eNoError)
		{
			dwglist_ProcessFile(argv[1]);
			int numXrefs = dwglist_getNumberOfXrefs();
			if (numXrefs > 0)
			{
				cout << "External References" << endl << "===================" << endl;
				for (int i = 0; i < numXrefs; i++)
				{
					string xrefName = dwglist_getXrefName(i);
					cout << xrefName << endl;
				}
			}
			else
				cout << "No External References in DWG file" << endl;

			int numImages = dwglist_getNumberOfRasterReferences();
			if (numImages > 0)
			{
				cout << endl << "External Images" << endl << "===================" << endl;
				for (int i = 0; i < numImages; i++)
				{
					string rasterName = dwglist_getRasterReferenceName(i);
					cout << rasterName << endl;
				}
			}
			else
				cout << endl << "No External Images in DWG file" << endl;

			int numFonts = dwglist_getNumberOfFonts();
			if (numFonts > 0)
			{
				cout << endl << "      Fonts" << endl << "===================" << endl;
				for (int i = 0; i < numFonts; i++)
				{
					string fontName = dwglist_getFontName(i);
					string fontPath = dwglist_getFontPath(i);
					cout << fontName << "    " << fontPath << endl;
				}
			}
			else
				cout << endl << "No Fonts in DWG file" << endl;

			if (!blockName.empty())
			{
				int numRefs = dwglist_getNumberOfInsertsForBlock((char *)blockName.c_str());
				if (numRefs > 0)
				{
					for (int iRef = 0; iRef < numRefs; iRef++)
					{
						string handle = dwglist_selectBlockReference(iRef);
						if (!handle.empty())
						{
							cout << endl << "------------ " << handle << " ------------ " << endl;
							int numAttrib = dwglist_getNumberOfAttributesForCurrentInsert();
							for (int iAttr = 0; iAttr < numAttrib; iAttr++)
							{
								string tag = dwglist_getAttributeTagForCurrentInsert(iAttr);
								string value = dwglist_getAttributeValueForCurrentInsert(iAttr);
								if (!tag.empty())
									cout << tag << "    " << value << endl;
							}
						}
					}
				}
				else
					cout << "No Insert for Block: " << blockName << endl;
			}

			dwglist_UnInit();
		}
		else
			cout << "Failed to initialize DWGList DLL" << endl;
	}
	else
	{
		cout << "Input DWG File does not exist, error code: " << errCode << endl;
	}
}


Last updated on 12 Jan 2021
Published on 12 Jan 2021