private void button1_Click(object sender, EventArgs e)
{
ChScale.L = (double)this.numeric_scale_L.Value;
ChScale.M = (double)this.numeric_scale_M.Value;
ChScale.T = (double)this.numeric_scale_T.Value;
ModelDoc2 swModel;
swModel = (ModelDoc2)this.mSWApplication.ActiveDoc;
if (swModel == null)
{
System.Windows.Forms.MessageBox.Show("Please open an assembly!");
return;
}
if (swModel.GetType() != (int)swDocumentTypes_e.swDocASSEMBLY)
{
System.Windows.Forms.MessageBox.Show("Please use this command when an assembly is open.");
return;
}
this.SaveFileDialog1.Filter = "C::E Python script (*.py)|*.py";
this.SaveFileDialog1.DefaultExt = "py";
//this.SaveFileDialog1.FileName = "mechanism";
this.SaveFileDialog1.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
DialogResult result = SaveFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string asciitext = "";
this.save_filename = SaveFileDialog1.FileName;
if (this.checkBox_surfaces.Checked)
{
string save_directory = System.IO.Path.GetDirectoryName(SaveFileDialog1.FileName);
this.save_dir_shapes = save_directory + "\\" + System.IO.Path.GetFileNameWithoutExtension(this.save_filename) + "_shapes";
//System.Windows.Forms.MessageBox.Show("DIRECTORY FOR SHAPES: " + save_dir_shapes);
DirectoryInfo mi = System.IO.Directory.CreateDirectory(this.save_dir_shapes);
if (mi.Exists == false)
System.Windows.Forms.MessageBox.Show("ERROR. Can't create directory for .obj surfaces: " + this.save_dir_shapes);
// ***TEST*** Dump also hierarchy for test
string asciidump = "";
this.ExportToDump(ref asciidump);
FileStream dumpstream = new FileStream(this.save_dir_shapes + "\\" + "dump_log.txt", FileMode.Create, FileAccess.ReadWrite);
StreamWriter dumpwriter = new StreamWriter(dumpstream);
dumpwriter.Write(asciidump);
dumpwriter.Flush();
dumpstream.Close();
}
// Do the conversion into a Python text block!!!
// This will scan the low level hierarchy of the assembly
// and its mating constraints and create the proper Chrono::Engine
// links.
this.ExportToPython(ref asciitext);
byte[] byteArray = Encoding.ASCII.GetBytes(asciitext);
MemoryStream stream = new MemoryStream(byteArray);
Stream fileStream;
fileStream = SaveFileDialog1.OpenFile();
stream.Position = 0;
stream.WriteTo(fileStream);
fileStream.Close();
if (this.checkBox_savetest.Checked)
{
string save_directory = System.IO.Path.GetDirectoryName(SaveFileDialog1.FileName);
try
{
//System.Windows.Forms.MessageBox.Show("GetCurrentWorkingDirectory: " + this.mSWApplication.GetCurrentWorkingDirectory());
//System.Windows.Forms.MessageBox.Show("GetExecutablePath: " + this.mSWApplication.GetExecutablePath());
//System.Windows.Forms.MessageBox.Show("GetDataFolder: " + this.mSWApplication.GetDataFolder(true));
if (!System.IO.File.Exists(save_directory + "\\run_test.py"))
System.IO.File.Copy(this.mSWApplication.GetExecutablePath() + "\\chronoengine\\run_test.py", save_directory + "\\run_test.py");
if (!System.IO.File.Exists(save_directory + "\\_template_POV.pov"))
System.IO.File.Copy(this.mSWApplication.GetExecutablePath() + "\\chronoengine\\_template_POV.pov", save_directory + "\\_template_POV.pov");
}
catch (Exception exc)
{
System.Windows.Forms.MessageBox.Show("Cannot write the test Python program. \n Make sure that the template chronoengine\\run_test.py is in your SolidWorks directory.\n\n" + exc.Message);
}
}
}
// System.Windows.Forms.MessageBox.Show("Ok, saved");
}