Draw Horizontal Text in Custom Entity

By Philippe Leefsma

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”>
 


Comments

2 responses to “Draw Horizontal Text in Custom Entity”

  1. could you provide an version of c#?

  2. Philippe Avatar
    Philippe

    Hi There,
    Well, in .Net custom entities do not exist but you could achieve the same result by using “DrawableOverrule.ViewportDraw” method.
    I don’t have a sample ready to send you unfortunately. You should be able to find overrule sample on this blog or on Kean’s Through The Interface blog.
    I hope it helps.

Leave a Reply to matlabCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading