-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_scraper.py
72 lines (58 loc) · 2.9 KB
/
_scraper.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
"""
Capture the Rhino viewports to an image file. Places the images in a folder with
the same name as the GH file and in the same directory as the GH file. It
captures the data used during the optimization process in a CSV file named and
saved in the same way as described for the images.
Inputs:
Toggle: Activate the component using a boolean toggle
goalValue: receives goal value
width: width of the screen to be captured
height: height of the screen to be captured
data: data list
"""
import scriptcontext as sc
import Rhino as rc
import os
import System
def checkOrMakeFolder():
""" Check/makes a "Captures" folder in the GH def folder """
if ghdoc.Path:
folder = os.path.dirname(ghdoc.Path)
ghDef = ghenv.LocalScope.ghdoc.Name.strip("*")
captureFolder = folder + "\\" + str(ghDef)
if not os.path.isdir(captureFolder):
os.makedirs(captureFolder)
return captureFolder
def makeFileName():
""" Make a string with the gh def name + current hourMinuteSecond """
fileName = str(goalValue)
return fileName
def captureActiveViewToFile(width,height,path):
"""
Captures the active view to an image file at the path. Path looks like this:
"C:\\Users\\adel\\Desktop\\Captures\\goalValue.png"
"""
sc.doc = rc.RhinoDoc.ActiveDoc
activeView = sc.doc.Views.ActiveView
imageDim = System.Drawing.Size(width,height)
try:
imageCap = rc.Display.RhinoView.CaptureToBitmap(activeView,imageDim)
System.Drawing.Bitmap.Save(imageCap,path)
rc.RhinoApp.WriteLine(path)
return path
except:
raise Exception(" Capture failed, check the path")
if Toggle:
capFolder = checkOrMakeFolder()
fileText = os.path.join(capFolder + ".csv")
with open(fileText, 'a') as file_object:
fileName = makeFileName()
count = 0
try:
path = os.path.join(capFolder,fileName + ".png")
Path = captureActiveViewToFile(width,height,path)
except:
raise Exception("Capture failed, save the GH definition")
converte = ', '.join(map(str, data))
concatenatedData = converte + ", " + fileName + "\n"
file_object.write(concatenatedData)