-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathspreadCmd.py
More file actions
52 lines (45 loc) · 1.32 KB
/
spreadCmd.py
File metadata and controls
52 lines (45 loc) · 1.32 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
#(c) 2016 R. T. LGPL: part of Flamingo tools w.b. for FreeCAD
__title__="spreadSheetUtils functions"
__author__="oddtopus"
__url__="github.com/oddtopus/flamingo"
__license__="LGPL 3"
global alpha
alpha='ABCDEFGHJKILMNOPQRSTUVWXYZ'
def cellRC(sp,target):
'arg1=spreadsheet,arg2=target; return row of target'
import xml.etree.ElementTree as et
cells=et.fromstring(sp.cells.Content)
for cell in cells:
if cell.get('content')==target:
addr=cell.get('address')
#print addr+'\n'
row=addr.lstrip(alpha)
return row
#print "There are no "+target+" in this sheet."
def makeDict(sp):
'arg1=spreadsheet; returns dict[\'address\']=\'content\''
import xml.etree.ElementTree as et
cells=et.fromstring(sp.cells.Content)
d=dict()
for c in cells:
d[c.attrib['address']]=c.attrib['content']
return d
def setTipo(l,w):
'arg1=length,arg2=width'
import FreeCAD
fpTipo=FreeCAD.activeDocument().tipo
fpTipo.length=l
fpTipo.width=w
FreeCAD.activeDocument().recompute()
def getTipo(sp,target):
'arg1=spreadsheet,arg2=str_Target; returns [length,width]'
d=makeDict(sp)
row=cellRC(sp,target)
l=d['C'+row]
w=d['D'+row]
setTipo(l,w)
return [l,w]
def getTipi(sp):
'arg1=spreadsheet; returns [contents in column A]'
d=makeDict(sp)
return [d[k] for k in d.keys() if k.startswith('A')]