Сообщество
ObjectARX
отмена
Отображаются результаты для 
Показать  только  | Вместо этого искать 
Вы имели в виду: 

AcDbViewport::setVisualStyle() do not work

3 ОТВЕТ 3
РЕШЕНО
Ответить
Сообщение 1 из 4
Anonymous
852 просмотров, 3 ответов

AcDbViewport::setVisualStyle() do not work

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!

3 ОТВЕТ 3
Сообщение 2 из 4
tbrammer
в ответ: Anonymous

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.

Сообщение 3 из 4
tbrammer
в ответ: tbrammer

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.

Сообщение 4 из 4
Anonymous
в ответ: tbrammer

thx, it works!

Не нашли то, что искали? Задайте вопросы в сообществе или поделитесь своими знаниями.

Новая тема  

Autodesk Customer Advisory Groups


Autodesk Design & Make Report