Hello, I have a question regarding the way to obtain the folder where I save my bitmaps from my program in order to save a csv file. The point is that when I save the bitmap I can choose the folder where I save my picture, but when I want to save my csv file, I have to set the folder in the program, so I would like to get the folder or make the program ask me for a folder to save. Thank you. My code is the following.
#include "StdAfx.h"
#include "TestPlugIn.h"
#include <iostream>
#include <fstream>
#include <math.h>
#include <algorithm>
using namespace std;
#include <Windows.h>
#include <stdio.h>
#include <list>
#include <string>
#include <sstream>
#include <vector>
static class CCommandTest theTestCommand;
CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
{
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CRhinoView* view = ::RhinoApp().ActiveView();
if( !view )
return CRhinoCommand::failure;
ON::display_mode dm = view->ActiveViewport().DisplayMode();
if( dm != ON::shaded_display )
{
view->ActiveViewport().SetDisplayMode( ON::shaded_display );
context.m_doc.ViewModified(view);
view->Redraw();
}
///////////////////////////////////////////////////////////////////
CWnd* pMainWnd = CWnd::FromHandle( RhinoApp().MainWnd() );
if( 0 == pMainWnd )
CRhinoCommand::nothing;
CRhinoGetFileDialog gf;
gf.SetScriptMode( context.IsInteractive() ? FALSE : TRUE );
////////////////////--------------------------------------//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////---------------select the name of the bitmap--------------------------------------------------//////////////////////////////
const wchar_t* file_name;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL rc = gf.DisplayFileDialog( CRhinoGetFileDialog::save_bitmap_dialog, file_name, pMainWnd );
if( !rc )
CRhinoCommand::cancel;
ON_wString filename = gf.FileName();
filename.TrimLeftAndRight();
if( filename.IsEmpty() )
CRhinoCommand::failure;
if( view )
{
CRect rect;
view->GetClientRect( rect );
CRhinoDib dib;
if( dib.CreateDib(rect.Width(), rect.Height(), 24, true) )
{
// Set these flags as you wish.
BOOL bIgnoreHighlights = TRUE;
BOOL bDrawTitle = FALSE;
BOOL bDrawConstructionPlane = FALSE;
BOOL bDrawWorldAxes = FALSE;
CRhinoObjectIterator it( CRhinoObjectIterator::normal_or_locked_objects,
CRhinoObjectIterator::active_and_reference_objects
);
if( view->ActiveViewport().DisplayMode() == ON::wireframe_display )
{
context.m_doc.DrawToDC( it, dib, dib.Width(), dib.Height(),
view->ActiveViewport().View(),
bIgnoreHighlights,
bDrawTitle,
bDrawConstructionPlane,
bDrawWorldAxes
);
}
else
{
context.m_doc.RenderToDC( it, dib, dib.Width(), dib.Height(),
view->ActiveViewport().View(),
bIgnoreHighlights,
bDrawTitle,
bDrawConstructionPlane,
bDrawWorldAxes,
view->ActiveViewport().GhostedShade()
);
}
dib.WriteToFile( filename );
}
}
ofstream myfile;
myfile.open ("D:/Myfolder/example.csv");
myfile << "This is the first cell in the first column\n";
myfile << "450\n";
myfile << "csv\n";
myfile << "6\n";
myfile << "colon\n";
myfile.close();