Search Results for

    Show / Hide Table of Contents

    alt-text Focus on Document handling


    Updated : 27 November 2024

    Export

    The TopSolidHost.Documents.Export method is used to export a document.

    To perform an export, you need to provide the following:

    • Exporter Index: An integer representing the desired exporter (e.g., Parasolid, Catia, etc.).
    • DocumentID: The unique identifier of the document to be exported.
    • File Path: A string specifying the path where the exported file will be created.

    By supplying these parameters, the method facilitates seamless export of documents to various supported formats.

    Warning

    Avoid hardcoding the export index directly into the code, as it may vary depending on the installation parameters. To ensure reliability and adaptability, it is recommended to use a function to retrieve the export index dynamically. This can be done by providing the desired file extension, as demonstrated in the method below:

    private int GetExporterIndex(string wantedFileExtension)
    {
       //Set a default impossible value to the exporter index
       int exporterIndex = -1;
       
       //Browse all exporters to return the index of the PDF one
       for (int i = 0; i < TopSolidHost.Application.ExporterCount; i++)
       {
          string fileType = "";
          string[] fileExtension = null;
          TopSolidHost.Application.GetExporterFileType(i, out fileType, out fileExtension);
          
          //Set the file extension in capital letter to avoid all possible problems
          List<string> extensions = fileExtension.ToList().ConvertAll(d => d.ToUpper()); 
          if (extensions.Contains(wantedFileExtension.ToUpper())
          {
             exporterIndex = i;
             break;
          }
       }
       return exporterIndex;
    }
    
    Note

    Before exporting a file, it is important to verify its exportability using the TopSolidHost.Documents.CanExport method. If the file cannot be exported, an appropriate error message should be returned to inform the user.

    Import

    The TopSolidHost.Documents.Import method is used to import a document and functions similarly to the Export method.

    It requires the following inputs:

    • Importer Index: An integer representing the desired importer.
    • File Path: The path of the file to be imported.
    • PdmObjectId: The identifier of the object where the file should be imported.

    The method also returns two outputs: a list of strings and a DocumentId. While these outputs are not relevant for basic use, they may prove useful for more advanced import scenarios.

    Warning

    Avoid hardcoding the import index directly into the code, as it may vary based on the installation parameters. For greater reliability and safety, it is recommended to use a function to dynamically retrieve the import index by specifying the desired file extension, as demonstrated in the method below:

    private int GetImporterIndex(string wantedFileExtension)
    {
       //Set a default impossible value to the importer index
       int importerIndex = TopSolidHost.Application.ImporterCount + 1;
    
       //Browse all importers to return the index of the PDF one
       for (int i = 0; i < TopSolidHost.Application.ImporterCount; i++)
       {
          string fileType = "";
          string[] fileExtension = null;
          TopSolidHost.Application.GetImporterFileType(i, out fileType, out fileExtension);
    
         //Set the file extension in capital letter to avoid all possible problems
         List<string> extensions = fileExtension.ToList().ConvertAll(d => d.ToUpper()); 
         if (extensions.Contains(wantedFileExtension.ToUpper())
         {
             importerIndex = i;
             break;
         }
       }
       return importerIndex;
    }
    

    Using a dictionary for options

    The TopSolidHost.Documents.ImportWithOptions and TopSolidHost.Documents.ExportWithOptions methods allow for importing or exporting a document with additional configurable options. To use these methods, you must provide a list of KeyValue pairs representing the options as a parameter. These options are specific to the importer or exporter, depending on the selected file format.

    You can retrieve the available options for a given format using the following methods:

    • TopSolidHost.Application.GetImporterOptions
    • TopSolidHost.Application.GetExporterOptions
    Important

    Example: Options for STL Format Here is a sample list of available options for the STL format:

    • SAVE_VERSION
    • SIMPLIFY_ASSEMBLY_STRUCTURE
    • EXPORTS_RIGID_GROUPS_AS_SUBASSEMBLIES
    • LINEAR_TOLERANCE
    • ANGULAR_TOLERANCE
    • WRITE_MODE
    • MAX_FACET_LENGTH
    • AGGREGATES_SHAPES
    • USER_UNIT_SET
    • USER_UNIT
    • REPRESENTATION_ID
    • REFERENCE_FRAME

    Hidden dictionary options

    Some more specific options won't be returned by these methods. For example, for STL format:

    • CREATION_MODE : options are "FacetedShape","Polyhedron","PointCloud" or "SolidShape"
    Tip

    To have more information about available options, do not hesitate to contact your local TopSolid support.

    In This Article
    • Term of use
    • Corporate information
    • Privacy Policy - GDPR

    Copyright ©2024 TopSolid - All rights reserved.