Skip to content

Commit 87e8250

Browse files
committed
Example for step header section, see issue tpaviot/pythonocc-core#1154
1 parent 9e5b58a commit 87e8250

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
##Copyright 2022 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 datetime import datetime
19+
20+
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
21+
22+
from OCC.Core.STEPControl import STEPControl_Writer, STEPControl_AsIs
23+
from OCC.Core.Interface import Interface_Static_SetCVal
24+
from OCC.Core.IFSelect import IFSelect_RetDone
25+
26+
from OCC.Core.Interface import Interface_HArray1OfHAsciiString
27+
from OCC.Core.APIHeaderSection import APIHeaderSection_MakeHeader
28+
from OCC.Core.TCollection import TCollection_HAsciiString
29+
30+
# creates a basic shape
31+
box_s = BRepPrimAPI_MakeBox(10, 20, 30).Shape()
32+
33+
# initialize the STEP exporter
34+
step_writer = STEPControl_Writer()
35+
dd = step_writer.WS().TransferWriter().FinderProcess()
36+
37+
Interface_Static_SetCVal("write.step.schema", "AP203")
38+
39+
# transfer shapes and write file
40+
Interface_Static_SetCVal("write.step.product.name", "Box")
41+
step_writer.Transfer(box_s, STEPControl_AsIs)
42+
43+
#
44+
# Set STEP header
45+
#
46+
model = step_writer.Model()
47+
model.ClearHeader()
48+
49+
hs = APIHeaderSection_MakeHeader()
50+
hs.SetName(TCollection_HAsciiString("model name"))
51+
hs.SetAuthorValue(1, TCollection_HAsciiString("My name"))
52+
hs.SetAuthorisation(TCollection_HAsciiString("authorization"))
53+
54+
descr = Interface_HArray1OfHAsciiString(1, 3)
55+
descr.SetValue(1, TCollection_HAsciiString("a description"))
56+
descr.SetValue(2, TCollection_HAsciiString("split into"))
57+
descr.SetValue(3, TCollection_HAsciiString("three items"))
58+
hs.SetDescription(descr)
59+
60+
org = Interface_HArray1OfHAsciiString(1, 1)
61+
org.SetValue(1, TCollection_HAsciiString("pythonocc organization"))
62+
hs.SetOrganization(org)
63+
64+
hs.SetOriginatingSystem(TCollection_HAsciiString("pythonocc originating system"))
65+
hs.SetImplementationLevel(TCollection_HAsciiString("implementation level"))
66+
67+
identifiers = Interface_HArray1OfHAsciiString(1, 1)
68+
identifiers.SetValue(1, TCollection_HAsciiString("a schema identifier"))
69+
hs.SetSchemaIdentifiers(identifiers)
70+
71+
hs.SetPreprocessorVersion(TCollection_HAsciiString("preprocessor version"))
72+
hs.SetTimeStamp(TCollection_HAsciiString(f"Time stamp: {datetime.now()}"))
73+
74+
model.AddHeaderEntity(hs.FnValue())
75+
model.AddHeaderEntity(hs.FsValue())
76+
model.AddHeaderEntity(hs.FdValue())
77+
78+
# finally write file
79+
status = step_writer.Write("box_header.stp")
80+
81+
if status != IFSelect_RetDone:
82+
raise AssertionError("load failed")

0 commit comments

Comments
 (0)