Blair Downie
Subscriber

Devendra,

Below is the C++ code that we use to launch SpaceClaim and then load our Addin.

Regards,

Blair

// RunSpaceClaim.cpp : main project file.
 
#include "stdafx.h"
 
using namespace System;
using namespace System::Collections::Generic;
using namespace SpaceClaim::Api::V22;
using namespace SpaceClaim::Api::V22::Extensibility;
#ifdef SimModS140
 using namespace LuaFileExec;
#else
 using namespace SC_SimScript;
#endif
 
Session^ GetSpaceClaimSession() {
ICollection^ SCsessions = Session::GetSessions();
for each (Session^ s in SCsessions)
return s;
return nullptr;
}
 
public ref class APICall {
public:
static String^ luaFile;
static bool addinLoaded;
static void CallAddin() {
Console::WriteLine(luaFile);
try {
LuaInterpreter^ luaInterp = AddIn::GetInstance();
if ( luaInterp != nullptr ) {
luaInterp->ProcessFile(luaFile);
addinLoaded = true;
}
else {
#ifdef SimModS140
Console::WriteLine(L"Unable to create SpaceClaim addin LuaExecFile");
#else
Console::WriteLine(L"Unable to create SpaceClaim addin SC_SimScript");
#endif
addinLoaded = false;
}
}
catch (...) {
#ifdef SimModS140
Console::WriteLine(L"Unhandled exception thrown by our lua interpreter LuaExecFile");
#else
Console::WriteLine(L"Unhandled exception thrown by our lua interpreter SC_SimScript");
#endif
addinLoaded = false;
}
}
};
 
int main(array ^args)
{
    Console::WriteLine(L"Executing lua file within SpaceClaim");
    Console::WriteLine(L"Current working directory is {0}",IO::Directory::GetCurrentDirectory());
String^ scdm = System::Environment::GetEnvironmentVariable("SCDM");
Console::WriteLine(L"SpaceClaim executable directory is {0}", scdm);
 
Api::Initialize();
 
Session^ session = GetSpaceClaimSession();
bool startSpaceClaim = false;
if ( session == nullptr ) {
try {
StartupOptions^ sopts = gcnew StartupOptions(30000);
sopts->ShowSplashScreen = false;
sopts->ShowApplication = false;
sopts->ManifestFile = args[0];
sopts->ExecutableFolder = scdm;
session = Session::Start(sopts);
if ( session == nullptr ) {
Console::WriteLine(L"Failed to start SpaceClaim");
return 1;
}
startSpaceClaim = true;
}
catch (...) {
Console::WriteLine(L"Failed to start SpaceClaim - unhandled exception");
return 1;
}
}
 
Api::AttachToSession(session);
APICall::luaFile = args[1];
int result = 0;
try {
WriteBlock::ExecuteTask( "run interpreter", gcnew Task(&APICall::CallAddin));
}
catch (System::IO::FileNotFoundException^) {
Console::WriteLine(L"ExecuteTask failed - file not found exception");
result = 1;
}
 
if (startSpaceClaim)
session->Stop();
if (!APICall::addinLoaded)
result = 1;
 
Console::WriteLine(L"Done");
//Console::ReadLine();
 
    return result;
}

Â