-
Notifications
You must be signed in to change notification settings - Fork 0
/
strip_step_file.py
51 lines (45 loc) · 1.51 KB
/
strip_step_file.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
#strip_step_file.py
#Description: Reads CAD file and strips unnecessary parts
#Engineer: T Looby
#Date: 20191031 (boo!)
FREECADPATH = '/opt/freecad/appImage/squashfs-root/usr/lib'
import sys
sys.path.append(FREECADPATH)
import FreeCAD
import FreeCADGui as Gui
import Part
import numpy as np
import Import
import time
"""
You can either explicitly define a list of parts, or import a csv file into an
array of strings. If there are several similar parts that share a common
prefix, you can only include the prefix and the parser will keep all parts that
contain the prefix.
Example:
part_list = ['E-ED1434-011', 'E-ED1434-010']
Prefix only:
part_list = ['E-ED1434']
"""
t0 = time.time()
#File that includes parts or part prefixes, each on their own line
partfile = '/u/tlooby/NSTX/CAD/2019_07/NSTXU_PFC_BOM.csv'
part_list = []
with open(partfile) as f:
part_list = f.read().splitlines()
print("Read parts list...")
#Input / Output STEP files
infile = '/u/tlooby/NSTX/CAD/2019_07/e-ed1384-02_asm.stp'
#infile = '/u/tlooby/NSTX/CAD/30deg/30deg_lowerhalf.step'
outfile = '/u/tlooby/NSTX/CAD/2019_07/test_parser_output.step'
#If a shape has a label in part_list, keep it
CAD = Import.open(infile)
newobj = []
for i in App.ActiveDocument.Objects:
if any(substring in i.Label for substring in part_list):
#if i.Label in part_list:
newobj.append(i)
#Export to a new step file
Import.export(newobj, outfile)
print("Step file export complete.")
print("Parser execution took {:f} seconds".format(time.time() - t0))