FreeCAD

Форк
0
/
buildPsets.py 
75 строк · 3.3 Кб
1
# ***************************************************************************
2
# *                                                                         *
3
# *   Copyright (c) 2018 Yorik van Havre <yorik@uncreated.net>              *
4
# *                                                                         *
5
# *   This program is free software; you can redistribute it and/or modify  *
6
# *   it under the terms of the GNU Lesser General Public License (LGPL)    *
7
# *   as published by the Free Software Foundation; either version 2 of     *
8
# *   the License, or (at your option) any later version.                   *
9
# *   for detail see the LICENCE text file.                                 *
10
# *                                                                         *
11
# *   This program is distributed in the hope that it will be useful,       *
12
# *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
# *   GNU Library General Public License for more details.                  *
15
# *                                                                         *
16
# *   You should have received a copy of the GNU Library General Public     *
17
# *   License along with this program; if not, write to the Free Software   *
18
# *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
19
# *   USA                                                                   *
20
# *                                                                         *
21
# ***************************************************************************
22

23
"""This script retrieves a list of standard property sets from the IFC4 official documentation website
24
   and stores them into a pset_dfinitions.xml files in the current directory. Warning, this can take
25
   a certain time (there are more than 400 definitions to retrieve)"""
26

27
import codecs, os, re
28
from urllib.request import urlopen
29

30
MAXTRIES = 3
31
IFC_DOCS_ROOT_URL = "https://standards.buildingsmart.org/IFC/DEV/IFC4_2/FINAL/HTML/"
32

33
# read the pset list
34
print("Getting psets list...")
35
u = urlopen(
36
    IFC_DOCS_ROOT_URL + "annex/annex-b/alphabeticalorder_psets.htm"
37
)
38
p = u.read().decode('utf-8')
39
u.close()
40
psets = re.findall(">Pset_(.*?)</a>", p)
41

42
# retrieve xml data from each Pset type
43
psetdefs = ""
44
failed = []
45
for i, pset in enumerate(psets):
46
    print(i + 1, "/", len(psets), ": Retrieving Pset", pset)
47
    for j in range(MAXTRIES):
48
        try:
49
            u = urlopen(
50
                IFC_DOCS_ROOT_URL + "psd/Pset_"
51
                + pset
52
                + ".xml"
53
            )
54
            p = u.read().decode('utf-8')
55
            u.close()
56
        except:
57
            print("    Connection failed. trying one more time...")
58
        else:
59
            break
60
    else:
61
        print("    Unable to retrieve ", pset, ". Skipping...")
62
        failed.append(pset)
63
    psetdefs += p
64
psetdefs = psetdefs.replace('<?xml version="1.0" encoding="utf-8"?>', "")
65
psetdefs = '<?xml version="1.0" encoding="utf-8"?>\n<Root>\n' + psetdefs + "</Root>"
66

67
f = codecs.open("pset_definitions.xml", "wb", "utf-8")
68
f.write(psetdefs)
69
f.close()
70
print(
71
    "All done! writing "
72
    + os.path.join(os.path.abspath(os.curdir), "pset_definitions.xml")
73
)
74
if failed:
75
    print("The following psets failed and were not retrieved:", failed)
76

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.