2 Replies Latest reply on Aug 22, 2018 9:50 PM by Thiago Motta

    How to Import a Parasolid file in C# as a Standalone build

    Thiago Motta

      Hello,

       

      I've just started working with SolidWords and wanted to see if it was possible to create a C# Project to start Solidworks as a background process (not visible at all) and load a Parasolid file, but Im not finding the correct documentation to help me out. The closest link I found was https://forum.solidworks.com/thread/94623, which was great already, but at the end didnt help me get through with it.

       

      This is what I have so far: A simple Console Project with the following code

       

      class Program
      {
          static SldWorks.SldWorks _swApp;
      
      
          static void Main( string [ ] args )
          {
              try
              {
                  Test( args );
              }
              catch ( Exception ex )
              {
                  Console.WriteLine( ex.Message );
              }
      
      
              if ( _swApp != null )
              {
                  _swApp.ExitApp( ); //Exits SolidWorks running in the background
                  _swApp = null;
              }
          }
      
      
          static void Test( string [ ] args )
          {
              SldWorks.SldWorks _swApp = new SldWorks.SldWorks( ); //Correctly starts a new instance of solidwords if one isnt opened already
              ModelDoc2 swModel;
      
      
              swModel = _swApp.ActiveDoc as ModelDoc2;
      
      
              string fileName = null;
              string argString = null;
              int Err = 0;
      
      
              fileName = "D:\\temp\\HEAD-A-0018.x_t";
              argString = "r";
      
      
              dynamic importData = _swApp.GetImportFileData( fileName );
              swModel = ( ModelDoc2 )_swApp.LoadFile4( fileName, argString, importData, ref Err );
      
      
          }
      }
      

      This is throwing the following exception:

      An exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Dynamic.dll but was not handled in user code

      Additional information: Element not found. (Exception from HRESULT: 0x8002802B (TYPE_E_ELEMENTNOTFOUND))

      What I could tell was that "importData" variable has a NULL value, the "fileName" path results in a valid file and that swApp is not null. Also added some Solidworks DLLs to the References of this C# Project .

       

      Can anyone point me the way to correct this? Because I havent been able to figure it out so far =/

       

      Thank you!