-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.py
More file actions
106 lines (85 loc) · 2.65 KB
/
system.py
File metadata and controls
106 lines (85 loc) · 2.65 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
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
"""
Operating System Methods
"""
from pathlib import Path
from glob import glob
import subprocess
import time
import os
EXPORT_DIR = Path('C:/Users/GARY/Desktop/CAD/')
INVENTOR_DIR = Path('D:/BC-Workspace/GARY/M-Balmoral,D-AGR/Projects')
INVENTOR_APP = Path('C:/Program Files/Autodesk/Inventor 2016/Bin/Inventor.exe')
def create_project(partcode):
"""Create project skeleton
Parameters
----------
partcode : str
AGR part number usually in 'AGR0000-000-00' format
"""
directory = str(EXPORT_DIR.joinpath(partcode))
if not os.path.exists(directory):
os.makedirs(directory)
os.makedirs(directory + r'\print\A0')
os.makedirs(directory + r'\print\A1')
os.makedirs(directory + r'\print\A3')
os.makedirs(directory + r'\pdf')
os.makedirs(directory + r'\from_autocad')
# os.makedirs(directory + r'\dxf')
# os.makedirs(directory + '\dwg')
def find_path(partcode, filetype):
"""find Inventor file path
Parameters
----------
partcode : str
AGR part number usually in 'AGR0000-000-00' format
filetype : str
inventor file type ('ipt', 'iam' or 'idw')
Returns
-------
Path : obj
Path object from Python pathlib module
"""
client = '*'
project = partcode[0:7]
section = partcode[8:11]
file = partcode + '.' + filetype
paths = glob(str(INVENTOR_DIR / client / project / section / file))
# if len(paths) == 0:
# paths = glob(str(INVENTOR_DIR / '**' / file), recursive=True)
if len(paths) == 0:
print('Unable to find ' + partcode)
if len(paths) > 1:
print('Warning - multiple files found. Use first path in list')
if len(paths) > 0:
return Path(paths[0])
def find_paths(partcodes, filetype):
"""find Inventor file paths
Parameters
----------
partcodes : :obj:`list` of :obj:`str`
AGR part numbers usually in 'AGR0000-000-00' format
filetype : str
inventor file type ('ipt', 'iam' or 'idw')
Returns
-------
Path : :obj:`list` of obj
Path object from Python pathlib module
"""
paths = []
for partcode in partcodes:
path = find_path(partcode, filetype)
if path is not None:
paths.append(path)
return paths
def start_inventor():
"""Open Inventor
Inventer must be active for the COM API to work.
"""
if 'Inventor.exe' not in os.popen("tasklist").read():
subprocess.Popen(INVENTOR_APP)
time.sleep(10)
if __name__ == '__main__':
pass
# start_inventor()
# create_project('Hello')
# print(find_paths(['AGR1316-010-00', 'AGR1316-020-00'], 'iam'))