Q:
How to draw a text in a custom entity which is always horizontal irrespective of view direction and plot rotation?
A:
You can use the AcGiViewport::getCameraUpVector() function to get the up vector for the current view direction. Using the up vector one can easily calculate the flow direction for drawing the text horizontal to the current view.
During plot, one needs to take into account the plot rotation. During the plot, the drawing is rotated depending on the drawing orientation(Portrait or Landscape).
Of course, this can be implemented only in the viewportDraw() override of the custom entity, since this is where the viewport-specific graphics are drawn. The following sample shows how to implement this:
void AsdkcusEnt::viewportDraw(AcGiViewportDraw * mode)
{
//draw the text
AcGeVector3d vecUp;
mode->viewport().getCameraUpVector(vecUp);
AcGeVector3d vecFlow = vecUp.crossProduct(
mode->viewport().viewDir());
//check the context
if (mode->context()->isPlotGeneration())
{
//Get the plot configuration of the current layout
AcApLayoutManager *pLayMan = (AcApLayoutManager *)
acdbHostApplicationServices()->layoutManager();
AcDbLayout *pLay = pLayMan->findLayoutNamed(
pLayMan->findActiveLayout(Adesk::kTrue),Adesk::kTrue);
// Check if this plot is rotated or not
double pi = 3.14159265;
switch(pLay->plotRotation())
{
case AcDbPlotSettings::PlotRotation::k90degrees:
vecFlow.rotateBy(-pi/2,mode->viewport().viewDir());
break;
case AcDbPlotSettings::PlotRotation::k180degrees:
vecFlow.rotateBy(pi,mode->viewport().viewDir());
break;
case AcDbPlotSettings::PlotRotation::k270degrees:
vecFlow.rotateBy(pi/2,mode->viewport().viewDir());
break;
}
pLay->close();
mode->geometry().text(
AcGePoint3d(10,10,0),
mode->viewport().viewDir(),
vecFlow, 10, 1, 0,
L"Test");
}
else
{
mode->geometry().text(
AcGePoint3d(10,10,0),
mode->viewport().viewDir(),
vecFlow, 10, 1, 0,
L"Test");
}
AcDbEntity::viewportDraw(mode);
}
<
p style=”line-height: normal;margin: 0in 0in 0pt” class=”MsoNormal”>

Leave a Reply to matlabCancel reply