Make Viewport snapshot


#1

Hi,

I’m looking for some ways to make a viewport snapshot. Capture Still Image is a macro and I’ve looked into this and it looks way too complicated for me. Do you guys have any ideas how to do this any other way?

I’m not looking for rendering viewport, but making just a one snapshot like a preview tool does. I would use preview, but the only downside of using preview is that it lacks in control.
preview tool maxscript help

I want to take just a one image (jpg, png…) but unfortunately always the window appear for the image to save. And I dont want this.

I want my tool to be able to save the image of the current viewport.


Remove selected objects that are not actually visible in the current view
Get 2D image from .max file
#2

something like this ?

fn viewport_snapshot fname frame =
(	
	snapshot_name = (getDir #preview)+"/" + fname;
	view_size = getViewSize()
	anim_bmp = bitmap view_size.x view_size.y filename:snapshot_name
	sliderTime = frame
	dib = gw.getViewportDib()
	copy dib anim_bmp
	save anim_bmp
	close anim_bmp
	gc()
)

viewport_snapshot "temp.jpg" 30f

#3

Thx!:slight_smile:

Sometimes it’s impossible to find those things in max help…


#4

I’m after the same but SDK. I almost have it sorted from the example but getActiveViewport() is not use in the interface class? It is grayed out? Looke in all the other and can’t find where they moved it to?


void BasicTools::Image(){
	BITMAPINFO *bmi = NULL;
	BITMAPINFOHEADER *bmih;
	BitmapInfo biFile;
	Bitmap *map;
	int size;
	TheManager->SelectFileOutput(&biFile,ip->GetMAXHWnd(), _M("Testing"));
	if(!biFile.Name()[0])
		return;
	ViewExp* view = ip->getActiveViewport();
	view->getGW()->getDIB(NULL, &size);
	bmi = (BITMAPINFO *)malloc(size);
	bmih = (BITMAPINFOHEADER *)bmi;
	view->getGW()->getDIB(bmi, &size);
	biFile.SetWidth((WORD)bmih->biWidth);
	biFile.SetHeight((WORD)bmih->biHeight);
	biFile.SetType(BMM_TRUE_32);
	map = TheManager->Create(&biFile);
	map->OpenOutput(&biFile);
	map->FromDib(bmi);
	map->Write(&biFile);
	map->Close(&biFile);
	if(bmi)
	free(bmi);
	ip->ReleaseViewport(view);
}

I did see in interface7 there is…
But this give me an error on ip7->SetActiveViewport


int MyView = ip7->getActiveViewportIndex(); 	
ViewExp* view = ip7->SetActiveViewport(MyView);	

Also not seeing a ip->ReleaseViewport(view); in any interface class.

Any thoughts


#5

an mxs function would look something like this, you should be able to convert it

Value* saveViewport_cf(Value** arg_list, int count)
{
	check_arg_count(saveViewport, 1, count);

	ViewExp *vpt = MAXScript_interface->GetActiveViewport();
	GraphicsWindow *gw = vpt->getGW();
	BITMAPINFO *bmi = NULL;
	BITMAPINFOHEADER *bmih;
	BitmapInfo bi;
	Bitmap *bmp;
	int size;
	gw->getDIB(NULL, &size);
	bmi  = (BITMAPINFO *)malloc(size);
	bmih = (BITMAPINFOHEADER *)bmi;
	gw->getDIB(bmi, &size);
	bi.SetWidth((WORD)bmih->biWidth);
	bi.SetHeight((WORD)bmih->biHeight);
	bi.SetType(BMM_TRUE_32);
	bmp = CreateBitmapFromBitmapInfo(bi);
	bmp->FromDib(bmi);
	free(bmi);	
	MAXScript_interface->ReleaseViewport(vpt);
	bi.SetName(arg_list[0]->to_string());
	bmp->OpenOutput(&bi);
	bmp->Write(&bi);
	bmp->Close(&bi);
	bmp->DeleteThis();  

	return &ok;
}

#6

Ok really dumb question what is this “mxs function” is this for function publishing? I remember putting a function in your [useful mxs function] thread and you asked what does this have to do with mxs function.


#7

mxs is short for maxscript, and a sdk mxs function is a function that extends maxscript via a dlx plugin. see the mxsagni project in the samples


#8

So I guess the question I would have now is how would I get…
ViewExp *vpt
and then Release it.

ip7->GetActiveViewExp();
is close but does not give me a pointer


#9

No error but big crash


void BasicTools::Image(){
	int viewPanelIndex = 1;
	int index = 1;
	IViewPanel* pPanel = GetViewPanelManager()->GetViewPanel(viewPanelIndex);
	BITMAPINFO *bmi = NULL;
	BITMAPINFOHEADER *bmih;
	BitmapInfo biFile;
	Bitmap *map;
	int size;
	TheManager->SelectFileOutput(&biFile,
	ip->GetMAXHWnd(), _M("Testing"));
	if(!biFile.Name()[0])
	return;

	ViewExp *vpt = nullptr;
	vpt = pPanel->GetViewExpByIndex(index).ToPointer();

	vpt->getGW()->getDIB(NULL, &size);
	bmi = (BITMAPINFO *)malloc(size);
	bmih = (BITMAPINFOHEADER *)bmi;
	vpt->getGW()->getDIB(bmi, &size);
	biFile.SetWidth((WORD)bmih->biWidth);
	biFile.SetHeight((WORD)bmih->biHeight);
	biFile.SetType(BMM_TRUE_32);
	map = TheManager->Create(&biFile);
	map->OpenOutput(&biFile);
	map->FromDib(bmi);
	map->Write(&biFile);
	map->Close(&biFile);
	if(bmi)
	free(bmi);
	// ip->ReleaseViewport(vpt);
}


#10
GetCOREInterface()->GetActiveViewport();

only has 343 matches when searching the samples


#11

Haha, this all works now.

my bad I set the index viewPanelIndex = 1; and Not 0


void BasicTools::Image(){
	int viewPanelIndex = 0;
	int index = 3;
	IViewPanel* pPanel = GetViewPanelManager()->GetViewPanel(viewPanelIndex);
	BITMAPINFO *bmi = NULL;
	BITMAPINFOHEADER *bmih;
	BitmapInfo biFile;
	Bitmap *map;
	int size;
	TheManager->SelectFileOutput(&biFile, ip->GetMAXHWnd(), _M("Testing"));
	//if(!biFile.Name()[0])
	//	return;

	ViewExp *vpt = nullptr;
	vpt = pPanel->GetViewExpByIndex(index).ToPointer();

	vpt->getGW()->getDIB(NULL, &size);
	bmi = (BITMAPINFO *)malloc(size);
	bmih = (BITMAPINFOHEADER *)bmi;
	vpt->getGW()->getDIB(bmi, &size);
	biFile.SetWidth((WORD)bmih->biWidth);
	biFile.SetHeight((WORD)bmih->biHeight);
	biFile.SetType(BMM_TRUE_32);
	map = TheManager->Create(&biFile);
	map->OpenOutput(&biFile);
	map->FromDib(bmi);
	map->Write(&biFile);
	map->Close(&biFile);
	if(bmi)
	free(bmi);
	// ip->ReleaseViewport(vpt);
}

I’m not using ReleaseViewport not sure if this will give me problems in the end


#12

Sorry for my stupid question, but I know nothing about SDK:
How can I insert your code in a maxscript file to test it?


#13

No sorry, it has to be in a c++ plugin with function publishing to use in maxscript


#14

hellow how to rename as jpg name four digits for examples

ı want to save

for t = animationrange.start to animationrange.end do
(

viewport_snapshot (t as string + “_.jpg”) t

)

jpgs like that 0001.jpg ,0002.jpg ,0003.jpg ,0004.jpg


#15

you can use this hack… :slight_smile:
http://cganimator.com/uiaccessor-mini-tutorial-how-to-control-make-preview-dialog/