1 Reply Latest reply on Feb 16, 2017 3:47 PM by Guillermo Oliver

    Saving assembly as part document (C++)

    Guillermo Oliver

      I am trying to use the C++ API implementation to save an assembly (.SLDASM) as a part document (.SLDPRT), but I keep getting swGenericSaveError.

       

      Using the following code:

       

      void guardarModelo()
      {
        //Guardar como part
        wchar_t exportedfilename[MAX_PATH], assemblyname[MAX_PATH], *pext, *pname;
        long error = 0, warning = 0;
        VARIANT_BOOL result = 0;
        CComPtr<IModelDocExtension> swExtension; //Extension (formato de fichero)
        swUserPreferenceIntegerValue_e part = swSaveAssemblyAsPartOptions; //Opciones de part
      
        //Arreglamos la extension y la ubicacion del fichero
        wcscpy(exportedfilename, filename);
        pext = wcsrchr(exportedfilename, L'\\') + 1;
        wcscpy(pext, L"-modelo\\");
        CreateDirectory(exportedfilename, NULL);
      
        wcscpy(assemblyname, filename);
        pname = wcsrchr(assemblyname, L'\\') + 1;
        pext = wcsrchr(assemblyname, L'.');
        wcsncpy(pext, L".SLDPRT\0", 8);
        wcscat(exportedfilename, pname);
      
        CComBSTR sFileName(exportedfilename);
      
        swModel->get_Extension(&swExtension);
      
        //swApp->SetUserPreferenceIntegerValue(part, swSaveAsmAsPart_AllComponents, &result);
        swExtension->SetUserPreferenceInteger(swSaveAssemblyAsPartOptions, swDetailingNoOptionSpecified, swSaveAsmAsPart_AllComponents, &result);
      
        swExtension->SaveAs(sFileName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, NULL, &error, &warning, &result);
      
        if (error == 0)
        wcout << "Modelo completo guardado como part." << endl;
        else
        wcout << "ERROR " << error << " guardando modelo completo como part." << endl;
      
      }
      

       

      The code works fine when exporting the asssembly to a Parasolid binary (.x_b):

       

      void exportarModelo()
      {
        //Exportar a parasolid
        wchar_t exportedfilename[MAX_PATH], assemblyname[MAX_PATH], *pext, *pname;
        long error = 0, warning = 0; 
        VARIANT_BOOL result = 0;
        CComPtr<IModelDocExtension> swExtension; //Extension (formato de fichero)
        swUserPreferenceIntegerValue_e parasolid = swParasolidOutputVersion; //Opciones de Parasolid
      
      
        //Arreglamos la extension y la ubicacion del fichero
        wcscpy(exportedfilename, filename);
        pext = wcsrchr(exportedfilename, L'\\') + 1;
        wcscpy(pext, L"-modelo\\");
        CreateDirectory(exportedfilename, NULL);
      
      
        wcscpy(assemblyname, filename);
        pname = wcsrchr(assemblyname, L'\\') + 1;
        pext = wcsrchr(assemblyname, L'.');
        wcsncpy(pext, L".x_b\0", 5);
        wcscat(exportedfilename, pname);
      
      
        CComBSTR sFileName(exportedfilename);
      
        swModel->get_Extension(&swExtension);
      
      
        //Elegir version de Parasolid y guardar
        swApp->SetUserPreferenceIntegerValue(parasolid, swParasolidOutputVersion_150, &result);
      
      
        swExtension->SaveAs(sFileName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, NULL, &error, &warning, &result);
      
      
        if (error == 0)
        wcout << "Modelo completo exportado a Parasolid." << endl;
        else
        wcout << "ERROR " << error << " exportando modelo completo a Parasolid." << endl;
      
      
      }
      

       

      Anyone has any idea why this isn't working?