Hide menu
modeling/metadata/metadata.py

Refer to the Metadata Example.

1 #!/usr/bin/env python3
2 
3 # $Id$
4 
5 # Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
6 # Copyright (C) 2014-2022, 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 
33 import sys
34 from pathlib import Path
35 import os
36 
37 import cadexchanger.CadExCore as cadex
38 
39 sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + r"/../../"))
40 import cadex_license as license
41 
42 
43 def main():
44  aKey = license.Value()
45 
46  if not cadex.LicenseManager.Activate(aKey):
47  print("Failed to activate CAD Exchanger license.")
48  return 1
49 
50  # Create a simple box
51  aBox = cadex.ModelAlgo_TopoPrimitives.CreateBox(5.0, 5.0, 5.0)
53 
54  # Color the box
55  aFaceIt = cadex.ModelData_Shape_Iterator(aBox, cadex.ModelData_ST_Face)
56  r = 10
57  g = 10
58  b = 250
59  a = 255
60  for aFace in aFaceIt:
61  r += 30
62  b -= 30
64  aBRep.SetAppearance(aFace, anApp)
65 
66  # Change properties
67  aPart = cadex.ModelData_Part(aBRep, cadex.Base_UTF16String("ColorBox"))
69  aTable.Add(cadex.Base_UTF16String("Color"), cadex.Base_UTF16String("Different"))
70  aPart.AddProperties(aTable)
71 
72  aModel = cadex.ModelData_Model()
73  aModel.AddRoot(aPart)
74  cadex.ModelData_ModelWriter().Write(aModel, cadex.Base_UTF16String("out/ColorBox.xml"))
75 
76  print("Completed")
77  return 0
78 
79 if __name__ == "__main__":
80  sys.exit(main())
81 
static ModelData_Solid CreateBox(double theDx, double theDy, double theDz)
Creates a box.
Definition: ModelAlgo_TopoPrimitives.cxx:82
Defines an RGBA color (with alpha channel).
Definition: ModelData_Color.hxx:33
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:33
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:40
Provides an interface to appearance which is a collection of visual styles.
Definition: ModelData_Appearance.hxx:38
Writes any format that CAD Exchanger can export.
Definition: ModelData_ModelWriter.hxx:31
Defines a collection of properties.
Definition: ModelData_PropertyTable.hxx:39
Defines a leaf node in the scene graph hiearchy.
Definition: ModelData_Part.hxx:34
Defines precise Boundary Representation of part.
Definition: ModelData_BRepRepresentation.hxx:38