Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

To Check out our forum post to learn how to programmatically create standard views for CAD models in PDF,

  1. Get the bounding box of the model and calculate the camera center point.

Code Block
//To get the camera center
A3DBoundingBoxData pboxdata;
A3D_INITIALIZE_DATA(A3DBoundingBoxData, pboxdata);
A3DMiscComputeBoundingBox(pModelFile, 0, &pboxdata);

double centerx, centery, centerz;
centerx = (pboxdata.m_sMax.m_dX + pboxdata.m_sMin.m_dX) / 2;
centery = (pboxdata.m_sMax.m_dY + pboxdata.m_sMin.m_dY) / 2;
centerz = (pboxdata.m_sMax.m_dZ + pboxdata.m_sMin.m_dZ) / 2;

2. The position of the camera is a point that represents the position of the viewpoint. Normally, the camera position is placed slightly away from the objects that you wish to view

More informtion for the Camera definition https://docs.techsoft3d.com/publish/latest/guide/authoring/defining_3d.html#camera-definition

Code Block
//To compute the position that slighlty aways 
double highestValue = centerz;
double pboxdataMax = pboxdata.m_sMax.m_dZ;
double pboxdataMin = pboxdata.m_sMin.m_dZ;

if (highestValue < centerx)
{
	highestValue = centerx;
	pboxdataMax = pboxdata.m_sMax.m_dX;
	pboxdataMin = pboxdata.m_sMin.m_dX;
}
if (highestValue < centery)
{
	highestValue = centery;
	pboxdataMax = pboxdata.m_sMax.m_dY;
	pboxdataMin = pboxdata.m_sMin.m_dY;
}

double maxFactor = (pboxdataMax - highestValue) * 5;
double minFactor = (pboxdataMin - highestValue) * 5;

3. Finally, we can create standard views (Right, Left, Top, Bottom, Front, Back and Iso)

Code Block
// creating the views
A3DPDFView* pViewDef;
A3DPDFView* pViews[6]; memset(pViews, 0, 4 * sizeof(A3DPDFView*));
A3DUTF8Char viewnameDef[] = "Right View";
const A3DUTF8Char* viewnames[6] = { "Left View", "Top View","Bottom View", "Front View", "Back View", "ISO view" };
// Right View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	pboxdata.m_sMax.m_dX + maxFactor, centery, centerz,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	true, viewnameDef, &pViewDef));

// Left View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	pboxdata.m_sMin.m_dX + minFactor, centery, centerz,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	false, viewnames[0], &pViews[0]));


// Top View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	centerx, centery, pboxdata.m_sMax.m_dZ + maxFactor,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	false, viewnames[1], &pViews[1]));

// Bottom View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	centerx, centery, pboxdata.m_sMin.m_dZ + minFactor,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	false, viewnames[2], &pViews[2]));

// Front View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	centerx, pboxdata.m_sMin.m_dY + minFactor, centerz,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	false, viewnames[3], &pViews[3]));

// Back View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	centerx, pboxdata.m_sMax.m_dY + maxFactor, centerz,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	false, viewnames[4], &pViews[4]));


// ISO View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	pboxdata.m_sMax.m_dX + maxFactor, pboxdata.m_sMax.m_dY + maxFactor, pboxdata.m_sMax.m_dZ + maxFactor,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	false, viewnames[5], &pViews[5]));

4. You may adjust the values to find the best fitting for your usage.