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

Refer to the Transfer with Parameters Example.

1#!/usr/bin/env python3
2
3# $Id$
4
5# Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
6# Copyright (C) 2014-2023, CADEX. All rights reserved.
7
8# This file is part of the CAD Exchanger software.
9
10# You may use this file under the terms of the BSD license as follows:
11
12# Redistribution and use in source and binary forms, with or without
13# modification, are permitted provided that the following conditions are met:
14# * Redistributions of source code must retain the above copyright notice,
15# this list of conditions and the following disclaimer.
16# * Redistributions in binary form must reproduce the above copyright notice,
17# this list of conditions and the following disclaimer in the documentation
18# and/or other materials provided with the distribution.
19
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE.
31
32
33import sys
34from pathlib import Path
35import os
36
37
38import cadexchanger.CadExCore as cadex
39
40sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + r"/../../"))
41import cadex_license as license
42import cadexchanger.CadExSTEP as step
43import cadexchanger.CadExJT as jt
44import cadexchanger.CadExOBJ as obj
45
46
47def main(theSource: str, theDest: str):
48 aKey = license.Value()
49
50 if not cadex.LicenseManager.Activate(aKey):
51 print("Failed to activate CAD Exchanger license.")
52 return 1
53
54 aModel = cadex.ModelData_Model()
55
56 print("Conversion started...")
57
59
60 # Let's set new parameters
61 aSTEPReaderParams = step.STEP_ReaderParameters()
62 aSTEPReaderParams.SetPreferredBRepRepresentationType(step.STEP_ReaderParameters.AdvancedBRep)
63 aReader.SetReaderParameters(aSTEPReaderParams)
64
65 aJTReaderParams = jt.JT_ReaderParameters()
66 aJTReaderParams.SetLayerConversionMode(jt.JT_ReaderParameters.LayerFilter)
67 aReader.SetReaderParameters(aJTReaderParams)
68
69 # Opening and converting the file
70 if not aReader.Read(cadex.Base_UTF16String(theSource), aModel):
71 print("Failed to open and convert the file " + theSource)
72 return 1
73
75
76 anOBJParams = obj.OBJ_WriterParameters()
77 # Set some writer parameters
78 anOBJParams.SetLengthUnit(cadex.Base_LU_Centimeters)
79 anOBJParams.SetToGenerateMtlFile(True)
80 aWriter.SetWriterParameters(anOBJParams)
81
82 aJTParams = jt.JT_WriterParameters()
83 aJTParams.SetFileSplitMode(jt.JT_WriterParameters.PerPart)
84 aWriter.SetWriterParameters(aJTParams)
85
86 cadex.Base_Settings.Default().SetValue(cadex.Base_Settings.UseExceptions, True)
87 try:
88 # Converting and writing the model to file
89 if not aWriter.Write(aModel, cadex.Base_UTF16String(theDest)):
90 print("Failed to convert and write the file to specified format " + theDest)
91 return 1
92 except cadex.Base_Exception as anEx:
93 print(anEx.What())
94 return 1
95
96 print("Completed")
97 return 0
98
99if __name__ == "__main__":
100 if len(sys.argv) != 3:
101 print(" <input_file> is a name of the STEP file to be read")
102 print(" <output_file> is a name of the JT file to Save() the model")
103 sys.exit(1)
104
105 aSource = os.path.abspath(sys.argv[1])
106 aDest = os.path.abspath(sys.argv[2])
107
108 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
Writes any format that CAD Exchanger can export.
Definition: ModelData_ModelWriter.hxx:33