-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvg_lib.py
109 lines (102 loc) · 3.58 KB
/
vg_lib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
###################################################################################
#
# vg_lib.py
#
# Copyright 2021 David Vachulka ([email protected])
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
###################################################################################
import os
def get_language_path():
return os.path.join(os.path.dirname(__file__), "translations")
def is_dir_writable(path):
# return os.access(path, os.W_OK | os.X_OK)
try:
tmp_prefix = "write_tester"
count = 0
filename = os.path.join(path, tmp_prefix)
while os.path.exists(filename):
filename = "{}.{}".format(os.path.join(path, tmp_prefix),count)
count = count + 1
f = open(filename, "w")
f.close()
os.remove(filename)
return True
except Exception as e:
#print "{}".format(e)
return False
def make_assignment(row, variable, obj, prop):
if "SketchObject" in obj.TypeId:
for expr in obj.ExpressionEngine:
if 'Constraints.' + prop == expr[0]:
obj.setExpression('Constraints.' + prop, None)
break
i = 0
indexlist = ''
for con in obj.Constraints:
if con.Name == prop:
indexlist = i
break
i += 1
obj.setDatum(indexlist, float(row[variable]))
return
if "FeaturePython" in obj.TypeId and "DynamicData" in obj.PropertiesList:
for expr in obj.ExpressionEngine:
if prop == expr[0]:
obj.setExpression(prop, None)
break
for p in obj.PropertiesList:
if p == prop:
setattr(obj, p, row[variable])
break
return
if "PartDesign" in obj.Module and "Body" not in obj.TypeId:
for expr in obj.ExpressionEngine:
if prop == expr[0]:
obj.setExpression(prop, None)
obj.recompute()
break
for p in obj.PropertiesList:
if p == prop:
setattr(obj, p, row[variable])
break
return
if "Part::" in obj.TypeId:
for expr in obj.ExpressionEngine:
if prop == expr[0]:
obj.setExpression(prop, None)
obj.recompute()
break
for p in obj.PropertiesList:
if p == prop:
if obj.getTypeIdOfProperty(p) == 'App::PropertyInteger':
setattr(obj, p, int(row[variable]))
break
else:
setattr(obj, p, row[variable])
break
return
if "Spreadsheet" in obj.Module:
for expr in obj.ExpressionEngine:
if prop == expr[0]:
obj.setExpression(prop, None)
obj.recompute()
break
obj.set(prop, row[variable])
return