DwgList 2021 DLL TechDocs

Blocks

Information on Blocks

DwgList DLL can easily provide information about Blocks in the DWG file. The DWG file must be opened using the dwglist_ProcessFile command(see Initialization). Processing Blocks is very simple. You call dwglist_getNumberOfBlocks to get the number of Blocks in the file, then you loop through each Block to get the information about it. Currently you can only get the Block name using the dwglist_getBlockName command and the Attributes defined for that Block (see below), but if you need more information let us know and we can easily add it.

int numBlocks = dwglist_getNumberOfBlocks();
if (numBlocks > 0)
{
	cout << "      Blocks" << endl << "===================" << endl;
	for (int i = 0; i < numBlocks; i++)
	{
		string blockName = dwglist_getBlockName(i);
		cout << blockName << endl;
	}
}
else
	cout << "No Blocks in DWG file" << endl;

Attribute Information

DwgList DLL can easily provide Attribute information about each Block Insert of the current block in the DWG file. Processing Attribute information is very simple. You call dwglist_getNumberOfInsertsForBlock to get the number of inserts for that particular block in the file, then you loop through each insert to get the information about it. For each insert you get the Handle for that insert (the unique identifier used in AutoCAD for each entity). Given the Insert Handle you get the number of Attributes using dwglist_getNumberOfAttributesForCurrentInsert and then the Tag and Value pair for that Attribute using dwglist_getAttributeTagForCurrentInsert and dwglist_getAttributeValueForCurrentInsert respectively.

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;

Last updated on 16 Feb 2021
Published on 15 Feb 2021