|
| 1 | +##Copyright 2023 Thomas Paviot (tpaviot@gmail.com) |
| 2 | +## |
| 3 | +##This file is part of pythonOCC. |
| 4 | +## |
| 5 | +##pythonOCC is free software: you can redistribute it and/or modify |
| 6 | +##it under the terms of the GNU Lesser General Public License as published by |
| 7 | +##the Free Software Foundation, either version 3 of the License, or |
| 8 | +##(at your option) any later version. |
| 9 | +## |
| 10 | +##pythonOCC is distributed in the hope that it will be useful, |
| 11 | +##but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +##GNU Lesser General Public License for more details. |
| 14 | +## |
| 15 | +##You should have received a copy of the GNU Lesser General Public License |
| 16 | +##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +from OCC.Core.TDocStd import TDocStd_Document |
| 19 | +from OCC.Core.XCAFDoc import ( |
| 20 | + XCAFDoc_DocumentTool_MaterialTool, |
| 21 | +) |
| 22 | +from OCC.Core.STEPCAFControl import STEPCAFControl_Reader |
| 23 | +from OCC.Core.IFSelect import IFSelect_RetDone |
| 24 | +from OCC.Core.TDF import TDF_LabelSequence |
| 25 | + |
| 26 | +filename = "../assets/models/eight_cyl.stp" |
| 27 | + |
| 28 | +# create an handle to a document |
| 29 | +doc = TDocStd_Document("pythonocc-doc") |
| 30 | + |
| 31 | +# Get root assembly |
| 32 | +mat_tool = XCAFDoc_DocumentTool_MaterialTool(doc.Main()) |
| 33 | + |
| 34 | +step_reader = STEPCAFControl_Reader() |
| 35 | + |
| 36 | +status = step_reader.ReadFile(filename) |
| 37 | +if status == IFSelect_RetDone: |
| 38 | + step_reader.Transfer(doc) |
| 39 | + |
| 40 | +material_labels = TDF_LabelSequence() |
| 41 | + |
| 42 | +mat_tool.GetMaterialLabels(material_labels) |
| 43 | + |
| 44 | +# materials |
| 45 | +for i in range(1, material_labels.Length() + 1): |
| 46 | + ( |
| 47 | + ok, |
| 48 | + material_name, |
| 49 | + material_description, |
| 50 | + material_density, |
| 51 | + material_densname, |
| 52 | + material_densvaltype, |
| 53 | + ) = mat_tool.GetMaterial(material_labels.Value(i)) |
| 54 | + |
| 55 | + print(f"Material name: {material_name}") |
| 56 | + print(f"Material description: {material_description}") |
| 57 | + print(f"Material density: {material_density}") |
| 58 | + print(f"Material densname: {material_densname}") |
| 59 | + print(f"Material_densvaltype: {material_densvaltype}\n") |
0 commit comments