# Too Many Props
```python
import xlwings as xw
```
```python
run vBase.ipynb
```
Microsoft Visio
TooManyProps_2024_05_07.vsdm
Zeichenblatt-1
```python
filename = r'C:\Users\...\Documents\Visguy\TooManyProps\Props.xlsm' # insert the right path here.
```
```python
wb = xw.Book(filename)
```
```python
sht = wb.sheets[0]
data = sht.range('Table1').value
```
```python
data
```
[[1.0, 'Base', 'personalID', 0.0, None],
[2.0, 'Base', 'ForeName', 0.0, None],
[3.0, 'Base', 'SecondName', 0.0, None],
[4.0, 'Base', 'SurName', 0.0, None],
[5.0, 'Base', 'BirtdDate', 5.0, None],
...
```python
shp = vWin.Selection(1)
```
```python
cats = []
for i in data:
cat = i[1]
if not cat in cats:
cats.append(cat)
cats
```
['Base',
'Address',
'Contact',
'Work',
'HRL',
'FacilityManagement',
'Family',
'Health',
'Allergenes',
'Medications',
'OnCall']
### Collapsible Sub-sections
```python
cat_name = '___' + 'AllProps' + '___'
shp.AddNamedRow(visSectionProp, cat_name, visTagDefault)
shp.Cells('prop.' + cat_name + '.label').Formula = chr(34) + cat_name + chr(34)
shp.Cells('prop.' + cat_name + '.type').Formula = 1
shp.Cells('prop.' + cat_name + '.format').Formula = chr(34) + "INDIVIDUAL;TRUE;FALSE" + chr(34)
for cat in cats:
cat_name = '___' + cat + '___'
shp.AddNamedRow(visSectionProp, cat_name, visTagDefault)
shp.Cells('prop.' + cat_name + '.label').Formula = chr(34) + cat_name + chr(34)
shp.Cells('prop.' + cat_name + '.type').Formula = 3
if cat == 'Base':
shp.Cells('prop.' + cat_name).Formula = "TRUE"
shp.Cells('prop.' + cat_name + '.invisible' ).Formula = "TRUE"
cat_rows = [i for i in data if i[1] == cat]
for row in cat_rows:
prop = row[2]
type_ = int(row[3])
shp.AddNamedRow(visSectionProp, prop, visTagDefault)
shp.Cells('prop.' + prop + '.label').Formula = chr(34) + prop + chr(34)
shp.Cells('prop.' + prop + '.type').Formula = type_
if type_ == 1:
format_ = row[4]
if format_:
shp.Cells('prop.' + prop + '.format' ).Formula = chr(34) + format_ + chr(34)
if cat != "Base":
formula = 'IF(STRSAME(Prop.___AllProps___,"INDIVIDUAL"),NOT(Prop.' + cat_name + '),NOT(Prop.___AllProps___) )'
#print(formula)
shp.Cells('prop.' + prop + '.invisible' ).FormulaU = formula
```
```python
shp.DeleteSection(visSectionProp)
```
### Input form
```python
for cat in cats:
cat_name = '___' + cat + '___'
'''shp.AddNamedRow(visSectionProp, cat_name, visTagDefault)
shp.Cells('prop.' + cat_name + '.label').Formula = chr(34) + cat_name + chr(34)
shp.Cells('prop.' + cat_name + '.type').Formula = 3
if cat == 'Base':
shp.Cells('prop.' + cat_name).Formula = "TRUE"
shp.Cells('prop.' + cat_name + '.invisible' ).Formula = "TRUE"
'''
cat_rows = [i for i in data if i[1] == cat]
for row in cat_rows:
prop = row[2]
type_ = int(row[3])
shp.AddNamedRow(visSectionProp, prop, visTagDefault)
shp.Cells('prop.' + prop + '.label').Formula = chr(34) + prop + chr(34)
shp.Cells('prop.' + prop + '.type').Formula = type_
if type_ == 1:
format_ = row[4]
if format_:
shp.Cells('prop.' + prop + '.format' ).Formula = chr(34) + format_ + chr(34)
'''
if cat != "Base":
formula = 'IF(STRSAME(Prop.___AllProps___,"INDIVIDUAL"),NOT(Prop.' + cat_name + '),NOT(Prop.___AllProps___) )'
#print(formula)
shp.Cells('prop.' + prop + '.invisible' ).FormulaU = formula
'''
```
### Sub-shapes as input
```python
shp.ConvertToGroup()
```
---------------------------------------------------------------------------
com_error Traceback (most recent call last)
Cell In[51], line 1
----> 1 shp.ConvertToGroup()
File D:\miniconda3\envs\YG1\Lib\site-packages\win32com\gen_py\00021A98-0000-0000-C000-000000000046x0x4x16\IVShape.py:155, in IVShape.ConvertToGroup(self)
154 def ConvertToGroup(self):
--> 155 return self._oleobj_.InvokeTypes(48, LCID, 1, (24, 0), (),)
com_error: (-2147352567, 'Ausnahmefehler aufgetreten.', (0, 'Visio Professional', '\n\nRequested operation is presently disabled.', None, 0, -2032465766), None)
```python
previous_shp = None
for row in data:
field = row[2]
#print(field)
fieldshp = shp.Drop(vDoc.Masters("Field"),1,1)
try:
fieldshp.NameU = field
except:
print("Error with :", field)
fieldshp.Cells('user.invisible').Formula = "not(sheet." + str(shp.ID) + "!user.editmode)"
if previous_shp:
fieldshp.Cells('pinx').Formula = "sheet." + str(previous_shp.ID) + "!pinx"
formula = "if(sheet." + str(shp.ID) + "!user.editmode; sheet." + str(previous_shp.ID) + "!piny - sheet." + str(previous_shp.ID) + "!height;0)"
print(formula)
fieldshp.Cells('piny').Formula = formula
else:
fieldshp.Cells('pinx').Formula = "sheet." + str(shp.ID) + "!controls.input"
fieldshp.Cells('piny').Formula = "sheet." + str(shp.ID) + "!controls.input.y"
previous_shp = fieldshp
previous_shp = None
```
if(sheet.1!user.editmode; sheet.374!piny - sheet.374!height;0)
if(sheet.1!user.editmode; sheet.376!piny - sheet.376!height;0)
...
```python
n = shp.Shapes.Count
for i in range(n,0,-1):
shp.Shapes(i).Delete()
```
```python
```
Quote from: Nikolay on May 01, 2024, 09:58:34 AMThe behavior does not seem to be reproducible (see the attached sample - VSDM - updates properly)
Could it be that some macro in the VSDM file prevents the formula from working?