We have an exciting announcement about badges coming in May 2025. Until then, we will temporarily stop issuing new badges for course completions and certifications. However, all completions will be recorded and fulfilled after May 2025.
3D Design

3D Design

Topics related to Ansys Discovery and Ansys SpaceClaim.

SpaceClaim.API.V21.Session

    • downie
      Subscriber

      The Session class in the SpaceClaim API provided a way to start a SpaceClaim session and load an AddIn DLL.

      Is there anything like that (currently or planned) for Discovery?

      Thank you.

       

    • Devendra Badgujar
      Forum Moderator

      Hello Blair, 

      When you say start a SpaceClaim session through the Session class are you referring to a .NetRemoting call? Or something else?  

      I will check what the session class does but in general the way to start Discovery is to provide a path to the executable and a manifest file to load add-ins. There is no need of any class to achieve this. 

      Regards,

      Devendra

    • 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;
      }

       

Viewing 2 reply threads
  • The topic ‘SpaceClaim.API.V21.Session’ is closed to new replies.