public void ExportToPython(ref string asciitext)
{
ModelDoc2 swModel;
ConfigurationManager swConfMgr;
Configuration swConf;
Component2 swRootComp;
this.saved_parts.Clear();
this.saved_shapes.Clear();
swModel = (ModelDoc2)this.mSWApplication.ActiveDoc;
if (swModel == null) return;
swConfMgr = (ConfigurationManager)swModel.ConfigurationManager;
swConf = (Configuration)swConfMgr.ActiveConfiguration;
swRootComp = (Component2)swConf.GetRootComponent3(true);
this.mSWApplication.GetUserProgressBar(out this.swProgress);
if (this.swProgress != null)
this.swProgress.Start(0, 5, "Exporting to Python");
num_comp =0;
asciitext = "# Chrono::Engine Python script from SolidWorks \n" +
"# Assembly: " + swModel.GetPathName() + "\n\n\n";
asciitext += "import ChronoEngine_PYTHON_core as chrono \n";
asciitext += "import builtins \n\n";
asciitext += "shapes_dir = '" + System.IO.Path.GetFileNameWithoutExtension(this.save_filename) + "_shapes" + "/' \n\n";
asciitext += "if hasattr(builtins, 'exported_system_relpath'): \n";
asciitext += " shapes_dir = builtins.exported_system_relpath + shapes_dir \n\n";
asciitext += "exported_items = [] \n\n";
asciitext += "body_0= chrono.ChBodyAuxRef()\n" +
"body_0.SetName('ground')\n" +
"body_0.SetBodyFixed(True)\n" +
"exported_items.append(body_0)\n\n";
if (swModel.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
{
// Write down all parts
PythonTraverseComponent_for_ChBody (swRootComp, 1, ref asciitext, -1);
// Write down all constraints
MathTransform roottrasf = swRootComp.GetTotalTransform(true);
if (roottrasf == null)
{
IMathUtility swMath = (IMathUtility)this.mSWApplication.GetMathUtility();
double[] nulltr = new double[] {1,0,0,0,1,0,0,0,1, 0,0,0, 1, 0,0,0};
roottrasf = (MathTransform)swMath.CreateTransform(nulltr);
}
Feature swFeat = (Feature)swModel.FirstFeature();
PythonTraverseFeatures_for_links(swFeat, 1, ref asciitext, ref roottrasf, ref swRootComp);
PythonTraverseComponent_for_links(swRootComp, 1, ref asciitext, ref roottrasf);
// Write down all markers in assembly (that are not in sub parts, so they belong to 'ground' object)
swFeat = (Feature)swModel.FirstFeature();
PythonTraverseFeatures_for_markers(swFeat, 1, ref asciitext, 0, roottrasf);
}
if (this.swProgress != null)
this.swProgress.End();
}