-
Notifications
You must be signed in to change notification settings - Fork 1
/
FilteredExportUtil.py
72 lines (59 loc) · 2.77 KB
/
FilteredExportUtil.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
import adsk.core
import adsk.fusion
#
# get all child occurences (components) recursively from a component
# and return a unique list of components
#
def getComponents(occurences, components, includeSubComponents, filterLinkedComponents):
# iterate over all occurences
for occurence in occurences:
if (filterLinkedComponents == True and occurence.isReferencedComponent == False) or filterLinkedComponents == False:
try:
# if the component is not hidden process the component
if occurence.isLightBulbOn:
# validate if the current component was already processed
componentFound = False
component = adsk.fusion.Component.cast(None)
# itereate over unique component list and compoare current
# occource with element of unique component list
for component in components:
if component == occurence.component:
# component exisits in filted list. No need to process
# the full list
componentFound = True
break
# if occurence not found in unique list of components, add this
# occurence because it's new
if not componentFound and occurence.component:
components.append(occurence.component)
# if this occurence has sub components process them, too
if occurence.childOccurrences and not componentFound and includeSubComponents:
components = getComponents(occurence.childOccurrences, components, includeSubComponents, filterLinkedComponents)
except:
pass
return components
#
# render result string showing path, exported objects and skipped objects
#
def renderResultMessage(exportResult):
# Initialize with path
resultMessage = 'Path:\n ' + exportResult.exportPath + '\n'
# render list of processed files
resultMessage += 'Processed:\n'
for export in exportResult.exportNames:
resultMessage += ' ' + export + '\n'
if len(exportResult.skippedNames) == 0:
return resultMessage
# render list of processed files
resultMessage += 'Skipped:\n'
for export in exportResult.skippedNames:
resultMessage += ' ' + export + '\n'
return resultMessage
#
# result set from a stl export
#
class FilteredExportResult(object):
def __init__(self, exportPath, exportNames, skippedNames):
self.exportPath = exportPath
self.exportNames = exportNames
self.skippedNames = skippedNames