<?xml encoding=”UTF-8″>By Balaji Ramamoorthy
In releases prior to AutoCAD 2015, the “acgsGetGsView” method provided access to the AcGsView of a viewport. In AutoCAD 2015, this method is not available and as a replacement, two other methods – “acgsGetCurrentAcGsView” and “acgsGetCurrent3dAcGsView” have been introduced. The sample code in this blog post and the comments are meant to clarify the differences and their usage.
#include "acgs.h"
<span>// Prior to AutoCAD 2015</span><span> </span>
<span>// Get the current viewport number</span><span> </span>
<span>struct</span><span> <span>resbuf</span><span> rb;</span></span>
<span>int</span><span> rt = acedGetVar(_T(<span>"CVPORT"</span><span> ), &rb);</span></span>
<span>if</span><span> (rt != RTNORM)</span>
<span>{</span>
acutPrintf(_T(<span>"\nError !"</span><span> ));</span>
<span>return</span><span> ;</span>
<span>}</span>
<span>int</span><span> vportNum = rb.resval.rint;</span>
<span>// Get the GS View associated with the viewport</span><span> </span>
AcGsView *pView1 = acgsGetGsView
(vportNum, <span>false</span><span> );</span>
<span>// If AutoCAD is in a shaded view, </span><span> </span>
<span>// then pView will be non-null.</span><span> </span>
<span>if</span><span> (pView1)</span>
<span>{</span> <span>//'re in shaded mode OR </span><span> </span>
<span>// a GS view has been already been created </span><span> </span>
<span>// and associated with viewport</span><span> </span>
acutPrintf(ACRX_T(<span>"We are in shaded mode..."</span><span> ));</span>
<span>}</span>
<span>else</span><span> </span>
<span>{</span>
<span>//'re in a 2D wireframe or a GsView has not </span><span> </span>
<span>// been created for this viewport ...</span><span> </span>
<span>// To create a GS View and associate with the </span><span> </span>
<span>// viewport use :</span><span> </span>
<span>// AcGsView *pView2 = acgsGetGsView(vportNum, true);</span><span> </span>
<span>//if(pView2 != NULL)</span><span> </span>
<span>//<span>{</span></span><span> </span>
<span>// acutPrintf(ACRX_T("Created a 3D GS View </span><span> </span>
<span>// and associated with viewport.."));</span><span> </span>
<span>//<span>}</span></span><span> </span>
acutPrintf(ACRX_T(<span>"We are in 2D wireframe mode..."</span><span> ));</span>
<span>}</span>
<span>// For AutoCAD 2015+</span><span> </span>
<span>// Get the current viewport number</span><span> </span>
<span>struct</span><span> <span>resbuf</span><span> rb;</span></span>
<span>int</span><span> rt = acedGetVar(_T(<span>"CVPORT"</span><span> ), &rb);</span></span>
<span>if</span><span> (rt != RTNORM)</span>
<span>{</span>
acutPrintf(_T(<span>"\nError ! "</span><span> ));</span>
<span>return</span><span> ;</span>
<span>}</span>
<span>int</span><span> vportNum = rb.resval.rint;</span>
Acad::ErrorStatus es;
<span>// Returns a GS View regardless of 2D or 3D</span><span> </span>
AcGsView *pGsView1 = acgsGetCurrentAcGsView(vportNum);
ASSERT(pGsView1 != NULL);
<span>// Returns a 3D GS view if a view is associated </span><span> </span>
<span>// with the viewport. If not this will return null. </span><span> </span>
<span>// But, a null value does not let us</span><span> </span>
<span>// assume it is 2D Wireframe, as a 3d AcGsView can </span><span> </span>
<span>// be created and associated with the viewport.</span><span> </span>
AcGsView *pGsView2 = acgsGetCurrent3dAcGsView(vportNum);
<span>if</span><span> (pGsView2 != NULL)</span>
<span>{</span>
<span>//'re in shaded mode OR </span><span> </span>
<span>// a 3D GS view has been created and </span><span> </span>
<span>// associated with viewport</span><span> </span>
acutPrintf(ACRX_T(<span>"We are in shaded mode..."</span><span> ));</span>
<span>}</span>
<span>else</span><span> </span>
<span>{</span>
<span>//'re in a 2D wireframe and a 3D GS view has </span><span> </span>
<span>// not been created yet...</span><span> </span>
<span>// Lets create a 3D GS View.</span><span> </span>
<span>// After the 3D GS view is created, both </span><span> </span>
<span>// acgsGetCurrentAcGsView and acgsGetCurrent3dAcGsView </span><span> </span>
<span>// will return the newly created GS View.</span><span> </span>
<span>// To create a GS View and associate it with the </span><span> </span>
<span>// viewport use :</span><span> </span>
<span>/*</span><span> </span>
<span> AcGsKernelDescriptor desc;</span><span> </span>
<span> desc.addRequirement( AcGsKernelDescriptor::k3DDrawing );</span><span> </span>
<span> AcGsView* pView2 = acgsObtainAcGsView(vportNum, desc);</span><span> </span>
<span> if(pView2 != NULL)</span><span> </span>
<span> <span>{</span></span><span> </span>
<span> acutPrintf(ACRX_T("Created a 3D GS View </span><span> </span>
<span> and associated with viewport.."));</span><span> </span>
<span> <span>}</span></span><span> </span>
<span> */</span><span> </span>
acutPrintf(ACRX_T(<span>"We are in a 2D wireframe mode..."</span><span> ));</span>
<span>}</span>

Leave a Reply