-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.py
61 lines (49 loc) · 2.11 KB
/
export.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
"""Functions related to export dwg files, images etc."""
from api import *
from lib import Walker
from lib import get_folder
from Autodesk.Revit.DB import ExportRange
from Autodesk.Revit.DB import FilteredElementCollector
from Autodesk.Revit.DB import FitDirectionType
from Autodesk.Revit.DB import ImageExportOptions
from Autodesk.Revit.DB import ImageFileType
from Autodesk.Revit.DB import ImageResolution
from Autodesk.Revit.DB import View3D
from Autodesk.Revit.DB import ViewFamily
from Autodesk.Revit.DB import ViewFamilyType
from Autodesk.Revit.DB import ZoomFitType
def export_images(doc):
"""Export 3D images from all revit family files found under starting directory"""
start_dir = get_folder('Enter start directory: ')
out_dir = get_folder('Enter directory to save images: ')
last_doc = None
def cb(filepath):
current_uidoc = __revit__.OpenAndActivateDocument(filepath)
current_doc = current_uidoc.Document
if last_doc:
last_doc.Close(False)
print('Closing {}'.format(last_doc))
last_doc = current_doc
current_dir, filename = os.path.split(current_doc.PathName)
basename, ext = os.path.splitext(filename)
view_type = [x for x in
FilteredElementCollector(current_doc).OfClass(ViewFamilyType)
if x.ViewFamily == ViewFamily.ThreeDimensional][0]
img = ImageExportOptions()
img.FilePath = os.path.join(out_dir, '{}.png'.format(basename))
img.HLRandWFViewsFileType = ImageFileType.PNG
img.ExportRange = ExportRange.CurrentView
img.ZoomType = ZoomFitType.FitToPage
img.FitDirection = FitDirectionType.Horizontal
img.ImageResolution = ImageResolution.DPI_600
cats = current_doc.Settings.Categories
view = current_doc.ActiveView
tr = transaction(current_doc, 'Change view settings')
tr.Start()
view = View3D.CreateIsometric(current_doc, view_type.Id)
current_uidoc.ActiveView = view
current_doc.ExportImage(img)
tr.RollBack()
print(basename)
w = Walker(start_dir, '.*.rfa', cb)
w.run()