Showing results for 
Search instead for 
Did you mean: 

C++ std::async with Solid Edge framework



This is my first post so I appologize for bad use of this forum.


I try to make a simple program to produce flat pattern in DXF with some sheet metal document.

I made it in C++ because I would like to explore possibities to make some task in parallel.


Thanks to tutorials on the web (thanks to J.Newell) I succeed to make my program in a synchonous mode.

I have create a class ClassSE


#pragma once
#include <vector>

class ClassSE
	bool IsWorking();
	bool DepliageAuto(std::string F_Tolerie);

	bool WorkInProgress;
	SolidEdgeFramework::ApplicationPtr pApplication;




I open Solid Edge Instance with


std::vector<ClassSE> lst_WindowsSE(nbFenetres);



This is the constructor


//Constructeur de la classe SE

	pApplication = NULL;
	// Start a new Solid Edge instance.
	hr = pApplication.CreateInstance(L"SolidEdge.Application");
	// Show the main window.
	pApplication->Visible = VARIANT_TRUE;
	pApplication->DisplayAlerts = false;

	WorkInProgress = false;


and then in a while loop, I tried to make DXF by multiple solid edge instance in a same time using std::async method



	//Traitement des fichiers
		//Initialisation des variables de boucles
		sortieBoucle = false;
		j = 0;
		i = 0;
		size_t nbFiles = FilesPsm.size();
		while (!sortieBoucle)

			if ((!lst_WindowsSE[i].IsWorking())&&(j<nbFiles)) //Si la fenetre etudié ne travaille pas
				auto DeplieTermine = std::async(std::launch::async, &ClassSE::DepliageAuto, lst_WindowsSE[i], FilesPsm[j]); // this function don't work
				//DeplieTermine = lst_WindowsSE[i].DepliageAuto(FilesPsm[j]); //This function works fine
				if (j < nbFiles) //On vérifie si on a pas fini de traiter tous les fichiers
					Sleep(100); // pause de 0.1s
					if (i < (nbFenetres - 1))
						i++; //On va faire travailler l'instance de Solid Edge suivante
						i = 0; //On repart de l'instance de Solid Edge n° 0
					sortieBoucle = true; //On a traiter tout les fichiers donc il faut sortir de la boucle

The method of my class ClassSE that I call is below

//Methode pour ouvrir un fichier tolerie et enregistrer son deplier dans le mm dossier
bool ClassSE :: DepliageAuto(std::string Fichier)
	WorkInProgress = true; // Cette instance de Solid edge est occupé, elle commence un travail

	SolidEdgeFramework::DocumentsPtr pDocuments = NULL;
	SolidEdgeFramework::SolidEdgeDocumentPtr pDocument = NULL;
	SolidEdgePart::SheetMetalDocumentPtr pSheetMetal = NULL;
	SolidEdgePart::FlatPatternModelsPtr pDepliesTole = NULL;
	SolidEdgePart::FlatPatternModelPtr pDeplieTole;
	_bstr_t FichierTolerie(Fichier.c_str()); // Conversion de std::string vers _bsr_t

	bool result;

	pDocuments = pApplication->Documents;
	pDocument = pDocuments->Open(FichierTolerie);
	pSheetMetal = pDocument;
	pDepliesTole = pSheetMetal->FlatPatternModels;
	int NbDepl = pDepliesTole->Count;

	if (NbDepl != 0)
		pDeplieTole = pDepliesTole->Item(1); //La collection commence à 1

		if (pDeplieTole->IsUpToDate)
			pSheetMetal->Models->SaveAsFlatDXFEx(FichierTolerie + ".dxf", NULL, NULL, NULL, true); // enregistrement du DXF à partir du model déplié
			::wprintf(FichierTolerie +  L" : deplie termine \n");
			result= true;
			::wprintf(L"Le deplie n est pas a jour \n");
			result = false;

		//Libération de la mémoire du deplié uniquement si celui-ci était présent dans le fichier tolerie
		::wprintf(FichierTolerie + L" : Pas de deplie dans le fichier \n");
		result = false;

	//Fermeture du document et nettoyage de la mémoire
	pDocument = pDocuments->Close();
	WorkInProgress = false; // Le travail est fini, l'instance est disponible
	return result;

As anyone could see I'm not c++ expert. There are probalbly many optimization possible.

I choose C++ langage because I was thinking that pointers on Solid Edge instance or documents instead of using active application or active documents could allowed parallelism.


I searched also near std::execution:Smiley Tonguear_unseq but I can't compile with VS2017 community.

I guess also I didn't understand well Com initialisation even if I put instruction ::CoInitialize(NULL);::CoUninitialize(); at begin and end of my main.


Could anyone help me please ?


The line below create a pop up debug error Microsoft Visual C++ Runtime library with  abort() has been called

auto DeplieTermine = std::async(std::launch::async, &ClassSE::DepliageAuto, lst_WindowsSE[i], FilesPsm[j]);

and when I click on retry, I go to this part of framewrk.tli

#pragma implementation_key(60)
inline HRESULT SolidEdgeFramework::Application::Quit ( ) {
    return _com_dispatch_method(this, 0x28, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);

Thanks by advance,


Re: C++ std::async with Solid Edge framework




The right place to post develoment related messages is the dedicated Solid Edge Developer Forum



Tushar Suradkar

Production ST10, Beta Testing ST11

Visual Studio 2015 Enterprise, Spy for Solid Edge.


Re: C++ std::async with Solid Edge framework


Ok Sorry.


I opened the same discussion on the right forum there :


Thanks for your answer. I think I find your blog about c++ with Solid Edge on surfandcode and I will use it to add an graphic interface to my small program waiting a solution to make tasks parallel.


Could someone supress my SolidEdge forum post wich is not at the right place ?