ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Accessing FaceRecords in AcDbPolygonMesh

1 REPLY 1
Reply
Message 1 of 2
crossfire639buy
218 Views, 1 Reply

Accessing FaceRecords in AcDbPolygonMesh

In the official documentation stated that AcDbPolygonMesh::openVertex provides access to the PolyMesh's vertices and FaceRecords. I need to get an information about about how many faces there are in AcDbPolygonMesh and which vertices belong to specific face.

 

So how to access FaceRecords in an AcDbPolygonMesh and examine the connectivity between vertices to identify the faces they form? Is it even possible using C++?

1 REPLY 1
Message 2 of 2
tbrammer
in reply to: crossfire639buy

An AcDbPolygonMesh is a simple MxN mesh. So any inner vertex with indices (i,j) is connected with (i+1,j), (i-1,j), (i,j+1) and  (i,j-1). For the outer vertices:

  • (M,j) and (0,j) are connected if mesh->isMClosed()==true
  • (i,N) and (i,0) are connected if mesh->isNClosed()==true 

You can query the vertices using an iterator like this:

struct MyPolygonVertexData {
	AcDbObjectId objId;
	AcGePoint3d  pt;
};

void cmdPolygonMesh()
{
	ads_point    pt;
	ads_name     ent;
	AcDbObjectId objId;

	if (acedEntSel(_T("\nSelect PolygonMesh: "), ent, pt) != RTNORM)
		return;
	if (acdbGetObjectId(objId, ent) != Acad::eOk)
		return;

	Acad::ErrorStatus es;
	AcDbPolygonMesh *mesh;
	Adesk::Int16 mSize, nSize, n=0;
	std::vector< std::vector<MyPolygonVertexData> > verticesMN;

	if ((es = acdbOpenObject(mesh, objId, AcDb::kForRead)) == Acad::eOk)
	{
		mSize = mesh->mSize();
		nSize = mesh->nSize();
		AcDbObjectIterator *it = mesh->vertexIterator();
		if (it)
		{
			AcDbPolygonMeshVertex *vert;
			MyPolygonVertexData vertex;
			std::vector<MyPolygonVertexData> verticesN;
			for (it->start(); !it->done(); it->step())
			{
				vertex.objId = it->objectId();
				if ((es = acdbOpenObject(vert, vertex.objId, AcDb::kForRead)) == Acad::eOk)
				{					
					vertex.pt = vert->position();
					verticesN.push_back(vertex);
					if (++n == nSize)
					{
						verticesMN.push_back(std::move(verticesN));
						verticesN.clear();
						n=0;
					}
					vert->close();
				}
			}
			delete it;
		}
		mesh->close();
	}
}


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report