Hide menu
Loading...
Searching...
No Matches
conversion/export/export.py

Refer to the Export Example.

1# $Id$
2
3# Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
4# Copyright (C) 2014-2023, CADEX. All rights reserved.
5
6# This file is part of the CAD Exchanger software.
7
8# You may use this file under the terms of the BSD license as follows:
9
10# Redistribution and use in source and binary forms, with or without
11# modification, are permitted provided that the following conditions are met:
12# * Redistributions of source code must retain the above copyright notice,
13# this list of conditions and the following disclaimer.
14# * Redistributions in binary form must reproduce the above copyright notice,
15# this list of conditions and the following disclaimer in the documentation
16# and/or other materials provided with the distribution.
17
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGE.
29
30
31import sys
32from pathlib import Path
33import os
34
35import cadexchanger.CadExCore as cadex
36import cadexchanger.CadExOBJ as obj
37
38sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + r"/../../"))
39import cadex_license as license
40
41
42def main(theSource: str, theDest: str):
43 aKey = license.Value()
44
45 if not cadex.LicenseManager.Activate(aKey):
46 print("Failed to activate CAD Exchanger license.")
47 return 1
48
49 aModel = cadex.ModelData_Model()
50
51 if not cadex.ModelData_ModelReader().Read(cadex.Base_UTF16String(theSource), aModel):
52 print("Failed to read the file " + theSource)
53 return 1
54
55 aWriter = obj.OBJ_Writer()
56 aWriterParams: obj.OBJ_WriterParameters = aWriter.Parameters()
57
58 # Set some writer parameteres
59 aWriterParams.SetLengthUnit(cadex.Base_LU_Centimeters)
60 aWriterParams.SetToGenerateMtlFile(True)
61
62 cadex.Base_Settings.Default().SetValue(cadex.Base_Settings.UseExceptions, True)
63 try:
64 # Converting model data to a new format
65 if not aWriter.Transfer(aModel):
66 print("Failed to transfer model data to specified format")
67 return 1
68
69 # Writing model data to file
70 if not aWriter.WriteFile(cadex.Base_UTF16String(theDest)):
71 print("Failed to write the file")
72 return 1
73 except cadex.Base_Exception as anEx:
74 print(anEx.What())
75 return 1
76
77 print("Completed")
78 return 0
79
80if __name__ == "__main__":
81 if len(sys.argv) != 3:
82 print(" <input_file> is a name of the XML file to be read")
83 print(" <output_file> is a name of the OBJ file to Save() the model")
84 sys.exit()
85
86 aSource = os.path.abspath(sys.argv[1])
87 aDest = os.path.abspath(sys.argv[2])
88
89 sys.exit(main(aSource, aDest))
Abstract base class for exceptions thrown from CAD Exchanger.
Definition: Base_Exception.hxx:34
static const std::shared_ptr< Base_Settings > & Default()
Returns global settings object.
Definition: Base_Settings.cxx:541
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:33