-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeshresize.py
More file actions
52 lines (47 loc) · 1.57 KB
/
meshresize.py
File metadata and controls
52 lines (47 loc) · 1.57 KB
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
import os
import glob
import sys
if len(sys.argv) > 3:
if os.path.isfile(sys.argv[1]):
filename = sys.argv[1]
outfile = sys.argv[2]
multiplier = float(sys.argv[3])
else:
print("meshresize.py [input] [output] [multiplier]")
sys.exit()
def fformat(ff):
return '{:0.6f}'.format(ff).rstrip('0')+'0'[0:(ff%1==0)]
priorline = ""
file = open(outfile, "w")
for line in open(filename):
if "Position" in line or "MaxBoundingExtents" in line or "MinBoundingExtents" in line:
resize = []
try:
position1 = line.replace("]","").split("[")
position2 = position1[1].strip()
positions = position2.split(" ")
for pos in positions:
pos = float(pos.strip())
if pos == 1.0 or pos == -1.0 or pos == 0.0:
resize.append(pos)
else:
resize.append(pos * multiplier)
reposition = position1[0] + "[ " + ' '.join(fformat(x) for x in resize) + " ]"
file.write(reposition + "\n")
except Exception as e:
print("Error in " + filename)
print(e)
print(line)
elif "BoundingRadius" in line:
try:
position = line.split(" ")
reposition = position[0] + " " + fformat(float(position[1].strip()) * multiplier)
file.write(reposition + "\n")
except Exception as e:
print("Error in " + filename)
print(e)
print(line)
else:
file.write(line)
priorline = line
file.close()