AcDbViewport::setVisualStyle() do not work

AcDbViewport::setVisualStyle() do not work

Anonymous
Not applicable
1,145 Views
3 Replies
Message 1 of 4

AcDbViewport::setVisualStyle() do not work

Anonymous
Not applicable

hi, community.

I'm trying to change viewport's visual style, but it doesn't, visual style label in layout winodw change, but make no change in entities.

 

static void func(AcDbViewport* pViewport, const AcGePoint3d& modelCenter)
{
	if (pViewport == nullptr)
	{
		ASSERT(pViewport != nullptr);
		return;
	}

	acedSetCurrentVPort(pViewport);
	acedMspace();

	AcDbObjectId vsId = AcDbObjectId::kNull;
	AcDbDictionaryPointer pNOD(acdbHostApplicationServices()->workingDatabase()->visualStyleDictionaryId(), AcDb::kForRead);
	pNOD->getAt(ACRX_T("Conceptual"), vsId);

	pViewport->setVisualStyle(vsId);

	//acedCommand(RTSTR, _T("_vscurrent"), RTSTR, _T("_c"), 0);
	acedCommand(RTSTR, _T("-view"), RTSTR, _T("_swiso"), 0);

	pViewport->setViewTarget(modelCenter);

	pViewport->updateDisplay();
	pViewport->syncModelView();
}

the entities in the viewport is still 2D wireframe, which is default, make no change.

 

Any wrong with my code?

pls help

thx!

0 Likes
Accepted solutions (1)
1,146 Views
3 Replies
Replies (3)
Message 2 of 4

tbrammer
Advisor
Advisor

You shoulnd't call  acedCommand(RTSTR, _T("-view"), RTSTR, _T("_swiso"), 0);
while you have pViewport open.

pViewport->updateDisplay()  is called automatically when you close the viewport. Usually you don't need to call it.

I think you shouldn't call pViewport->syncModelView() as well. According to the docs it

    "updates the parameters of the AcDbViewport with parameters in the associated view."

which is not what you want. Maybe you have to call REGEN or ads_regen() ( see here ) to update the display.

Try this:

 

void SetVpCenterAndStyle(AcGePoint3d modelCenter)
{
	AcDbObjectId vsId = AcDbObjectId::kNull;
	AcDbDictionaryPointer pNOD(acdbHostApplicationServices()->workingDatabase()->visualStyleDictionaryId(), AcDb::kForRead);
	pNOD->getAt(ACRX_T("Conceptual"), vsId);
		
	AcDbViewport *pViewport;
	AcDbObjectId idVP;
	if ( (es=acdbOpenObject(pViewport, idVP, AcDb::kForWrite)) == Acad::eOk )
	{
		pViewport->setVisualStyle(vsId);
		pViewport->setViewTarget(modelCenter);
		pViewport->close();
	}
	
	void ads_regen();
	ads_regen();
}

Note that this code only sets the view target and the visual style.

You can also set the view direction directly within the viewport without using acedCommand(), which should be avoided anyway.

 


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

0 Likes
Message 3 of 4

tbrammer
Advisor
Advisor
Accepted solution

I've just tested my proposed code. It will work if the viewport already has a "3D visual style" but not if it has the style "2D wireframe".

If you switch from "2D wireframe" to a 3D visual style, an AcGsView needs to be created. This code works for AutoCAD 2018:

 

//Need AcDrawBridge.lib for AcGsKernelDescriptor::k3DDrawing
#pragma comment(lib, "AcDrawBridge.lib")

void SetVP(AcGePoint3d modelCenter, AcDbObjectId idVP)
{
	Acad::ErrorStatus es;
	AcDbObjectId vsId = AcDbObjectId::kNull;
	AcDbDictionaryPointer pNOD(acdbHostApplicationServices()->workingDatabase()->visualStyleDictionaryId(), AcDb::kForRead);
	pNOD->getAt(ACRX_T("Conceptual"), vsId);

 
	int vpNum = -1;
	AcDbViewport *pViewport;	
	if ((es = acdbOpenObject(pViewport, idVP, AcDb::kForWrite)) == Acad::eOk)
	{
		vpNum = pViewport->number();
		pViewport->setVisualStyle(vsId);
		pViewport->setViewTarget(modelCenter);
		pViewport->close();
	}

	AcGsView *pView = acgsGetCurrent3dAcGsView(vpNum);
	if (!pView)
	{
		AcGsKernelDescriptor gsKernel;
		gsKernel.addSupport(AcGsKernelDescriptor::k3DDrawing);
		pView = acgsObtainAcGsView(vpNum, gsKernel);    // create if necessary.
	}
	if (pView)
		pView->show();

	void ads_regen();
	ads_regen();
}

 


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

Message 4 of 4

Anonymous
Not applicable
thx, it works!
0 Likes